use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.
the class IfHandlerTest method shouldExecuteCorrectlyWithOperationChainAsThen.
@Test
public void shouldExecuteCorrectlyWithOperationChainAsThen() 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 OperationChain<Object> then = mock(OperationChain.class);
final GetAllElements otherwise = mock(GetAllElements.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
final Object result = handler.doOperation(filter, context, store);
// Then
verify(store).execute(then, context);
verify(store, never()).execute(otherwise, context);
}
use of uk.gov.gchq.gaffer.operation.impl.If in project Gaffer by gchq.
the class IfHandlerTest method shouldExecuteThenWithBooleanCondition.
@Test
public void shouldExecuteThenWithBooleanCondition() throws OperationException {
// Given
final Object input = Arrays.asList(new EntitySeed("1"), new EntitySeed("2"));
final GetElements then = mock(GetElements.class);
final GetAllElements otherwise = mock(GetAllElements.class);
final If filter = new If.Builder<>().input(input).condition(true).then(then).otherwise(otherwise).build();
final IfHandler handler = new IfHandler();
// When
handler.doOperation(filter, context, store);
// Then
verify(store).execute(then, context);
verify(store, never()).execute(otherwise, context);
}
use of uk.gov.gchq.gaffer.operation.impl.If 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);
}
use of uk.gov.gchq.gaffer.operation.impl.If 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.impl.If 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);
}
Aggregations