FilteringHelper { public static Set<Class<? extends BaseDimensionalItemObject>> extractEntitiesFromInFilter( final String filter ) { final Set<Class<? extends BaseDimensionalItemObject>> dimensionTypes = new HashSet<>( 0 ); if ( contains( filter, DIMENSION_TYPE_IN_FILTER_PREFIX ) ) { final String[] dimensionTypesInFilter = split( deleteWhitespace( substringBetween( filter, "[", "]" ) ), "," ); if ( isNotEmpty( dimensionTypesInFilter ) ) { for ( final String dimensionType : dimensionTypesInFilter ) { dimensionTypes.add( entityClassFromString( dimensionType ) ); } } else { throw new IllegalQueryException( new ErrorMessage( E2014, filter ) ); } } return dimensionTypes; }  static Set<Class<? extends BaseDimensionalItemObject>> extractEntitiesFromInFilter( final String filter ); static Class<? extends BaseDimensionalItemObject> extractEntityFromEqualFilter( final String filter );  }
@Test public void testExtractEntitiesFromInFilter() { final String anyFilters = "dimensionItemType:in:[INDICATOR,DATA_SET]"; final Class<? extends BaseDimensionalItemObject>[] expectedClasses = new Class[] { Indicator.class, DataSet.class }; final Set<Class<? extends BaseDimensionalItemObject>> actualClasses = extractEntitiesFromInFilter( anyFilters ); assertThat( actualClasses, hasSize( 2 ) ); assertThat( actualClasses, containsInAnyOrder( expectedClasses ) ); }
@Test public void testExtractEntitiesFromInFilterWhenTypeIsInvalid() { final String filtersWithInvalidType = "dimensionItemType:in:[INVALID_TYPE,DATA_SET]"; 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() ) ); extractEntitiesFromInFilter( filtersWithInvalidType ); }
@Test public void testExtractEntitiesFromInFilterWhenFilterContainsOnlyEmpties() { final String filtersWithInvalidType = "dimensionItemType:in:[,]"; expectedException.expect( IllegalQueryException.class ); expectedException.expectMessage( "Unable to parse filter `" + filtersWithInvalidType + "`" ); extractEntitiesFromInFilter( filtersWithInvalidType ); }
@Test public void testExtractEntitiesFromInFilterWhenFilterIsNotFullyDefined() { final String filtersNotFullyDefined = "dimensionItemType:in:[,DATA_SET]"; final Class<? extends BaseDimensionalItemObject>[] expectedClasses = new Class[] { DataSet.class }; final Set<Class<? extends BaseDimensionalItemObject>> actualClasses = extractEntitiesFromInFilter( filtersNotFullyDefined ); assertThat( actualClasses, hasSize( 1 ) ); assertThat( actualClasses, containsInAnyOrder( expectedClasses ) ); }