use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class WhileScoreResolverTest method shouldThrowErrorWhenNoDefaultResolverConfigured.
@Test
public void shouldThrowErrorWhenNoDefaultResolverConfigured() {
// Given
final WhileScoreResolver resolver = new WhileScoreResolver();
final While operation = new While.Builder<>().conditional(new Conditional()).operation(new GetAllElements()).build();
// When / Then
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> resolver.getScore(operation)).withMessage("Default Score Resolver has not been provided.");
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class IfTest method shouldShallowCloneOperation.
@Test
@Override
public void shouldShallowCloneOperation() {
// Given
final Object input = "testInput";
final If ifOp = new If.Builder<>().input(input).condition(true).conditional(new Conditional()).then(new GetElements.Builder().input(new EntitySeed("A")).build()).otherwise(new GetAllElements()).build();
// When
final If clone = ifOp.shallowClone();
// Then
assertNotSame(ifOp, clone);
assertEquals(input, clone.getInput());
}
use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldHandleNestedOperationChain.
@Test
public void shouldHandleNestedOperationChain() throws SerialisationException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation validate = new Validate();
Operation getAdjacentIds = new GetAdjacentIds();
Operation count = new Count<>();
Operation countGroups = new CountGroups();
Operation getElements = new GetElements();
If ifOp = new If.Builder<>().conditional(new Conditional(new Exists(), new GetElements())).then(new GetElements()).otherwise(new GetAllElements()).build();
Operation getAllElements = new GetAllElements();
Operation limit = new Limit<>();
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(new OperationChain.Builder().first(getElements).then(getAllElements).build()).then(ifOp).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then((Operation) new OperationChain.Builder().first(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).build()).then(new If.Builder<>().conditional(new Conditional(new Exists(), new OperationChain<>(new CountGroups(), new GetElements()))).then(new OperationChain<>(new CountGroups(), new GetElements())).otherwise(new OperationChain<>(new GetAllElements(), new Limit<>(), new Validate())).build()).then(new Count()).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.util.Conditional 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.util.Conditional in project Gaffer by gchq.
the class WhileHandlerTest method shouldUpdateTransformInputAndTestAgainstPredicate.
@Test
public void shouldUpdateTransformInputAndTestAgainstPredicate() throws OperationException {
final Edge input = new Edge.Builder().group("testEdge").source("src").dest("dest").directed(true).property("count", 3).build();
final Map<Element, Object> transform = mock(Map.class);
final Map<Element, Object> transformClone = mock(Map.class);
given(transform.shallowClone()).willReturn(transformClone);
final Predicate predicate = new IsMoreThan(2);
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(transformClone).setInput(input);
verify(store).execute(transformClone, context);
}
Aggregations