use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class WhileHandlerTest method shouldThrowExceptionWhenPredicateCannotAcceptInputType.
@Test
public void shouldThrowExceptionWhenPredicateCannotAcceptInputType() throws OperationException {
// Given
final Predicate predicate = new IsFalse();
final Object input = new EntitySeed();
final Conditional conditional = new Conditional(predicate);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final While operation = new While.Builder<>().input(input).conditional(conditional).operation(new GetElements()).build();
final WhileHandler handler = new WhileHandler();
// When / Then
try {
handler.doOperation(operation, context, store);
fail("Exception expected");
} catch (final OperationException e) {
assertTrue(e.getMessage().contains("The predicate '" + predicate.getClass().getSimpleName() + "' cannot accept an input of type '" + input.getClass().getSimpleName() + "'"));
}
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class WhileHandlerTest method shouldFailPredicateTestAndNotExecuteDelegateOperation.
@Test
public void shouldFailPredicateTestAndNotExecuteDelegateOperation() throws OperationException {
// Given
final Edge input = new Edge.Builder().group("testEdge").source("src").dest("dest").directed(true).property("count", 3).build();
final Map<Element, Object> transform = new Map.Builder<Element>().first(new ExtractProperty("count")).build();
final Predicate predicate = new IsMoreThan(5);
final Conditional conditional = new Conditional(predicate, transform);
final Context context = mock(Context.class);
final Store store = mock(Store.class);
final GetElements getElements = mock(GetElements.class);
final While operation = new While.Builder<>().input(input).maxRepeats(1).conditional(conditional).operation(getElements).build();
final WhileHandler handler = new WhileHandler();
// When
handler.doOperation(operation, context, store);
// Then
verify(store, never()).execute((Output) getElements, context);
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class GetWalksIT method shouldReturnAllWalksWhenConditionalIsUnconfigured.
@Test
public void shouldReturnAllWalksWhenConditionalIsUnconfigured() throws Exception {
final Iterable<Walk> walks = executeGetWalksApplyingConditional(new Conditional());
assertThat(getPaths(walks)).isEqualTo("AED,ABC");
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class GetWalksIT method shouldGetPathsWithWhile.
@Test
public void shouldGetPathsWithWhile() throws Exception {
// Given
final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
final GetWalks op = new Builder().input(seedA).operations(new While.Builder<>().conditional(new Conditional(// This will always be true
new Exists(), new Map.Builder<>().first(new AssertEntityIdsUnwrapped()).build())).operation(operation).maxRepeats(2).build()).build();
// When
final Iterable<Walk> results = graph.execute(op, getUser());
// Then
assertThat(getPaths(results)).isEqualTo("AED,ABC");
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class IfIT method shouldRunOtherwiseOperationsWhenConditionIsFalse.
@Test
public void shouldRunOtherwiseOperationsWhenConditionIsFalse() throws OperationException {
// Given
final If<Object, Object> ifOperation = new If<>();
ifOperation.setInput(INPUT_CAMEL_CASE);
ifOperation.setConditional(new Conditional(new IsA("java.lang.Integer")));
ifOperation.setThen(new Map<>(Lists.newArrayList(new ToUpperCase(), new ToList())));
ifOperation.setOtherwise(new Map<>(Lists.newArrayList(new ToLowerCase(), new ToList())));
// When
final Object output = graph.execute(ifOperation, getUser());
// Then
assertThat(output).isEqualTo(Lists.newArrayList(INPUT_CAMEL_CASE.toLowerCase())).isInstanceOf(List.class);
}
Aggregations