use of uk.gov.gchq.gaffer.function.AggregateFunction in project Gaffer by gchq.
the class ElementAggregatorTest method shouldCloneAggregator.
@Test
public void shouldCloneAggregator() {
// Given
final String reference1 = "reference1";
final ElementAggregator aggregator = new ElementAggregator();
final PassThroughFunctionContext<String, AggregateFunction> functionContext1 = mock(PassThroughFunctionContext.class);
final AggregateFunction function = mock(AggregateFunction.class);
final AggregateFunction clonedFunction = mock(AggregateFunction.class);
given(functionContext1.getFunction()).willReturn(function);
given(functionContext1.getSelection()).willReturn(Collections.singletonList(reference1));
given(function.statelessClone()).willReturn(clonedFunction);
aggregator.addFunction(functionContext1);
// When
final ElementAggregator clone = aggregator.clone();
// Then
assertNotSame(aggregator, clone);
assertEquals(1, clone.getFunctions().size());
final PassThroughFunctionContext<String, AggregateFunction> 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());
}
use of uk.gov.gchq.gaffer.function.AggregateFunction in project Gaffer by gchq.
the class AggregatorTest method shouldAddAndInitAggregateFunction.
@Test
public void shouldAddAndInitAggregateFunction() {
// Given
final Aggregator<String> aggregator = new Aggregator<>();
final PassThroughFunctionContext<String, AggregateFunction> functionContext1 = mock(PassThroughFunctionContext.class);
final AggregateFunction function1 = mock(AggregateFunction.class);
given(functionContext1.getFunction()).willReturn(function1);
// When
aggregator.addFunction(functionContext1);
aggregator.initFunctions();
// Then
verify(functionContext1).getFunction();
verify(function1).init();
}
use of uk.gov.gchq.gaffer.function.AggregateFunction in project Gaffer by gchq.
the class AggregatorTest method shouldBuildAggregator.
@Test
public void shouldBuildAggregator() {
// Given
final String reference1 = "reference 1";
final String reference2 = "reference 2";
final String reference3a = "reference 3a";
final String reference3b = "reference 3b";
final String reference5 = "reference 5";
final AggregateFunction func1 = mock(AggregateFunction.class);
final AggregateFunction func3 = mock(AggregateFunction.class);
final AggregateFunction func4 = mock(AggregateFunction.class);
final AggregateFunction func5 = mock(AggregateFunction.class);
// When - check you can build the selection/function in any order,
// although normally it will be done - select then aggregate.
final Aggregator<String> aggregator = new Aggregator.Builder<String>().select(reference1).execute(func1).select(reference2).select(reference3a, reference3b).execute(func3).execute(func4).execute(func5).select(reference5).build();
// Then
int i = 0;
PassThroughFunctionContext<String, AggregateFunction> context = aggregator.getFunctions().get(i++);
assertEquals(1, context.getSelection().size());
assertEquals(reference1, context.getSelection().get(0));
assertSame(func1, context.getFunction());
context = aggregator.getFunctions().get(i++);
assertEquals(1, context.getSelection().size());
assertEquals(reference2, context.getSelection().get(0));
context = aggregator.getFunctions().get(i++);
assertEquals(2, context.getSelection().size());
assertEquals(reference3a, context.getSelection().get(0));
assertEquals(reference3b, context.getSelection().get(1));
assertSame(func3, context.getFunction());
context = aggregator.getFunctions().get(i++);
assertSame(func4, context.getFunction());
context = aggregator.getFunctions().get(i++);
assertSame(func5, context.getFunction());
assertEquals(1, context.getSelection().size());
assertEquals(reference5, context.getSelection().get(0));
assertEquals(i, aggregator.getFunctions().size());
}
Aggregations