Search in sources :

Example 6 with ToSet

use of uk.gov.gchq.gaffer.operation.impl.output.ToSet 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");
}
Also used : ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) Set(java.util.Set) ToVertices(uk.gov.gchq.gaffer.operation.impl.output.ToVertices) OperationChainValidator(uk.gov.gchq.gaffer.store.operation.OperationChainValidator) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) OperationChainOptimiser(uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) IterableFunction(uk.gov.gchq.koryphe.impl.function.IterableFunction) FirstItem(uk.gov.gchq.koryphe.impl.function.FirstItem) Edge(uk.gov.gchq.gaffer.data.element.Edge) Map(uk.gov.gchq.gaffer.operation.impl.Map) Test(org.junit.jupiter.api.Test)

Aggregations

ToSet (uk.gov.gchq.gaffer.operation.impl.output.ToSet)6 Test (org.junit.jupiter.api.Test)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)3 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)3 Map (uk.gov.gchq.gaffer.operation.impl.Map)3 ToVertices (uk.gov.gchq.gaffer.operation.impl.output.ToVertices)3 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 ElementPropertyComparator (uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator)2 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)2 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 CsvGenerator (uk.gov.gchq.gaffer.data.generator.CsvGenerator)2 Operation (uk.gov.gchq.gaffer.operation.Operation)2 Sort (uk.gov.gchq.gaffer.operation.impl.compare.Sort)2 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)2 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)2 OperationChainValidator (uk.gov.gchq.gaffer.store.operation.OperationChainValidator)2 OperationChainOptimiser (uk.gov.gchq.gaffer.store.optimiser.OperationChainOptimiser)2