Search in sources :

Example 11 with FilterFunction

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

the class NotTest method shouldAcceptTheValueWhenTheWrappedFunctionReturnsTrue.

@Test
public void shouldAcceptTheValueWhenTheWrappedFunctionReturnsTrue() {
    // Given
    final FilterFunction function = mock(FilterFunction.class);
    final Not filter = new Not(function);
    final Object[] input = new Object[] { "some value" };
    given(function.isValid(input)).willReturn(true);
    // When
    boolean accepted = filter.isValid(input);
    // Then
    assertFalse(accepted);
    verify(function).isValid(input);
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Example 12 with FilterFunction

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

the class NotTest method shouldClone.

@Test
public void shouldClone() {
    // Given
    final FilterFunction function = mock(FilterFunction.class);
    final FilterFunction clonedFunction = mock(FilterFunction.class);
    final Not filter = new Not(function);
    given(function.statelessClone()).willReturn(clonedFunction);
    // When
    final Not clonedFilter = filter.statelessClone();
    // Then
    assertNotSame(filter, clonedFilter);
    assertSame(clonedFunction, clonedFilter.getFunction());
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Example 13 with FilterFunction

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

the class OrTest method shouldAcceptWhenOneFunctionsAccepts.

@Test
public void shouldAcceptWhenOneFunctionsAccepts() {
    // 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 Or or = new Or(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(false);
    // When
    boolean accepted = or.isValid(new String[] { test, test1a, test2a, test1b });
    // Then
    assertTrue(accepted);
    verify(func1).isValid(new String[] { test, test1a, test1b });
    verify(func2, never()).isValid(new String[] { test, test2a });
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) ArrayTuple(uk.gov.gchq.gaffer.function.ArrayTuple) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Example 14 with FilterFunction

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

the class OrTest 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 Or or = new Or(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 Or clonedOr = or.statelessClone();
    // Then
    assertNotSame(or, clonedOr);
    assertNotNull(clonedOr);
    assertEquals(2, clonedOr.getFunctions().size());
    assertSame(func1Cloned, clonedOr.getFunctions().get(0).getFunction());
    assertArrayEquals(new Integer[] { 0, 1, 3 }, clonedOr.getFunctions().get(0).getSelection().toArray());
    assertSame(func2Cloned, clonedOr.getFunctions().get(1).getFunction());
    assertArrayEquals(new Integer[] { 0, 2 }, clonedOr.getFunctions().get(1).getSelection().toArray());
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Example 15 with FilterFunction

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

the class OrTest method shouldRejectWhenAllFunctionsReject.

@Test
public void shouldRejectWhenAllFunctionsReject() {
    // 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 ConsumerFunctionContext<Integer, FilterFunction> funcContext3 = mock(ConsumerFunctionContext.class);
    final FilterFunction func1 = mock(FilterFunction.class);
    final FilterFunction func2 = mock(FilterFunction.class);
    final FilterFunction func3 = mock(FilterFunction.class);
    final Or or = new Or(Arrays.asList(funcContext1, funcContext2, funcContext3));
    given(funcContext1.getFunction()).willReturn(func1);
    given(funcContext2.getFunction()).willReturn(func2);
    given(funcContext3.getFunction()).willReturn(func3);
    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(funcContext3.select(Mockito.any(ArrayTuple.class))).willReturn(new Object[] { test });
    given(func1.isValid(new String[] { test, test1a, test1b })).willReturn(false);
    given(func2.isValid(new String[] { test, test2a })).willReturn(false);
    given(func3.isValid(new String[] { test })).willReturn(false);
    // When
    boolean accepted = or.isValid(new String[] { test, test1a, test2a, test1b });
    // Then
    assertFalse(accepted);
    verify(func1).isValid(new String[] { test, test1a, test1b });
    verify(func2).isValid(new String[] { test, test2a });
    verify(func3, never()).isValid(new String[] { test, test2a });
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) ArrayTuple(uk.gov.gchq.gaffer.function.ArrayTuple) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

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