use of uk.gov.gchq.koryphe.tuple.predicate.KoryphePredicate2 in project Gaffer by gchq.
the class PropertiesFilterTest method shouldTestPropertiesOnPredicate2WithValidationResult.
@Test
public void shouldTestPropertiesOnPredicate2WithValidationResult() {
// Given
final PropertiesFilter propertiesFilter = new PropertiesFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new KoryphePredicate2<String, String>() {
@Override
public boolean test(final String o, final String o2) {
return "value".equals(o) && "value2".equals(o2);
}
}).build();
final Properties correctProperties = new Properties();
correctProperties.put(TestPropertyNames.PROP_1, "value");
correctProperties.put(TestPropertyNames.PROP_2, "value2");
final Properties incorrectProperties = new Properties();
incorrectProperties.put(TestPropertyNames.PROP_1, "value_incorrect");
incorrectProperties.put(TestPropertyNames.PROP_2, "value2_incorrect");
// When
final ValidationResult correctResult = propertiesFilter.testWithValidationResult(correctProperties);
final ValidationResult incorrectResult = propertiesFilter.testWithValidationResult(incorrectProperties);
// Then
assertTrue(correctResult.isValid());
assertFalse(incorrectResult.isValid());
assertTrue(incorrectResult.getErrorString().contains("{property1: <java.lang.String>value_incorrect, property2: <java.lang.String>value2_incorrect}"), "Result was: " + incorrectResult.getErrorString());
}
use of uk.gov.gchq.koryphe.tuple.predicate.KoryphePredicate2 in project Gaffer by gchq.
the class PropertiesFilterTest method shouldTestPropertiesOnPredicate2.
@Test
public void shouldTestPropertiesOnPredicate2() {
// Given
final PropertiesFilter propertiesFilter = new PropertiesFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new KoryphePredicate2<String, String>() {
@Override
public boolean test(final String o, final String o2) {
return "value".equals(o) && "value2".equals(o2);
}
}).build();
final Properties correctProperties = new Properties();
correctProperties.put(TestPropertyNames.PROP_1, "value");
correctProperties.put(TestPropertyNames.PROP_2, "value2");
final Properties incorrectProperties = new Properties();
incorrectProperties.put(TestPropertyNames.PROP_1, "value_incorrect");
incorrectProperties.put(TestPropertyNames.PROP_2, "value2_incorrect");
// When
final boolean correctResult = propertiesFilter.test(correctProperties);
final boolean incorrectResult = propertiesFilter.test(incorrectProperties);
// Then
assertTrue(correctResult);
assertFalse(incorrectResult);
}
use of uk.gov.gchq.koryphe.tuple.predicate.KoryphePredicate2 in project Gaffer by gchq.
the class ElementFilterTest method shouldTestElementOnPredicate2.
@Test
public void shouldTestElementOnPredicate2() {
// Given
final ElementFilter filter = new ElementFilter.Builder().select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2).execute(new KoryphePredicate2<String, String>() {
@Override
public boolean test(final String o, final String o2) {
return "value".equals(o) && "value2".equals(o2);
}
}).build();
final Entity element1 = makeEntity("value", "value2");
final Entity element2 = makeEntity("unknown", "value2");
// When
final boolean result1 = filter.test(element1);
final boolean result2 = filter.test(element2);
// Then
assertTrue(result1);
assertFalse(result2);
}
use of uk.gov.gchq.koryphe.tuple.predicate.KoryphePredicate2 in project Gaffer by gchq.
the class ElementFilterTest method shouldTestElementOnPredicate2WithValidationResult.
@Test
public void shouldTestElementOnPredicate2WithValidationResult() {
// Given
final KoryphePredicate2<String, String> predicate2 = new KoryphePredicate2<String, String>() {
@Override
public boolean test(final String o, final String o2) {
return "value".equals(o) && "value2".equals(o2);
}
};
final ElementFilter filter = new ElementFilter.Builder().select("prop1", "prop2").execute(predicate2).build();
final Entity element1 = new Entity.Builder().property("prop1", "value").property("prop2", "value2").build();
final Entity element2 = new Entity.Builder().property("prop1", "unknown").property("prop2", "value2").build();
// When
final ValidationResult result1 = filter.testWithValidationResult(element1);
final ValidationResult result2 = filter.testWithValidationResult(element2);
// Then
assertTrue(result1.isValid());
assertFalse(result2.isValid());
assertTrue(result2.getErrorString().contains("{prop1: <java.lang.String>unknown, prop2: <java.lang.String>value2}"), "Result was: " + result2.getErrorString());
}
Aggregations