FilteringHelper { public static Class<? extends BaseDimensionalItemObject> extractEntityFromEqualFilter( final String filter ) { final byte DIMENSION_TYPE = 2; Class<? extends BaseDimensionalItemObject> entity = null; if ( trimToEmpty( filter ).contains( DIMENSION_TYPE_EQUAL_FILTER_PREFIX ) ) { final String[] array = filter.split( ":" ); final boolean hasDimensionType = array.length == 3; if ( hasDimensionType ) { entity = entityClassFromString( array[DIMENSION_TYPE] ); } else { throw new IllegalQueryException( new ErrorMessage( E2014, filter ) ); } } return entity; }  static Set<Class<? extends BaseDimensionalItemObject>> extractEntitiesFromInFilter( final String filter ); static Class<? extends BaseDimensionalItemObject> extractEntityFromEqualFilter( final String filter );  }
@Test public void testExtractEntityFromEqualFilter() { final String anyFilter = "dimensionItemType:eq:DATA_SET"; final Class<? extends BaseDimensionalItemObject> expectedClass = DataSet.class; final Class<? extends BaseDimensionalItemObject> actualClass = extractEntityFromEqualFilter( anyFilter ); assertThat( actualClass, is( notNullValue() ) ); assertThat( actualClass, is( equalTo( expectedClass ) ) ); }
@Test public void testExtractEntityFromEqualFilterWhenTypeIsInvalid() { final String filtersWithInvalidType = "dimensionItemType:eq:INVALID_TYPE"; expectedException.expect( IllegalQueryException.class ); expectedException.expectMessage( "Unable to parse element `" + "INVALID_TYPE` on filter `dimensionItemType`. The values available are: " + Arrays.toString( DATA_TYPE_ENTITY_MAP.keySet().toArray() ) ); extractEntityFromEqualFilter( filtersWithInvalidType ); }
@Test public void testExtractEntityFromEqualFilterWhenFilterIsInvalid() { final String invalidFilter = "dimensionItemType:eq:"; expectedException.expect( IllegalQueryException.class ); expectedException.expectMessage( "Unable to parse filter `" + invalidFilter + "`" ); extractEntityFromEqualFilter( invalidFilter ); }