use of uk.gov.gchq.gaffer.operation.impl.function.Transform in project Gaffer by gchq.
the class TransformHandlerTest method shouldSelectMatchedVertexForTransform.
@Test
public void shouldSelectMatchedVertexForTransform() throws OperationException {
// Given
given(store.getSchema()).willReturn(schema);
final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source("srcVal").dest("destVal").matchedVertex(EdgeId.MatchedVertex.SOURCE).build();
final Transform transform = new Transform.Builder().input(edge).edge(TestGroups.EDGE, new ElementTransformer.Builder().select(IdentifierType.MATCHED_VERTEX.name()).execute(new Identity()).project(TestPropertyNames.PROP_3).build()).build();
// When
final Iterable<? extends Element> results = handler.doOperation(transform, context, store);
// Then
final Edge expectedEdge = new Edge.Builder().group(TestGroups.EDGE).source("srcVal").dest("destVal").matchedVertex(EdgeId.MatchedVertex.SOURCE).property(TestPropertyNames.PROP_3, "srcVal").build();
ElementUtil.assertElementEquals(Collections.singletonList(expectedEdge), results);
}
use of uk.gov.gchq.gaffer.operation.impl.function.Transform in project Gaffer by gchq.
the class TransformHandlerTest method shouldFailValidationWhenElementTransformerOperationIsNull.
@Test
public void shouldFailValidationWhenElementTransformerOperationIsNull() {
// Given
given(store.getSchema()).willReturn(schema);
final Entity entity = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).property(TestPropertyNames.PROP_2, TestPropertyNames.STRING).build();
final Entity entity1 = new Entity.Builder().group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, TestPropertyNames.INT).build();
final ElementTransformer transformer = new ElementTransformer.Builder().select(TestPropertyNames.PROP_1).execute(null).project(TestPropertyNames.PROP_3).build();
input.add(entity);
input.add(entity1);
final Transform transform = new Transform.Builder().input(input).entity(TestGroups.ENTITY, transformer).build();
// When / Then
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(transform, context, store)).withMessageContaining(transformer.getClass().getSimpleName() + " contains a null function.");
}
use of uk.gov.gchq.gaffer.operation.impl.function.Transform in project Gaffer by gchq.
the class FederatedTransformHandlerTest method shouldDelegateToHandler.
@Test
public void shouldDelegateToHandler() throws OperationException {
// Given
final FederatedStore store = mock(FederatedStore.class);
final TransformHandler handler = mock(TransformHandler.class);
final Transform op = mock(Transform.class);
final Context context = mock(Context.class);
final Iterable expectedResult = mock(Iterable.class);
final Schema schema = mock(Schema.class);
given(store.getSchema(op, context)).willReturn(schema);
given(handler.doOperation(op, schema)).willReturn(expectedResult);
final FederatedTransformHandler federatedHandler = new FederatedTransformHandler(handler);
// When
final Object result = federatedHandler.doOperation(op, context, store);
// Then
assertSame(expectedResult, result);
verify(handler).doOperation(op, schema);
}
Aggregations