Search in sources :

Example 1 with ElementTuple

use of uk.gov.gchq.gaffer.data.element.ElementTuple in project Gaffer by gchq.

the class ElementFilterTest method shouldWrapElementInElementTupleAndCallSuper.

@Test
public void shouldWrapElementInElementTupleAndCallSuper() {
    // Given
    final String reference = "reference1";
    final String value = "value";
    final ElementFilter filter = new ElementFilter();
    final ConsumerFunctionContext<String, FilterFunction> functionContext1 = mock(ConsumerFunctionContext.class);
    final FilterFunction function = mock(FilterFunction.class);
    given(functionContext1.getFunction()).willReturn(function);
    filter.addFunction(functionContext1);
    final Element element = mock(Element.class);
    given(element.getProperty(reference)).willReturn(value);
    final ArgumentCaptor<ElementTuple> elementTupleCaptor = ArgumentCaptor.forClass(ElementTuple.class);
    given(functionContext1.select(elementTupleCaptor.capture())).willReturn(new Object[] { value });
    // When
    filter.filter(element);
    // Then
    assertSame(element, elementTupleCaptor.getValue().getElement());
    verify(functionContext1).getFunction();
    final ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class);
    verify(function).isValid(argumentCaptor.capture());
    assertEquals(value, argumentCaptor.getValue()[0]);
}
Also used : FilterFunction(uk.gov.gchq.gaffer.function.FilterFunction) Element(uk.gov.gchq.gaffer.data.element.Element) ElementTuple(uk.gov.gchq.gaffer.data.element.ElementTuple) Test(org.junit.Test)

Example 2 with ElementTuple

use of uk.gov.gchq.gaffer.data.element.ElementTuple in project Gaffer by gchq.

the class ElementTransformerTest method shouldWrapElementInElementTupleAndCallSuper.

@Test
public void shouldWrapElementInElementTupleAndCallSuper() {
    // Given
    final String reference = "reference1";
    final String value = "value";
    final ElementTransformer transformer = new ElementTransformer();
    final ConsumerProducerFunctionContext<String, TransformFunction> functionContext1 = mock(ConsumerProducerFunctionContext.class);
    final TransformFunction function = mock(TransformFunction.class);
    given(functionContext1.getFunction()).willReturn(function);
    transformer.addFunction(functionContext1);
    final Element element = mock(Element.class);
    given(element.getProperty(reference)).willReturn(value);
    final ArgumentCaptor<ElementTuple> elementTupleCaptor = ArgumentCaptor.forClass(ElementTuple.class);
    given(functionContext1.select(elementTupleCaptor.capture())).willReturn(new Object[] { value });
    // When
    transformer.transform(element);
    // Then
    assertSame(element, elementTupleCaptor.getValue().getElement());
    verify(functionContext1).getFunction();
    final ArgumentCaptor<Object[]> argumentCaptor = ArgumentCaptor.forClass(Object[].class);
    verify(function).transform(argumentCaptor.capture());
    assertEquals(value, argumentCaptor.getValue()[0]);
}
Also used : TransformFunction(uk.gov.gchq.gaffer.function.TransformFunction) Element(uk.gov.gchq.gaffer.data.element.Element) ElementTuple(uk.gov.gchq.gaffer.data.element.ElementTuple) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 ElementTuple (uk.gov.gchq.gaffer.data.element.ElementTuple)2 FilterFunction (uk.gov.gchq.gaffer.function.FilterFunction)1 TransformFunction (uk.gov.gchq.gaffer.function.TransformFunction)1