Search in sources :

Example 1 with PropertiesTuple

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]);
}
Also used : PropertiesTuple(uk.gov.gchq.gaffer.data.element.PropertiesTuple) AggregateFunction(uk.gov.gchq.gaffer.function.AggregateFunction) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 2 with PropertiesTuple

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());
}
Also used : PropertiesTuple(uk.gov.gchq.gaffer.data.element.PropertiesTuple) AggregateFunction(uk.gov.gchq.gaffer.function.AggregateFunction) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 3 with PropertiesTuple

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());
}
Also used : PropertiesTuple(uk.gov.gchq.gaffer.data.element.PropertiesTuple) AggregateFunction(uk.gov.gchq.gaffer.function.AggregateFunction) Properties(uk.gov.gchq.gaffer.data.element.Properties) Test(org.junit.Test)

Example 4 with PropertiesTuple

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]);
}
Also used : PropertiesTuple(uk.gov.gchq.gaffer.data.element.PropertiesTuple) AggregateFunction(uk.gov.gchq.gaffer.function.AggregateFunction) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 PropertiesTuple (uk.gov.gchq.gaffer.data.element.PropertiesTuple)4 AggregateFunction (uk.gov.gchq.gaffer.function.AggregateFunction)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 Properties (uk.gov.gchq.gaffer.data.element.Properties)2