Search in sources :

Example 6 with Element

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

the class InputFormatTest method shouldReturnCorrectDataToMapReduceJob.

@Test
public void shouldReturnCorrectDataToMapReduceJob() throws Exception {
    final View view = new View.Builder().build();
    final Set<String> expectedResults = new HashSet<>();
    for (final Element element : DATA) {
        expectedResults.add(element.toString());
    }
    shouldReturnCorrectDataToMapReduceJob(getSchema(), KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA, view, new User(), "instance1", expectedResults);
    shouldReturnCorrectDataToMapReduceJob(getSchema(), KeyPackage.CLASSIC_KEY_PACKAGE, DATA, view, new User(), "instance2", expectedResults);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with Element

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

the class InputFormatTest method shouldReturnCorrectDataToMapReduceJobRespectingAuthorizations.

@Test
public void shouldReturnCorrectDataToMapReduceJobRespectingAuthorizations() throws Exception {
    final Schema schema = getSchemaWithVisibilities();
    final View view = new View.Builder().build();
    final Set<String> expectedResultsPublicNotPrivate = new HashSet<>();
    final Set<String> expectedResultsPrivate = new HashSet<>();
    for (final Element element : DATA_WITH_VISIBILITIES) {
        expectedResultsPrivate.add(element.toString());
        if (element.getProperty("visibility").equals("public")) {
            expectedResultsPublicNotPrivate.add(element.toString());
        }
    }
    final Set<String> privateAuth = new HashSet<>();
    privateAuth.add("public");
    privateAuth.add("private");
    final Set<String> publicNotPrivate = new HashSet<>();
    publicNotPrivate.add("public");
    final User userWithPrivate = new User("user1", privateAuth);
    final User userWithPublicNotPrivate = new User("user1", publicNotPrivate);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA_WITH_VISIBILITIES, view, userWithPublicNotPrivate, "instance5", expectedResultsPublicNotPrivate);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA_WITH_VISIBILITIES, view, userWithPrivate, "instance6", expectedResultsPrivate);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA_WITH_VISIBILITIES, view, userWithPublicNotPrivate, "instance7", expectedResultsPublicNotPrivate);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA_WITH_VISIBILITIES, view, userWithPrivate, "instance8", expectedResultsPrivate);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with Element

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

the class InputFormatTest method shouldReturnCorrectDataToMapReduceJobWithView.

@Test
public void shouldReturnCorrectDataToMapReduceJobWithView() throws Exception {
    final Schema schema = getSchema();
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    final Set<String> expectedResults = new HashSet<>();
    for (final Element element : DATA) {
        if (element.getGroup().equals(TestGroups.EDGE)) {
            expectedResults.add(element.toString());
        }
    }
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.BYTE_ENTITY_KEY_PACKAGE, DATA, view, new User(), "instance3", expectedResults);
    shouldReturnCorrectDataToMapReduceJob(schema, KeyPackage.CLASSIC_KEY_PACKAGE, DATA, view, new User(), "instance4", expectedResults);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Element

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

the class ByteEntityRangeElementPropertyFilterIteratorTest method shouldOnlyAcceptUndirectedEdges.

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

        {
            put(AccumuloStoreConstants.UNDIRECTED_EDGE_ONLY, "true");
            put(AccumuloStoreConstants.OUTGOING_EDGE_ONLY, "true");
        }
    };
    filter.validateOptions(options);
    // value should not be used
    final Value value = null;
    // When / Then
    for (final Element element : ELEMENTS) {
        final boolean expectedResult = element instanceof Edge && !((Edge) element).isDirected();
        final Pair<Key> keys = converter.getKeysFromElement(element);
        assertEquals("Failed for element: " + element.toString(), expectedResult, filter.accept(keys.getFirst(), value));
        if (null != keys.getSecond()) {
            // self elements are not added the other way round
            assertEquals("Failed for element: " + element.toString(), expectedResult, 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 10 with Element

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

the class ByteEntityRangeElementPropertyFilterIteratorTest method shouldOnlyAcceptDirectedEdges.

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

        {
            put(AccumuloStoreConstants.DIRECTED_EDGE_ONLY, "true");
        }
    };
    filter.validateOptions(options);
    // value should not be used
    final Value value = null;
    // When / Then
    for (final Element element : ELEMENTS) {
        final boolean expectedResult = element instanceof Edge && ((Edge) element).isDirected();
        final Pair<Key> keys = converter.getKeysFromElement(element);
        assertEquals("Failed for element: " + element.toString(), expectedResult, filter.accept(keys.getFirst(), value));
        if (null != keys.getSecond()) {
            // self elements are not added the other way round
            assertEquals("Failed for element: " + element.toString(), expectedResult, 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)

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