Search in sources :

Example 56 with ElementId

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

the class AbstractAccumuloElementConverterTest method shouldDeserialiseEdgeId.

@Test
public void shouldDeserialiseEdgeId() {
    // Given
    final EdgeId expectedElementId = new EdgeSeed("source1", "dest1", true);
    final Edge edge = new Edge.Builder().source("source1").dest("dest1").directed(true).group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
    final Key key = converter.getKeysFromEdge(edge).getFirst();
    // When
    final ElementId elementId = converter.getElementId(key, false);
    // Then
    assertEquals(expectedElementId, elementId);
}
Also used : FreqMap(uk.gov.gchq.gaffer.types.FreqMap) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Key(org.apache.accumulo.core.data.Key) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Example 57 with ElementId

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

the class AbstractAccumuloElementConverterTest method shouldDeserialiseEntityId.

@Test
public void shouldDeserialiseEntityId() {
    // Given
    final EntityId expectedElementId = new EntitySeed("vertex1");
    final Entity entity = new Entity.Builder().vertex("vertex1").group(TestGroups.ENTITY).property(TestPropertyNames.PROP_1, new FreqMap()).property(TestPropertyNames.PROP_2, new FreqMap()).build();
    final Key key = converter.getKeyFromEntity(entity);
    // When
    final ElementId elementId = converter.getElementId(key, false);
    // Then
    assertEquals(expectedElementId, elementId);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Entity(uk.gov.gchq.gaffer.data.element.Entity) FreqMap(uk.gov.gchq.gaffer.types.FreqMap) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Key(org.apache.accumulo.core.data.Key) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Example 58 with ElementId

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

the class GetAllElementsIT method shouldGetAllElements.

protected void shouldGetAllElements(final boolean includeEntities, final boolean includeEdges, final DirectedType directedType) throws Exception {
    // Given
    final List<Element> expectedElements = new ArrayList<>();
    if (includeEntities) {
        expectedElements.addAll(getEntities().values());
    }
    if (includeEdges) {
        for (final Edge edge : getEdges().values()) {
            if (DirectedType.EITHER == directedType || (edge.isDirected() && DirectedType.DIRECTED == directedType) || (!edge.isDirected() && DirectedType.UNDIRECTED == directedType)) {
                expectedElements.add(edge);
            }
        }
    }
    final View.Builder viewBuilder = new View.Builder();
    if (includeEntities) {
        viewBuilder.entity(TestGroups.ENTITY);
    }
    if (includeEdges) {
        viewBuilder.edge(TestGroups.EDGE);
    }
    final GetAllElements op = new GetAllElements.Builder().directedType(directedType).view(viewBuilder.build()).build();
    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    final List<Element> expectedElementsCopy = Lists.newArrayList(expectedElements);
    for (final Element result : results) {
        final ElementId seed = ElementSeed.createSeed(result);
        if (result instanceof Entity) {
            Entity entity = (Entity) result;
            assertThat(expectedElements).as("Entity was not expected: " + entity).contains(entity);
        } else {
            Edge edge = (Edge) result;
            if (edge.isDirected()) {
                assertThat(expectedElements).as("Edge was not expected: " + edge).contains(edge);
            } else {
                final Edge edgeReversed = new Edge.Builder().group(TestGroups.EDGE).source(edge.getDestination()).dest(edge.getSource()).directed(edge.isDirected()).build();
                expectedElementsCopy.remove(edgeReversed);
                assertThat(expectedElements.contains(result) || expectedElements.contains(edgeReversed)).as("Edge was not expected: " + seed).isTrue();
            }
        }
        expectedElementsCopy.remove(result);
    }
    assertThat(Lists.newArrayList(results)).as("The number of elements returned was not as expected. Missing elements: " + expectedElementsCopy).hasSameSizeAs(expectedElements);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Edge(uk.gov.gchq.gaffer.data.element.Edge) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId)

Aggregations

ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)58 Test (org.junit.jupiter.api.Test)32 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)29 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)19 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)19 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)17 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 Element (uk.gov.gchq.gaffer.data.element.Element)14 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)14 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)14 HashSet (java.util.HashSet)11 Entity (uk.gov.gchq.gaffer.data.element.Entity)9 User (uk.gov.gchq.gaffer.user.User)9 ArrayList (java.util.ArrayList)7 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)7 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)7 Test (org.junit.Test)6 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)6 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)5 Key (org.apache.accumulo.core.data.Key)4