use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class IfIT method shouldDoOtherwiseWhenConditionIsFalseAndNoThenOperation.
@Test
public void shouldDoOtherwiseWhenConditionIsFalseAndNoThenOperation() 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.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);
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class IfHandlerTest method shouldExecuteThenOperationWhenConditionMet.
@Test
public void shouldExecuteThenOperationWhenConditionMet() throws OperationException {
// Given
final Object input = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
final Conditional conditional = mock(Conditional.class);
final Predicate<Object> predicate = mock(Predicate.class);
final GetWalks then = mock(GetWalks.class);
final GetElements otherwise = mock(GetElements.class);
final If filter = new If.Builder<>().input(input).conditional(conditional).then(then).otherwise(otherwise).build();
final IfHandler handler = new IfHandler();
given(conditional.getPredicate()).willReturn(predicate);
given(predicate.test(input)).willReturn(true);
// When
handler.doOperation(filter, context, store);
// Then
verify(predicate).test(input);
verify(store).execute(then, context);
verify(store, never()).execute(otherwise, context);
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class IfHandlerTest method shouldExecuteOtherwiseOperationWhenConditionNotMet.
@Test
public void shouldExecuteOtherwiseOperationWhenConditionNotMet() throws OperationException {
// Given
final Object input = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
final Conditional conditional = mock(Conditional.class);
final Predicate<Object> predicate = mock(Predicate.class);
final GetWalks then = mock(GetWalks.class);
final GetElements otherwise = mock(GetElements.class);
final If filter = new If.Builder<>().input(input).conditional(conditional).then(then).otherwise(otherwise).build();
final IfHandler handler = new IfHandler();
given(conditional.getPredicate()).willReturn(predicate);
given(predicate.test(input)).willReturn(false);
// When
handler.doOperation(filter, context, store);
// Then
verify(predicate).test(input);
verify(store, never()).execute(then, context);
verify(store).execute(otherwise, context);
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class IfHandlerTest method shouldReturnInitialInputForNullOperations.
@Test
public void shouldReturnInitialInputForNullOperations() throws OperationException {
// Given
final Object input = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
final Conditional conditional = mock(Conditional.class);
final Predicate<Object> predicate = mock(Predicate.class);
final GetWalks then = null;
final GetElements otherwise = null;
final If filter = new If.Builder<>().input(input).conditional(conditional).then(then).otherwise(otherwise).build();
given(conditional.getPredicate()).willReturn(predicate);
given(predicate.test(input)).willReturn(true);
final IfHandler handler = new IfHandler();
// When
final Object result = handler.doOperation(filter, context, store);
// Then
assertEquals(result, input);
verify(predicate).test(input);
verify(store, never()).execute(then, context);
verify(store, never()).execute(otherwise, context);
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class IfHandlerTest method shouldCorrectlyExecutePrePredicateTransformUsingConditional.
@Test
public void shouldCorrectlyExecutePrePredicateTransformUsingConditional() throws OperationException {
// Given
final Object input = Arrays.asList(new EntitySeed("A"), new EntitySeed("B"));
final Object intermediate = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
final Conditional conditional = mock(Conditional.class);
final Predicate<Object> predicate = mock(Predicate.class);
final OperationChain<Object> transform = mock(OperationChain.class);
final GetElements then = mock(GetElements.class);
final GetAllElements otherwise = mock(GetAllElements.class);
final If filter = new If.Builder<>().input(input).conditional(conditional).then(then).build();
final IfHandler handler = new IfHandler();
given(conditional.getPredicate()).willReturn(predicate);
given(conditional.getTransform()).willReturn(transform);
given(store.execute(transform, context)).willReturn(intermediate);
given(predicate.test(intermediate)).willReturn(true);
// When
final Object result = handler.doOperation(filter, context, store);
// Then
verify(predicate).test(intermediate);
verify(predicate, never()).test(input);
verify(store).execute(transform, context);
verify(store).execute(then, context);
verify(store, never()).execute(otherwise, context);
}
Aggregations