Search in sources :

Example 1 with ToList

use of uk.gov.gchq.koryphe.impl.function.ToList 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);
}
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 2 with ToList

use of uk.gov.gchq.koryphe.impl.function.ToList 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);
}
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) Test(org.junit.Test)

Example 3 with ToList

use of uk.gov.gchq.koryphe.impl.function.ToList 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 4 with ToList

use of uk.gov.gchq.koryphe.impl.function.ToList 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 5 with ToList

use of uk.gov.gchq.koryphe.impl.function.ToList 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)

Aggregations

Test (org.junit.Test)5 If (uk.gov.gchq.gaffer.operation.impl.If)5 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)5 ToList (uk.gov.gchq.koryphe.impl.function.ToList)5 IsA (uk.gov.gchq.koryphe.impl.predicate.IsA)5 ToLowerCase (uk.gov.gchq.koryphe.impl.function.ToLowerCase)3 ToLong (uk.gov.gchq.koryphe.impl.function.ToLong)2 ToUpperCase (uk.gov.gchq.koryphe.impl.function.ToUpperCase)2