use of uk.gov.gchq.koryphe.impl.predicate.IsXMoreThanY in project gaffer-doc by gchq.
the class IsXMoreThanYExample method isXMoreThanY.
public void isXMoreThanY() {
// ---------------------------------------------------------
final IsXMoreThanY function = new IsXMoreThanY();
// ---------------------------------------------------------
runExample(function, null, new Tuple2<>(1, 5), new Tuple2<>(5, 5), new Tuple2<>(10, 5), new Tuple2<>(10L, 5), new Tuple2<>(1L, 5L), new Tuple2<>(5L, 5L), new Tuple2<>(10L, 5L), new Tuple2<>(10, 5L), new Tuple2<>("bcd", "cde"), new Tuple2<>("bcd", "abc"), new Tuple2<>("10", 5));
}
use of uk.gov.gchq.koryphe.impl.predicate.IsXMoreThanY in project Gaffer by gchq.
the class SchemaElementDefinitionTest method shouldReturnFullValidator.
@Test
public void shouldReturnFullValidator() {
// Given
final T elementDef = createBuilder().property("property", PROPERTY_STRING_TYPE).property("property1", PROPERTY_STRING_TYPE).property("property2", PROPERTY_STRING_TYPE).validator(new ElementFilter.Builder().select("property1", "property2").execute(new IsXMoreThanY()).build()).build();
setupSchema(elementDef);
// When
final ElementFilter validator = elementDef.getValidator();
// Then
int i = 0;
assertEquals(IsXMoreThanY.class, validator.getComponents().get(i).getPredicate().getClass());
assertArrayEquals(new String[] { "property1", "property2" }, validator.getComponents().get(i).getSelection());
i++;
if (elementDef instanceof SchemaEdgeDefinition) {
assertEquals(Integer.class.getName(), ((IsA) validator.getComponents().get(i).getPredicate()).getType());
assertArrayEquals(new String[] { IdentifierType.SOURCE.name() }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(Date.class.getName(), ((IsA) validator.getComponents().get(i).getPredicate()).getType());
assertArrayEquals(new String[] { IdentifierType.DESTINATION.name() }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(Boolean.class.getName(), ((IsA) validator.getComponents().get(i).getPredicate()).getType());
assertArrayEquals(new String[] { IdentifierType.DIRECTED.name() }, validator.getComponents().get(i).getSelection());
i++;
} else {
assertArrayEquals(new String[] { IdentifierType.VERTEX.name() }, validator.getComponents().get(i).getSelection());
i++;
}
assertEquals(String.class.getName(), ((IsA) validator.getComponents().get(i).getPredicate()).getType());
assertArrayEquals(new String[] { "property" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(Exists.class, validator.getComponents().get(i).getPredicate().getClass());
assertArrayEquals(new String[] { "property" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(String.class.getName(), ((IsA) validator.getComponents().get(i).getPredicate()).getType());
assertArrayEquals(new String[] { "property1" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(Exists.class, validator.getComponents().get(i).getPredicate().getClass());
assertArrayEquals(new String[] { "property1" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(String.class.getName(), ((IsA) validator.getComponents().get(i).getPredicate()).getType());
assertArrayEquals(new String[] { "property2" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(Exists.class, validator.getComponents().get(i).getPredicate().getClass());
assertArrayEquals(new String[] { "property2" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(i, validator.getComponents().size());
// Check the validator is cached
assertSame(validator, elementDef.getValidator());
assertNotSame(validator, elementDef.getValidator(false));
}
use of uk.gov.gchq.koryphe.impl.predicate.IsXMoreThanY in project Gaffer by gchq.
the class SchemaTest method testLoadingSchemaFromJson.
@Test
public void testLoadingSchemaFromJson() {
// Edge definitions
SchemaElementDefinition edgeDefinition = schema.getEdge(TestGroups.EDGE);
assertNotNull(edgeDefinition);
assertEquals(EDGE_DESCRIPTION, edgeDefinition.getDescription());
final Map<String, String> propertyMap = edgeDefinition.getPropertyMap();
assertThat(propertyMap).hasSize(3);
assertEquals("prop.string", propertyMap.get(TestPropertyNames.PROP_2));
assertEquals("prop.date", propertyMap.get(TestPropertyNames.DATE));
assertEquals("timestamp", propertyMap.get(TestPropertyNames.TIMESTAMP));
assertEquals(Sets.newLinkedHashSet(Collections.singletonList(TestPropertyNames.DATE)), edgeDefinition.getGroupBy());
// Check validator
ElementFilter validator = edgeDefinition.getValidator();
List<TupleAdaptedPredicate<String, ?>> valContexts = validator.getComponents();
int index = 0;
TupleAdaptedPredicate<String, ?> tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof IsA);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(IdentifierType.SOURCE.name(), tuplePredicate.getSelection()[0]);
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof IsA);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(IdentifierType.DESTINATION.name(), tuplePredicate.getSelection()[0]);
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof IsA);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(IdentifierType.DIRECTED.name(), tuplePredicate.getSelection()[0]);
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof ExampleFilterFunction);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(IdentifierType.DIRECTED.name(), tuplePredicate.getSelection()[0]);
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof IsA);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(TestPropertyNames.PROP_2, tuplePredicate.getSelection()[0]);
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof ExampleFilterFunction);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(TestPropertyNames.PROP_2, tuplePredicate.getSelection()[0]);
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof IsA);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(TestPropertyNames.DATE, tuplePredicate.getSelection()[0]);
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof IsA);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(TestPropertyNames.TIMESTAMP, tuplePredicate.getSelection()[0]);
assertEquals(index, valContexts.size());
TypeDefinition type = edgeDefinition.getPropertyTypeDef(TestPropertyNames.DATE);
assertEquals(Date.class, type.getClazz());
assertEquals(DATE_TYPE_DESCRIPTION, type.getDescription());
assertNull(type.getSerialiser());
assertTrue(type.getAggregateFunction() instanceof ExampleAggregateFunction);
// Entity definitions
SchemaElementDefinition entityDefinition = schema.getEntity(TestGroups.ENTITY);
assertNotNull(entityDefinition);
assertEquals(ENTITY_DESCRIPTION, entityDefinition.getDescription());
assertTrue(entityDefinition.containsProperty(TestPropertyNames.PROP_1));
type = entityDefinition.getPropertyTypeDef(TestPropertyNames.PROP_1);
assertEquals(0, entityDefinition.getGroupBy().size());
assertEquals(STRING_TYPE_DESCRIPTION, type.getDescription());
assertEquals(String.class, type.getClazz());
assertNull(type.getSerialiser());
assertTrue(type.getAggregateFunction() instanceof ExampleAggregateFunction);
validator = entityDefinition.getValidator();
valContexts = validator.getComponents();
index = 0;
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof IsXMoreThanY);
assertThat(tuplePredicate.getSelection()).hasSize(2);
assertEquals(TestPropertyNames.PROP_1, tuplePredicate.getSelection()[0]);
assertEquals(TestPropertyNames.VISIBILITY, tuplePredicate.getSelection()[1]);
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof IsA);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(IdentifierType.VERTEX.name(), tuplePredicate.getSelection()[0]);
tuplePredicate = valContexts.get(index++);
assertTrue(tuplePredicate.getPredicate() instanceof IsA);
assertThat(tuplePredicate.getSelection()).hasSize(1);
assertEquals(TestPropertyNames.PROP_1, tuplePredicate.getSelection()[0]);
final ElementAggregator aggregator = edgeDefinition.getFullAggregator();
final List<TupleAdaptedBinaryOperator<String, ?>> aggContexts = aggregator.getComponents();
assertThat(aggContexts).hasSize(3);
TupleAdaptedBinaryOperator<String, ?> aggContext = aggContexts.get(0);
assertTrue(aggContext.getBinaryOperator() instanceof ExampleAggregateFunction);
assertThat(aggContext.getSelection()).hasSize(1);
assertEquals(TestPropertyNames.PROP_2, aggContext.getSelection()[0]);
aggContext = aggContexts.get(1);
assertTrue(aggContext.getBinaryOperator() instanceof ExampleAggregateFunction);
assertThat(aggContext.getSelection()).hasSize(1);
assertEquals(TestPropertyNames.DATE, aggContext.getSelection()[0]);
TypeDefinition mapTypeDef = schema.getType(TestTypes.PROP_MAP);
assertEquals(LinkedHashMap.class, mapTypeDef.getClazz());
assertEquals(MAP_TYPE_DESCRIPTION, mapTypeDef.getDescription());
Serialiser serialiser = mapTypeDef.getSerialiser();
assertEquals(MapSerialiser.class, serialiser.getClass());
MapSerialiser mapSerialiser = (MapSerialiser) serialiser;
assertEquals(StringSerialiser.class, mapSerialiser.getKeySerialiser().getClass());
assertEquals(RawLongSerialiser.class, mapSerialiser.getValueSerialiser().getClass());
assertNull(mapSerialiser.getMapClass());
}
use of uk.gov.gchq.koryphe.impl.predicate.IsXMoreThanY in project Gaffer by gchq.
the class SchemaElementDefinitionTest method shouldReturnFullValidatorWithoutIsA.
@Test
public void shouldReturnFullValidatorWithoutIsA() {
// Given
final T elementDef = createBuilder().property("property", PROPERTY_STRING_TYPE).property("property1", PROPERTY_STRING_TYPE).property("property2", PROPERTY_STRING_TYPE).validator(new ElementFilter.Builder().select("property1", "property2").execute(new IsXMoreThanY()).build()).build();
setupSchema(elementDef);
// When
final ElementFilter validator = elementDef.getValidator(false);
// Then
int i = 0;
assertEquals(IsXMoreThanY.class, validator.getComponents().get(i).getPredicate().getClass());
assertArrayEquals(new String[] { "property1", "property2" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(Exists.class, validator.getComponents().get(i).getPredicate().getClass());
assertArrayEquals(new String[] { "property" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(Exists.class, validator.getComponents().get(i).getPredicate().getClass());
assertArrayEquals(new String[] { "property1" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(Exists.class, validator.getComponents().get(i).getPredicate().getClass());
assertArrayEquals(new String[] { "property2" }, validator.getComponents().get(i).getSelection());
i++;
assertEquals(i, validator.getComponents().size());
// Check the validator is cached
// Check the validator is cached
assertSame(validator, elementDef.getValidator(false));
assertNotSame(validator, elementDef.getValidator(true));
}
Aggregations