ThingsFieldExpressionFactoryImpl implements ThingsFieldExpressionFactory { @Override public FilterFieldExpression filterBy(final String propertyNameWithOptionalLeadingSlash) throws IllegalArgumentException { requireNonNull(propertyNameWithOptionalLeadingSlash); final String propertyName = stripLeadingSlash(propertyNameWithOptionalLeadingSlash); final Supplier<FilterFieldExpression> defaultSupplier = () -> (FilterFieldExpression) common(propertyName); return FieldExpressionUtil.parseFeatureField(requireNonNull(propertyName)) .<FilterFieldExpression>flatMap(f -> f.getProperty() .flatMap(property -> f.getFeatureId().map(id -> new FeatureIdPropertyExpressionImpl(id, property)) ) ) .orElseGet(defaultSupplier); } ThingsFieldExpressionFactoryImpl();  ThingsFieldExpressionFactoryImpl(final Map<String, String> simpleFieldMappings); @Override FilterFieldExpression filterBy(final String propertyNameWithOptionalLeadingSlash); @Override ExistsFieldExpression existsBy(final String propertyNameWithOptionalLeadingSlash); @Override SortFieldExpression sortBy(final String propertyNameWithOptionalLeadingSlash);  }
@Test(expected = NullPointerException.class) public void filterByWithNullPropertyName() { ef.filterBy(null); }
@Test(expected = IllegalArgumentException.class) public void filterByWithUnknownPropertyName() { ef.filterBy("unknown"); }
@Test public void filterByWithFeaturePropertyWithId() { final FieldExpression fieldExpression = ef.filterBy(KNOWN_FEATURE_PROPERTY_WITH_ID); final FilterFieldExpression expected = new FeatureIdPropertyExpressionImpl(KNOWN_FEATURE_ID, KNOWN_STRING); assertThat(fieldExpression).isEqualTo(expected); }
@Test(expected = IllegalArgumentException.class) public void filterByWithFeature() { ef.filterBy(KNOWN_FEATURE); }
@Test public void filterByWithAttribute() { final FieldExpression fieldExpression = ef.filterBy(FieldExpressionUtil.addAttributesPrefix(KNOWN_STRING)); final FilterFieldExpression expected = new AttributeExpressionImpl(KNOWN_STRING); assertThat(fieldExpression).isEqualTo(expected); }
@Test public void filterByWithThingId() { final FieldExpression fieldExpression = ef.filterBy(FieldExpressionUtil.FIELD_NAME_THING_ID); final FilterFieldExpression expected = new SimpleFieldExpressionImpl(FieldExpressionUtil.FIELD_ID); assertThat(fieldExpression).isEqualTo(expected); }
@Test public void filterByWithJsonPointer() { final FieldExpression fieldExpression = ef.filterBy(SLASH + FieldExpressionUtil.FIELD_NAME_THING_ID); final FilterFieldExpression expected = new SimpleFieldExpressionImpl(FieldExpressionUtil.FIELD_ID); assertThat(fieldExpression).isEqualTo(expected); }
@Test public void filterByDefinition() { final FilterFieldExpression fieldExpression = ef.filterBy(KNOWN_THING_DEFINITION); final FilterFieldExpression expected = new SimpleFieldExpressionImpl(KNOWN_THING_DEFINITION); assertThat(fieldExpression).isEqualTo(expected); }