use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class ViewElementDefinitionTest method shouldJsonSerialiseAndDeserialise.
@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
// Given
final ViewElementDefinition elementDef = new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_1, String.class).transientProperty(TestPropertyNames.PROP_2, String.class).properties(TestPropertyNames.COUNT, TestPropertyNames.DATE).preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsMoreThan(5)).build()).aggregator(new ElementAggregator.Builder().select(TestPropertyNames.COUNT).execute(new Max()).build()).postAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsLessThan(10)).build()).transformer(new ElementTransformer.Builder().select(TestPropertyNames.COUNT).execute(new TestTransform()).project(TestPropertyNames.PROP_1).build()).postTransformFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new IsEqual("9")).build()).build();
// When
final byte[] json = JSONSerialiser.serialise(elementDef, true);
final ViewElementDefinition deserialisedElementDef = JSONSerialiser.deserialise(json, ViewElementDefinition.class);
assertEquals(Sets.newHashSet(TestPropertyNames.COUNT, TestPropertyNames.DATE), deserialisedElementDef.getProperties());
assertNull(deserialisedElementDef.getExcludeProperties());
final List<TupleAdaptedPredicate<String, ?>> preFilterComponents = deserialisedElementDef.getPreAggregationFilter().getComponents();
assertThat(preFilterComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.COUNT }, preFilterComponents.get(0).getSelection());
assertEquals(new IsMoreThan(5), preFilterComponents.get(0).getPredicate());
final List<TupleAdaptedBinaryOperator<String, ?>> aggComponents = deserialisedElementDef.getAggregator().getComponents();
assertThat(aggComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.COUNT }, aggComponents.get(0).getSelection());
assertEquals(new Max(), aggComponents.get(0).getBinaryOperator());
final List<TupleAdaptedPredicate<String, ?>> postFilterComponents = deserialisedElementDef.getPostAggregationFilter().getComponents();
assertThat(postFilterComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.COUNT }, postFilterComponents.get(0).getSelection());
assertEquals(new IsLessThan(10), postFilterComponents.get(0).getPredicate());
final List<TupleAdaptedFunction<String, ?, ?>> transformComponents = deserialisedElementDef.getTransformer().getComponents();
assertThat(transformComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.COUNT }, transformComponents.get(0).getSelection());
assertEquals(new TestTransform(), transformComponents.get(0).getFunction());
assertArrayEquals(new String[] { TestPropertyNames.PROP_1 }, transformComponents.get(0).getProjection());
final List<TupleAdaptedPredicate<String, ?>> postTransformFilterComponents = deserialisedElementDef.getPostTransformFilter().getComponents();
assertThat(postTransformFilterComponents).hasSize(1);
assertArrayEquals(new String[] { TestPropertyNames.PROP_1 }, postTransformFilterComponents.get(0).getSelection());
assertEquals(new IsEqual("9"), postTransformFilterComponents.get(0).getPredicate());
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class ConditionalTest method shouldNotFailToShallowCloneWhenTransformIsNull.
@Test
public void shouldNotFailToShallowCloneWhenTransformIsNull() {
// Given
final Operation transform = null;
final Conditional conditional = new Conditional(new IsMoreThan(1), transform);
// When
final Conditional clone = conditional.shallowClone();
// Then
assertNotSame(conditional, clone);
assertNull(clone.getTransform());
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class GetWalksIT method shouldGetPathsWithModifiedViews.
@Test
public void shouldGetPathsWithModifiedViews() throws OperationException {
// Given
final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.COUNT).execute(new IsMoreThan(0L)).build()).build()).build()).build();
final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operation).build();
// When
final Iterable<Walk> results = graph.execute(op, getUser());
// Then
assertThat(getPaths(results)).isEqualTo("AED,ABC");
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsByEdgeIdWithViewRestrictedByGroupAndAPreAggregationFilter.
@Test
public void testGetElementsByEdgeIdWithViewRestrictedByGroupAndAPreAggregationFilter() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetElements getElements = new GetElements.Builder().input(new EdgeSeed("A", "B0", true)).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new IsMoreThan(5)).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(element -> {
if (element instanceof Entity) {
return ((Entity) element).getVertex().equals("A") || ((Entity) element).getVertex().equals("B0");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") && edge.getDestination().equals("B0");
}
}).filter(e -> e.getGroup().equals(GetAllElementsHandlerTest.BASIC_EDGE1) && ((int) e.getProperty(GetAllElementsHandlerTest.COUNT)) > 5).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
use of uk.gov.gchq.koryphe.impl.predicate.IsMoreThan in project Gaffer by gchq.
the class GetElementsHandlerTest method testGetElementsByEdgeSeedWithViewRestrictedByGroupAndAPostTransformFilter.
@Test
public void testGetElementsByEdgeSeedWithViewRestrictedByGroupAndAPostTransformFilter() throws OperationException {
// Given
final Graph graph = GetAllElementsHandlerTest.getGraph();
final AddElements addElements = new AddElements.Builder().input(getElements()).build();
graph.execute(addElements, new User());
// When
final GetElements getElements = new GetElements.Builder().input(new EdgeSeed("A", "B0", true)).view(new View.Builder().edge(GetAllElementsHandlerTest.BASIC_EDGE1, new ViewElementDefinition.Builder().transformer(new ElementTransformer.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new ExampleTransform()).project(GetAllElementsHandlerTest.COUNT).build()).postTransformFilter(new ElementFilter.Builder().select(GetAllElementsHandlerTest.COUNT).execute(new IsMoreThan(50)).build()).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
// Then
final Set<Element> resultsSet = new HashSet<>();
Streams.toStream(results).forEach(resultsSet::add);
final Set<Element> expectedResults = new HashSet<>();
getElements().stream().filter(e -> e.getGroup().equals(GetAllElementsHandlerTest.BASIC_EDGE1)).filter(element -> {
if (element instanceof Entity) {
return ((Entity) element).getVertex().equals("A") || ((Entity) element).getVertex().equals("B0");
} else {
final Edge edge = (Edge) element;
return edge.getSource().equals("A") && edge.getDestination().equals("B0");
}
}).map(element -> {
element.putProperty(GetAllElementsHandlerTest.COUNT, ((Integer) element.getProperty(GetAllElementsHandlerTest.COUNT)) + ExampleTransform.INCREMENT_BY);
return element;
}).filter(element -> ((Integer) element.getProperty(GetAllElementsHandlerTest.COUNT)) > 50).forEach(expectedResults::add);
assertEquals(expectedResults, resultsSet);
}
Aggregations