use of uk.gov.gchq.gaffer.operation.impl.ForEach in project Gaffer by gchq.
the class ForEachHandlerTest method shouldThrowExceptionWithNullOperation.
@Test
public void shouldThrowExceptionWithNullOperation() {
// Given
final Store store = mock(Store.class);
final Context context = new Context(new User());
final ForEach op = new ForEach.Builder<>().operation(null).input(Arrays.asList("1", "2")).build();
final ForEachHandler handler = new ForEachHandler();
// When / Then
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(op, context, store)).withMessage("Operation cannot be null");
}
use of uk.gov.gchq.gaffer.operation.impl.ForEach in project Gaffer by gchq.
the class ForEachHandlerTest method shouldThrowExceptionWithNullInput.
@Test
public void shouldThrowExceptionWithNullInput() {
// Given
final Store store = mock(Store.class);
final Context context = new Context(new User());
final ForEach op = new ForEach.Builder<>().operation(new GetElements()).build();
final ForEachHandler handler = new ForEachHandler();
// When / Then
assertThatExceptionOfType(OperationException.class).isThrownBy(() -> handler.doOperation(op, context, store)).withMessage("Inputs cannot be null");
}
use of uk.gov.gchq.gaffer.operation.impl.ForEach in project Gaffer by gchq.
the class ForEachHandlerTest method shouldExecuteAndReturnExpected.
@Test
public void shouldExecuteAndReturnExpected() throws OperationException {
// Given
final Store store = mock(Store.class);
final Context context = new Context(new User());
final InputOutput op = mock(InputOutput.class);
final InputOutput opClone = mock(InputOutput.class);
given(op.shallowClone()).willReturn(opClone);
final Object input = mock(Object.class);
final Object output = mock(Object.class);
final ForEach forEach = new ForEach.Builder<>().input(input).operation(op).build();
final ForEachHandler handler = new ForEachHandler();
given(store.execute(opClone, context)).willReturn(output);
// When
final List<Object> result = (List<Object>) handler.doOperation(forEach, context, store);
// Then
verify(opClone).setInput(input);
assertThat(result).hasSize(1);
assertSame(output, result.get(0));
}
use of uk.gov.gchq.gaffer.operation.impl.ForEach in project Gaffer by gchq.
the class GetWalksIT method shouldGetPathsWithEntities.
@Test
public void shouldGetPathsWithEntities() throws Exception {
// Given
final GetElements getEntities = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
final GetElements getElements = new GetElements.Builder().directedType(DirectedType.DIRECTED).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build()).build();
final GetWalks op = new GetWalks.Builder().input(seedA).operations(getElements, getElements, getEntities).build();
// When
final List<Walk> results = Lists.newArrayList(graph.execute(op, getUser()));
// Then
assertThat(getPaths(results)).isEqualTo("AED,ABC");
results.forEach(r -> r.getEntities().forEach(l -> {
assertThat(l).isNotEmpty();
}));
}
use of uk.gov.gchq.gaffer.operation.impl.ForEach in project Gaffer by gchq.
the class ForEachIT method shouldReturnEmptyIterableWithOperationThatDoesntImplementOutput.
@Test
public void shouldReturnEmptyIterableWithOperationThatDoesntImplementOutput() throws OperationException {
// Given
final ForEach<ElementSeed, Element> op = new ForEach.Builder<ElementSeed, Element>().operation(new DiscardOutput.Builder().build()).input(Collections.singletonList(new EdgeSeed(SOURCE_DIR_1, DEST_DIR_1, true))).build();
// When
final Iterable<? extends Element> results = graph.execute(op, getUser());
// Then
ElementUtil.assertElementEquals(Sets.newHashSet((ElementId) null), results);
}
Aggregations