use of uk.gov.gchq.koryphe.impl.function.ApplyBiFunction in project Gaffer by gchq.
the class GetAllElementsIT method shouldAllowBiFunctionInView.
@Test
@TraitRequirement({ StoreTrait.TRANSFORMATION })
public void shouldAllowBiFunctionInView() throws OperationException {
final Map<String, Class<?>> transientProperties = new HashMap<>();
transientProperties.put("propLong", Long.class);
transientProperties.put("combined", Long.class);
final List<TupleAdaptedFunction<String, ?, ?>> transformFunctions = new ArrayList<>();
final TupleAdaptedFunction<String, Integer, Long> convertToLong = new TupleAdaptedFunction<>();
convertToLong.setSelection(new String[] { TestPropertyNames.INT });
convertToLong.setFunction((Function) new ToLong());
convertToLong.setProjection(new String[] { "propLong" });
final TupleAdaptedFunction<String, Integer, Long> sum = new TupleAdaptedFunction<>();
sum.setSelection(new String[] { "propLong", TestPropertyNames.COUNT });
sum.setFunction(new ApplyBiFunction(new Sum()));
sum.setProjection(new String[] { "combined" });
transformFunctions.add(convertToLong);
transformFunctions.add(sum);
final GetAllElements get = new GetAllElements.Builder().view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().transientProperties(transientProperties).addTransformFunctions(transformFunctions).build()).build()).build();
final CloseableIterable<? extends Element> results = graph.execute(get, user);
for (final Element result : results) {
final Long expectedResult = (Long) result.getProperty("propLong") + (Long) result.getProperty(TestPropertyNames.COUNT);
final Long combined = (Long) result.getProperty("combined");
assertThat(combined).isEqualTo(expectedResult);
}
}
Aggregations