Search in sources :

Example 16 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class AndTest method shouldConstructInputTypesCorrectly.

@Test
public void shouldConstructInputTypesCorrectly() {
    // Given
    final ConsumerFunctionContext<Integer, FilterFunction> funcContext1 = mock(ConsumerFunctionContext.class);
    final ConsumerFunctionContext<Integer, FilterFunction> funcContext2 = mock(ConsumerFunctionContext.class);
    final FilterFunction func1 = mock(FilterFunction.class);
    final FilterFunction func2 = mock(FilterFunction.class);
    final And and = new And(Arrays.asList(funcContext1, funcContext2));
    final Class<?>[] expectedInputClasses = new Class<?>[] { Integer.class, String.class, Long.class, Double.class };
    given(func1.getInputClasses()).willReturn(new Class<?>[] { Integer.class, Object.class });
    given(func2.getInputClasses()).willReturn(new Class<?>[] { String.class, Long.class, Double.class });
    given(funcContext1.getFunction()).willReturn(func1);
    given(funcContext2.getFunction()).willReturn(func2);
    given(funcContext1.getSelection()).willReturn(Arrays.asList(0, 1));
    given(funcContext2.getSelection()).willReturn(Arrays.asList(1, 2, 3));
    // When
    final Class<?>[] inputClasses = and.getInputClasses();
    // Then
    assertArrayEquals(expectedInputClasses, inputClasses);
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest) Test(org.junit.Test)

Example 17 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class AndTest method shouldClone.

@Test
public void shouldClone() {
    // Given
    final ConsumerFunctionContext<Integer, FilterFunction> funcContext1 = mock(ConsumerFunctionContext.class);
    final ConsumerFunctionContext<Integer, FilterFunction> funcContext2 = mock(ConsumerFunctionContext.class);
    final FilterFunction func1 = mock(FilterFunction.class);
    final FilterFunction func2 = mock(FilterFunction.class);
    final FilterFunction func1Cloned = mock(FilterFunction.class);
    final FilterFunction func2Cloned = mock(FilterFunction.class);
    final And and = new And(Arrays.asList(funcContext1, funcContext2));
    given(funcContext1.getFunction()).willReturn(func1);
    given(funcContext2.getFunction()).willReturn(func2);
    given(funcContext1.getSelection()).willReturn(Arrays.asList(0, 1, 3));
    given(funcContext2.getSelection()).willReturn(Arrays.asList(0, 2));
    given(func1.statelessClone()).willReturn(func1Cloned);
    given(func2.statelessClone()).willReturn(func2Cloned);
    // When
    final And clonedAnd = and.statelessClone();
    // Then
    assertNotSame(and, clonedAnd);
    assertNotNull(clonedAnd);
    assertEquals(2, clonedAnd.getFunctions().size());
    assertSame(func1Cloned, clonedAnd.getFunctions().get(0).getFunction());
    assertArrayEquals(new Integer[] { 0, 1, 3 }, clonedAnd.getFunctions().get(0).getSelection().toArray());
    assertSame(func2Cloned, clonedAnd.getFunctions().get(1).getFunction());
    assertArrayEquals(new Integer[] { 0, 2 }, clonedAnd.getFunctions().get(1).getSelection().toArray());
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest) Test(org.junit.Test)

Example 18 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class AndTest method shouldAcceptWhenAllFunctionsAccept.

@Test
public void shouldAcceptWhenAllFunctionsAccept() {
    // Given
    final String test = "test";
    final String test1a = "test1a";
    final String test1b = "test1b";
    final String test2a = "test2a";
    final ConsumerFunctionContext<Integer, FilterFunction> funcContext1 = mock(ConsumerFunctionContext.class);
    final ConsumerFunctionContext<Integer, FilterFunction> funcContext2 = mock(ConsumerFunctionContext.class);
    final FilterFunction func1 = mock(FilterFunction.class);
    final FilterFunction func2 = mock(FilterFunction.class);
    final And and = new And(Arrays.asList(funcContext1, funcContext2));
    given(funcContext1.getFunction()).willReturn(func1);
    given(funcContext2.getFunction()).willReturn(func2);
    given(funcContext1.select(Mockito.any(ArrayTuple.class))).willReturn(new Object[] { test, test1a, test1b });
    given(funcContext2.select(Mockito.any(ArrayTuple.class))).willReturn(new Object[] { test, test2a });
    given(func1.isValid(new String[] { test, test1a, test1b })).willReturn(true);
    given(func2.isValid(new String[] { test, test2a })).willReturn(true);
    // When
    boolean accepted = and.isValid(new String[] { test, test1a, test2a, test1b });
    // Then
    assertTrue(accepted);
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) ArrayTuple(uk.gov.gchq.gaffer.function.ArrayTuple) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest) Test(org.junit.Test)

Example 19 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class AndTest method shouldThrowExceptionWhenInputTypesAreNotCompatible.

@Test
public void shouldThrowExceptionWhenInputTypesAreNotCompatible() {
    // Given
    final ConsumerFunctionContext<Integer, FilterFunction> funcContext1 = mock(ConsumerFunctionContext.class);
    final ConsumerFunctionContext<Integer, FilterFunction> funcContext2 = mock(ConsumerFunctionContext.class);
    final FilterFunction func1 = mock(FilterFunction.class);
    final FilterFunction func2 = mock(FilterFunction.class);
    final And and = new And(Arrays.asList(funcContext1, funcContext2));
    given(func1.getInputClasses()).willReturn(new Class<?>[] { Integer.class, Date.class });
    given(func2.getInputClasses()).willReturn(new Class<?>[] { String.class, Long.class, Double.class });
    given(funcContext1.getFunction()).willReturn(func1);
    given(funcContext2.getFunction()).willReturn(func2);
    given(funcContext1.getSelection()).willReturn(Arrays.asList(0, 1));
    given(funcContext2.getSelection()).willReturn(Arrays.asList(1, 2, 3));
    // When / Then
    try {
        and.getInputClasses();
        fail("Exception expected");
    } catch (InputMismatchException e) {
        assertNotNull(e);
    }
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) InputMismatchException(java.util.InputMismatchException) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest) Test(org.junit.Test)

Example 20 with FilterFunction

use of uk.gov.gchq.gaffer.function.FilterFunction in project Gaffer by gchq.

the class ElementFilterTest method shouldCloneFilter.

@Test
public void shouldCloneFilter() {
    // Given
    final String reference1 = "reference1";
    final ElementFilter filter = new ElementFilter();
    final ConsumerFunctionContext<String, FilterFunction> functionContext1 = mock(ConsumerFunctionContext.class);
    final FilterFunction function = mock(FilterFunction.class);
    final FilterFunction clonedFunction = mock(FilterFunction.class);
    given(functionContext1.getFunction()).willReturn(function);
    given(functionContext1.getSelection()).willReturn(Collections.singletonList(reference1));
    given(function.statelessClone()).willReturn(clonedFunction);
    filter.addFunction(functionContext1);
    // When
    final ElementFilter clone = filter.clone();
    // Then
    assertNotSame(filter, clone);
    assertEquals(1, clone.getFunctions().size());
    final ConsumerFunctionContext<String, FilterFunction> resultClonedFunction = clone.getFunctions().get(0);
    assertEquals(1, resultClonedFunction.getSelection().size());
    assertEquals(reference1, resultClonedFunction.getSelection().get(0));
    assertNotSame(functionContext1, resultClonedFunction);
    assertNotSame(function, resultClonedFunction.getFunction());
    assertSame(clonedFunction, resultClonedFunction.getFunction());
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) Test(org.junit.Test)

Aggregations

FilterFunction (uk.gov.gchq.gaffer.function.FilterFunction)22 Test (org.junit.Test)14 FilterFunctionTest (uk.gov.gchq.gaffer.function.FilterFunctionTest)11 ConsumerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext)6 ArrayTuple (uk.gov.gchq.gaffer.function.ArrayTuple)4 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)4 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 And (uk.gov.gchq.gaffer.function.filter.And)2 Or (uk.gov.gchq.gaffer.function.filter.Or)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 HashMap (java.util.HashMap)1 InputMismatchException (java.util.InputMismatchException)1 List (java.util.List)1 Set (java.util.Set)1 Filter (org.apache.spark.sql.sources.Filter)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 ElementTuple (uk.gov.gchq.gaffer.data.element.ElementTuple)1 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)1