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);
}
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());
}
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);
}
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);
}
}
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());
}
Aggregations