use of uk.gov.gchq.gaffer.store.operation.OperationChainValidator in project Gaffer by gchq.
the class ValidateOperationChainHandlerTest method shouldValidateOperationChain.
@Test
public void shouldValidateOperationChain() throws OperationException {
// Given
final AddElements addElements = new AddElements();
final GetAdjacentIds getAdj = new GetAdjacentIds();
final GetElements getElements = new GetElements();
final DiscardOutput discardOutput = new DiscardOutput();
OperationChain chain = new OperationChain.Builder().first(addElements).then(getAdj).then(getElements).then(discardOutput).build();
ValidateOperationChain validateOperationChain = new ValidateOperationChain.Builder().operationChain(chain).build();
given(store.getOperationChainValidator()).willReturn(new OperationChainValidator(new ViewValidator()));
ValidateOperationChainHandler handler = new ValidateOperationChainHandler();
// When
ValidationResult result = handler.doOperation(validateOperationChain, context, store);
// Then
assertTrue(result.isValid());
}
use of uk.gov.gchq.gaffer.store.operation.OperationChainValidator 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.store.operation.OperationChainValidator 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