Search in sources :

Example 6 with Conditional

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.");
}
Also used : GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) While(uk.gov.gchq.gaffer.operation.impl.While) Test(org.junit.jupiter.api.Test)

Example 7 with Conditional

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());
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 8 with Conditional

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 9 with Conditional

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);
}
Also used : EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 10 with Conditional

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);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Element(uk.gov.gchq.gaffer.data.element.Element) Store(uk.gov.gchq.gaffer.store.Store) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) While(uk.gov.gchq.gaffer.operation.impl.While) Predicate(java.util.function.Predicate) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Aggregations

Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)30 Test (org.junit.jupiter.api.Test)18 If (uk.gov.gchq.gaffer.operation.impl.If)16 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)14 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)10 Test (org.junit.Test)9 Operation (uk.gov.gchq.gaffer.operation.Operation)9 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)9 GetWalks (uk.gov.gchq.gaffer.operation.impl.GetWalks)7 Map (uk.gov.gchq.gaffer.operation.impl.Map)6 While (uk.gov.gchq.gaffer.operation.impl.While)6 LinkedHashMap (java.util.LinkedHashMap)5 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)5 Context (uk.gov.gchq.gaffer.store.Context)5 ToList (uk.gov.gchq.koryphe.impl.function.ToList)5 IsA (uk.gov.gchq.koryphe.impl.predicate.IsA)5 HashMap (java.util.HashMap)4 Walk (uk.gov.gchq.gaffer.data.graph.Walk)4 LinkedList (java.util.LinkedList)3 Predicate (java.util.function.Predicate)3