use of uk.gov.gchq.gaffer.data.element.PropertiesTuple in project Gaffer by gchq.
the class ElementAggregatorTest method shouldWrapPropertiesInPropertiesTupleAndCallSuper.
@Test
public void shouldWrapPropertiesInPropertiesTupleAndCallSuper() {
// Given
final String reference = "reference1";
final String value = "value";
final ElementAggregator aggregator = new ElementAggregator();
final PassThroughFunctionContext<String, AggregateFunction> functionContext1 = mock(PassThroughFunctionContext.class);
final AggregateFunction function = mock(AggregateFunction.class);
given(functionContext1.getFunction()).willReturn(function);
final List<String> references = Collections.singletonList(reference);
given(functionContext1.getSelection()).willReturn(references);
aggregator.addFunction(functionContext1);
final Properties properties = new Properties(reference, value);
final ArgumentCaptor<PropertiesTuple> propertiesTupleCaptor = ArgumentCaptor.forClass(PropertiesTuple.class);
given(functionContext1.select(propertiesTupleCaptor.capture())).willReturn(new String[] { value });
// When
aggregator.aggregate(properties);
// Then
verify(functionContext1, times(2)).getFunction();
assertSame(properties, propertiesTupleCaptor.getValue().getProperties());
final ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class);
verify(function).aggregate(argumentCaptor.capture());
assertEquals(value, argumentCaptor.getValue()[0]);
}
use of uk.gov.gchq.gaffer.data.element.PropertiesTuple in project Gaffer by gchq.
the class ElementAggregatorTest method shouldSetStateOnElement.
@Test
public void shouldSetStateOnElement() {
// Given
final Object[] state = { "state1", "state2" };
final ElementAggregator aggregator = new ElementAggregator();
final PassThroughFunctionContext<String, AggregateFunction> functionContext1 = mock(PassThroughFunctionContext.class);
final AggregateFunction function = mock(AggregateFunction.class);
given(functionContext1.getFunction()).willReturn(function);
given(function.state()).willReturn(state);
aggregator.addFunction(functionContext1);
final Edge edge = new Edge("group");
// When
aggregator.state(edge);
// Then
final ArgumentCaptor<PropertiesTuple> propertiesTupleCaptor = ArgumentCaptor.forClass(PropertiesTuple.class);
verify(functionContext1).project(propertiesTupleCaptor.capture(), Mockito.eq(state));
assertEquals(edge.getProperties(), propertiesTupleCaptor.getValue().getProperties());
}
use of uk.gov.gchq.gaffer.data.element.PropertiesTuple in project Gaffer by gchq.
the class ElementAggregatorTest method shouldSetStateOnProperties.
@Test
public void shouldSetStateOnProperties() {
// Given
final Object[] state = { "state1", "state2" };
final ElementAggregator aggregator = new ElementAggregator();
final PassThroughFunctionContext<String, AggregateFunction> functionContext1 = mock(PassThroughFunctionContext.class);
final AggregateFunction function = mock(AggregateFunction.class);
given(functionContext1.getFunction()).willReturn(function);
given(function.state()).willReturn(state);
aggregator.addFunction(functionContext1);
final Properties properties = new Properties();
// When
aggregator.state(properties);
// Then
final ArgumentCaptor<PropertiesTuple> propertiesTupleCaptor = ArgumentCaptor.forClass(PropertiesTuple.class);
verify(functionContext1).project(propertiesTupleCaptor.capture(), Mockito.eq(state));
assertSame(properties, propertiesTupleCaptor.getValue().getProperties());
}
use of uk.gov.gchq.gaffer.data.element.PropertiesTuple in project Gaffer by gchq.
the class ElementAggregatorTest method shouldWrapElementInElementTupleAndCallSuper.
@Test
public void shouldWrapElementInElementTupleAndCallSuper() {
// Given
final String reference = "reference1";
final String value = "value";
final ElementAggregator aggregator = new ElementAggregator();
final PassThroughFunctionContext<String, AggregateFunction> functionContext1 = mock(PassThroughFunctionContext.class);
final AggregateFunction function = mock(AggregateFunction.class);
given(functionContext1.getFunction()).willReturn(function);
final List<String> references = Collections.singletonList(reference);
given(functionContext1.getSelection()).willReturn(references);
aggregator.addFunction(functionContext1);
final Edge edge = new Edge("group");
edge.putProperty(reference, value);
final ArgumentCaptor<PropertiesTuple> propertiesTupleCaptor = ArgumentCaptor.forClass(PropertiesTuple.class);
given(functionContext1.select(propertiesTupleCaptor.capture())).willReturn(new String[] { value });
// When
aggregator.aggregate(edge);
// Then
assertEquals(edge.getProperties(), propertiesTupleCaptor.getValue().getProperties());
verify(functionContext1, times(2)).getFunction();
final ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class);
verify(function).aggregate(argumentCaptor.capture());
assertEquals(value, argumentCaptor.getValue()[0]);
}
Aggregations