Search in sources :

Example 26 with Conditional

use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.

the class GetWalksIT method shouldNotFilterWalksWhenNoPredicateSupplied.

@Test
public void shouldNotFilterWalksWhenNoPredicateSupplied() throws Exception {
    final Conditional conditional = new Conditional();
    conditional.setTransform(new OperationChain.Builder().first(new Map.Builder<>().first(new ExtractWalkEntities()).then(new IterableConcat()).build()).then(new ForEach.Builder<>().operation(new Map.Builder<>().first(new ExtractProperty(TestPropertyNames.PROP_1)).build()).build()).build());
    final Iterable<Walk> walks = executeGetWalksApplyingConditional(conditional);
    assertThat(getPaths(walks)).isEqualTo("AED,ABC");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) ExtractWalkEntities(uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntities) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) IterableConcat(uk.gov.gchq.koryphe.impl.function.IterableConcat) HashMap(java.util.HashMap) Map(uk.gov.gchq.gaffer.operation.impl.Map) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) Test(org.junit.Test)

Example 27 with Conditional

use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.

the class IfIT method shouldReturnOriginalInputWhenConditionIsFalseAndNoOtherwise.

@Test
public void shouldReturnOriginalInputWhenConditionIsFalseAndNoOtherwise() 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 ToLong(), new ToList())));
    // When
    final Object output = graph.execute(ifOperation, getUser());
    // Then
    assertThat(output).isEqualTo(INPUT_CAMEL_CASE).isInstanceOf(String.class);
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToList(uk.gov.gchq.koryphe.impl.function.ToList) Test(org.junit.Test)

Example 28 with Conditional

use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.

the class IfIT method shouldReturnOriginalInputWhenConditionIsTrueAndNoThen.

@Test
public void shouldReturnOriginalInputWhenConditionIsTrueAndNoThen() throws OperationException {
    // Given
    final If<Object, Object> ifOperation = new If<>();
    ifOperation.setInput(INPUT_CAMEL_CASE);
    ifOperation.setConditional(new Conditional(new IsA("java.lang.String")));
    ifOperation.setOtherwise(new Map<>(Lists.newArrayList(new ToLong(), new ToList())));
    // When
    final Object output = graph.execute(ifOperation, getUser());
    // Then
    assertThat(output).isEqualTo(INPUT_CAMEL_CASE).isInstanceOf(String.class);
}
Also used : ToLong(uk.gov.gchq.koryphe.impl.function.ToLong) IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToList(uk.gov.gchq.koryphe.impl.function.ToList) Test(org.junit.Test)

Example 29 with Conditional

use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.

the class IfIT method shouldRunThenOperationWhenConditionIsTrue.

@Test
public void shouldRunThenOperationWhenConditionIsTrue() throws OperationException {
    // Given
    final If<Object, Object> ifOperation = new If<>();
    ifOperation.setInput(INPUT_CAMEL_CASE);
    ifOperation.setConditional(new Conditional(new IsA("java.lang.String")));
    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.toUpperCase())).isInstanceOf(List.class);
}
Also used : IsA(uk.gov.gchq.koryphe.impl.predicate.IsA) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) If(uk.gov.gchq.gaffer.operation.impl.If) ToLowerCase(uk.gov.gchq.koryphe.impl.function.ToLowerCase) ToList(uk.gov.gchq.koryphe.impl.function.ToList) ToUpperCase(uk.gov.gchq.koryphe.impl.function.ToUpperCase) Test(org.junit.Test)

Example 30 with Conditional

use of uk.gov.gchq.gaffer.operation.util.Conditional in project Gaffer by gchq.

the class GetWalksIT method getWalksThatPassPredicateTest.

private Iterable<Walk> getWalksThatPassPredicateTest(final Predicate predicate) throws Exception {
    final Conditional conditional = new Conditional();
    conditional.setTransform(new OperationChain.Builder().first(new Map.Builder<>().first(new ExtractWalkEntities()).then(new IterableConcat()).build()).then(new ForEach.Builder<>().operation(new Map.Builder<>().first(new ExtractProperty(TestPropertyNames.PROP_1)).build()).build()).build());
    conditional.setPredicate(predicate);
    return executeGetWalksApplyingConditional(conditional);
}
Also used : ExtractWalkEntities(uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntities) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) IterableConcat(uk.gov.gchq.koryphe.impl.function.IterableConcat) HashMap(java.util.HashMap) Map(uk.gov.gchq.gaffer.operation.impl.Map) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach)

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