use of uk.gov.gchq.gaffer.operation.impl.output.ToVertices in project Gaffer by gchq.
the class ToVerticesHandlerTest method shouldCorrectlyConvertEdgeSeedsWithEqualUseMatchedVertex.
@Test
public void shouldCorrectlyConvertEdgeSeedsWithEqualUseMatchedVertex() throws OperationException {
// Given
final List elementIds = Arrays.asList(new EdgeSeed(vertex1, vertex2, false, null), new EdgeSeed(vertex3, vertex4, false, null), new EdgeSeed(vertex5, vertex6, false, null), new EdgeSeed(vertex7, vertex8, false, null));
final ToVerticesHandler handler = new ToVerticesHandler();
final ToVertices operation = mock(ToVertices.class);
given(operation.getInput()).willReturn(elementIds);
given(operation.getUseMatchedVertex()).willReturn(ToVertices.UseMatchedVertex.EQUAL);
// When
final Iterable<Object> results = handler.doOperation(operation, new Context(), null);
// Then
assertThat(Sets.newHashSet(results)).containsOnly(vertex1, vertex3, vertex5, vertex7);
}
use of uk.gov.gchq.gaffer.operation.impl.output.ToVertices in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldAddIfOperation.
@Test
public void shouldAddIfOperation() throws SerialisationException {
// Given
final GetWalks getWalks = new GetWalks();
final uk.gov.gchq.gaffer.operation.impl.Map map = new uk.gov.gchq.gaffer.operation.impl.Map();
final ToVertices toVertices = new ToVertices();
final ToSet toSet = new ToSet();
final Exists exists = new Exists();
final Limit limit = new Limit();
final GetAllElements getAllElements = new GetAllElements();
final GetElements getElements = new GetElements();
final Conditional conditional = new Conditional();
conditional.setPredicate(exists);
final If ifOp = new If.Builder<>().conditional(conditional).then(getElements).otherwise(getAllElements).build();
final AddOperationsToChain hook = new AddOperationsToChain();
final Map<String, List<Operation>> after = new HashMap<>();
final List<Operation> afterOps = new LinkedList<>();
afterOps.add(ifOp);
afterOps.add(limit);
after.put("uk.gov.gchq.gaffer.operation.impl.output.ToSet", afterOps);
hook.setAfter(after);
final OperationChain opChain = new OperationChain.Builder().first(getWalks).then(map).then(toVertices).then(toSet).build();
// When
hook.preExecute(opChain, new Context());
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(getWalks).then(map).then(toVertices).then(toSet).then(ifOp).then(limit).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.output.ToVertices in project Gaffer by gchq.
the class MapHandlerTest method shouldProcessWalksWithEdgeExtraction.
@Test
public void shouldProcessWalksWithEdgeExtraction() throws OperationException {
// Given
final Iterable<Walk> walks = Arrays.asList(walk, walk1);
final Map<Iterable<Walk>, Iterable<Edge>> map = new Map.Builder<Iterable<Walk>>().input(walks).first(new IterableFunction.Builder<Walk>().first(new ExtractWalkEdgesFromHop(1)).then(new FirstItem<>()).build()).build();
final ToVertices toVertices = new ToVertices.Builder().edgeVertices(ToVertices.EdgeVertices.SOURCE).build();
final ToSet<Object> toSet = new ToSet<>();
final OperationChain<Set<?>> opChain = new OperationChain.Builder().first(map).then(toVertices).then(toSet).build();
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
final OperationChainHandler<Set<?>> opChainHandler = new OperationChainHandler<>(opChainValidator, opChainOptimisers);
given(store.handleOperation(map, context)).willReturn(Arrays.asList(EDGE_BC, EDGE_BD));
given(store.handleOperation(toVertices, context)).willReturn(Arrays.asList("B", "B"));
given(store.handleOperation(toSet, context)).willReturn(Sets.newHashSet("B", "B"));
// When
final Iterable<?> results = opChainHandler.doOperation(opChain, context, store);
// Then
assertThat((Iterable<String>) results).contains("B");
}
use of uk.gov.gchq.gaffer.operation.impl.output.ToVertices in project Gaffer by gchq.
the class MapHandlerTest method shouldProcessWalksInOperationChain.
@Test
public void shouldProcessWalksInOperationChain() throws OperationException {
// Given
final Iterable<Iterable<Set<Edge>>> walks = Arrays.asList(walk, walk1);
final Map<Iterable<Iterable<Set<Edge>>>, Iterable<Edge>> map = new Map.Builder<Iterable<Iterable<Set<Edge>>>>().input(walks).first(new IterableFunction.Builder<Iterable<Set<Edge>>>().first(new FirstItem<>()).then(new FirstItem<>()).build()).build();
final ToVertices toVertices = new ToVertices.Builder().edgeVertices(ToVertices.EdgeVertices.SOURCE).build();
final ToSet<Object> toSet = new ToSet<>();
final OperationChain<Set<?>> opChain = new OperationChain.Builder().first(map).then(toVertices).then(toSet).build();
final OperationChainValidator opChainValidator = mock(OperationChainValidator.class);
final List<OperationChainOptimiser> opChainOptimisers = Collections.emptyList();
given(opChainValidator.validate(any(), any(), any())).willReturn(new ValidationResult());
final OperationChainHandler<Set<?>> opChainHandler = new OperationChainHandler<>(opChainValidator, opChainOptimisers);
given(store.handleOperation(map, context)).willReturn(Arrays.asList(EDGE_AB, EDGE_CB));
given(store.handleOperation(toVertices, context)).willReturn(Arrays.asList("A", "C"));
given(store.handleOperation(toSet, context)).willReturn(Sets.newHashSet("A", "C"));
// When
final Iterable<?> results = opChainHandler.doOperation(opChain, context, store);
// Then
assertThat((Iterable<String>) results).containsOnly("A", "C");
}
Aggregations