Search in sources :

Example 16 with Element

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

the class ElementPreAggregationFilterTest method shouldAcceptElementWhenViewValidatorAcceptsElement.

@Test
public void shouldAcceptElementWhenViewValidatorAcceptsElement() throws Exception {
    // Given
    final AbstractElementFilter filter = new ElementPreAggregationFilter();
    final Map<String, String> options = new HashMap<>();
    options.put(AccumuloStoreConstants.SCHEMA, getSchemaJson());
    options.put(AccumuloStoreConstants.VIEW, getViewJson());
    options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, ByteEntityAccumuloElementConverter.class.getName());
    filter.validateOptions(options);
    final ByteEntityAccumuloElementConverter converter = new ByteEntityAccumuloElementConverter(getSchema());
    final Element element = new Edge(TestGroups.EDGE, "source", "dest", true);
    final Pair<Key> key = converter.getKeysFromElement(element);
    final Value value = converter.getValueFromElement(element);
    // When
    final boolean accept = filter.accept(key.getFirst(), value);
    // Then
    assertTrue(accept);
}
Also used : AbstractElementFilter(uk.gov.gchq.gaffer.accumulostore.key.AbstractElementFilter) HashMap(java.util.HashMap) Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 17 with Element

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

the class ValidatorFilterTest method shouldAcceptElementWhenSchemaValidatorAcceptsElement.

@Test
public void shouldAcceptElementWhenSchemaValidatorAcceptsElement() throws Exception {
    // Given
    final ValidatorFilter filter = new ValidatorFilter();
    final Map<String, String> options = new HashMap<>();
    options.put(AccumuloStoreConstants.SCHEMA, getSchemaJson());
    options.put(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS, ByteEntityAccumuloElementConverter.class.getName());
    filter.validateOptions(options);
    final ByteEntityAccumuloElementConverter converter = new ByteEntityAccumuloElementConverter(getSchema());
    final Element element = new Edge(TestGroups.EDGE, "source", "dest", true);
    final Pair<Key> key = converter.getKeysFromElement(element);
    final Value value = converter.getValueFromElement(element);
    // When
    final boolean accept = filter.accept(key.getFirst(), value);
    // Then
    assertTrue(accept);
}
Also used : HashMap(java.util.HashMap) Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) ByteEntityAccumuloElementConverter(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityAccumuloElementConverter) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 18 with Element

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

the class ByteEntityRangeElementPropertyFilterIteratorTest method shouldOnlyAcceptDeduplicatedEdges.

@Test
public void shouldOnlyAcceptDeduplicatedEdges() throws OperationException, AccumuloElementConversionException {
    // Given
    final ByteEntityRangeElementPropertyFilterIterator filter = new ByteEntityRangeElementPropertyFilterIterator();
    final Map<String, String> options = new HashMap<String, String>() {

        {
            put(AccumuloStoreConstants.OUTGOING_EDGE_ONLY, "true");
            put(AccumuloStoreConstants.DEDUPLICATE_UNDIRECTED_EDGES, "true");
        }
    };
    filter.validateOptions(options);
    // value should not be used
    final Value value = null;
    // When / Then
    for (final Element element : ELEMENTS) {
        final Pair<Key> keys = converter.getKeysFromElement(element);
        // First key is deduplicated, but only edges should be excepted
        assertEquals("Failed for element: " + element.toString(), element instanceof Edge, filter.accept(keys.getFirst(), value));
        if (null != keys.getSecond()) {
            // self elements are not added the other way round
            assertEquals("Failed for element: " + element.toString(), false, filter.accept(keys.getSecond(), value));
        }
    }
}
Also used : HashMap(java.util.HashMap) ByteEntityRangeElementPropertyFilterIterator(uk.gov.gchq.gaffer.accumulostore.key.core.impl.byteEntity.ByteEntityRangeElementPropertyFilterIterator) Element(uk.gov.gchq.gaffer.data.element.Element) Value(org.apache.accumulo.core.data.Value) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 19 with Element

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

the class OneToOneElementGeneratorTest method getElementShouldReturnGeneratedElement.

@Test
public void getElementShouldReturnGeneratedElement() {
    // Given
    final OneToOneElementGenerator<String> generator = new OneToOneElementGeneratorImpl();
    // When
    final Element result = generator.getElement(obj1);
    // Then
    assertSame(elm1, result);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) Test(org.junit.Test)

Example 20 with Element

use of uk.gov.gchq.gaffer.data.element.Element 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)

Aggregations

Element (uk.gov.gchq.gaffer.data.element.Element)182 Test (org.junit.Test)102 Edge (uk.gov.gchq.gaffer.data.element.Edge)72 User (uk.gov.gchq.gaffer.user.User)53 Entity (uk.gov.gchq.gaffer.data.element.Entity)52 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)50 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)42 ArrayList (java.util.ArrayList)33 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)32 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)26 Key (org.apache.accumulo.core.data.Key)23 Value (org.apache.accumulo.core.data.Value)23 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 HashMap (java.util.HashMap)14 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)14 Configuration (org.apache.hadoop.conf.Configuration)12 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)12