Search in sources :

Example 16 with EntityId

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

the class EntitySeedTest method shouldSerialiseAndDeserialiseIntegersAndLongs.

@Test
public void shouldSerialiseAndDeserialiseIntegersAndLongs() throws SerialisationException {
    // Given
    final Long vertex1 = 1L;
    final Integer vertex2 = 2;
    final EntityId seed1 = new EntitySeed(vertex1);
    final EntityId seed2 = new EntitySeed(vertex2);
    // When
    final byte[] bytes1 = JSONSerialiser.serialise(seed1);
    final byte[] bytes2 = JSONSerialiser.serialise(seed2);
    final EntityId seed1Deserialised = JSONSerialiser.deserialise(bytes1, EntityId.class);
    final EntityId seed2Deserialised = JSONSerialiser.deserialise(bytes2, EntityId.class);
    // Then
    assertEquals(seed1, seed1Deserialised);
    assertEquals(seed2, seed2Deserialised);
    assertTrue(seed1Deserialised.getVertex() instanceof Long);
    assertTrue(seed2Deserialised.getVertex() instanceof Integer);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 17 with EntityId

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

the class EntitySeedTest method shouldSerialiseAndDeserialiseCustomVertexObjects.

@Test
public void shouldSerialiseAndDeserialiseCustomVertexObjects() throws SerialisationException {
    // Given
    final CustomVertex vertex = new CustomVertex();
    vertex.setType("type");
    vertex.setValue("value");
    final EntityId seed = new EntitySeed(vertex);
    // When
    final byte[] bytes = JSONSerialiser.serialise(seed);
    final EntityId seedDeserialised = JSONSerialiser.deserialise(bytes, EntityId.class);
    // Then
    assertTrue(seedDeserialised.getVertex() instanceof CustomVertex);
    assertEquals("type", ((CustomVertex) seedDeserialised.getVertex()).getType());
    assertEquals("value", ((CustomVertex) seedDeserialised.getVertex()).getValue());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 18 with EntityId

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

the class EntitySeedTest method shouldNotBeRelatedToEdgeIdWhenVertexNotEqualToSourceOrDestination.

@Test
public void shouldNotBeRelatedToEdgeIdWhenVertexNotEqualToSourceOrDestination() {
    // Given
    final String source = "source";
    final String destination = "destination";
    final boolean directed = true;
    final EntityId seed = new EntitySeed("other vertex");
    final EdgeId relatedSeed = mock(EdgeId.class);
    given(relatedSeed.getSource()).willReturn(source);
    given(relatedSeed.getDestination()).willReturn(destination);
    given(relatedSeed.isDirected()).willReturn(directed);
    // Then
    assertFalse(seed.isRelated((ElementId) relatedSeed).isMatch());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 19 with EntityId

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

the class EdgeSeedTest method shouldBeRelatedToEntityIdWhenDestinationAndVertexAreNull.

@Test
public void shouldBeRelatedToEntityIdWhenDestinationAndVertexAreNull() {
    // Given
    final String source = "source";
    final String destination = null;
    final boolean directed = true;
    final EdgeId seed = new EdgeSeed(source, destination, directed);
    final EntityId relatedSeed = mock(EntityId.class);
    given(relatedSeed.getVertex()).willReturn(source);
    // When
    final boolean isRelated = seed.isRelated((ElementId) relatedSeed).isMatch();
    // Then
    assertTrue(isRelated);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 20 with EntityId

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

the class EdgeSeedTest method shouldBeRelatedToEntityIdWhenSourceEqualsVertex.

@Test
public void shouldBeRelatedToEntityIdWhenSourceEqualsVertex() {
    // Given
    final String source = "source";
    final String destination = "destination";
    final boolean directed = true;
    final EdgeId seed = new EdgeSeed(source, destination, directed);
    final EntityId relatedSeed = mock(EntityId.class);
    given(relatedSeed.getVertex()).willReturn(source);
    // When
    final boolean isRelated = seed.isRelated((ElementId) relatedSeed).isMatch();
    // Then
    assertTrue(isRelated);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Aggregations

EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)93 Test (org.junit.jupiter.api.Test)60 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)41 HashSet (java.util.HashSet)22 User (uk.gov.gchq.gaffer.user.User)21 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)15 Entity (uk.gov.gchq.gaffer.data.element.Entity)15 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)15 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)15 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 Element (uk.gov.gchq.gaffer.data.element.Element)14 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)14 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)13 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)13 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)12 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)10 ArrayList (java.util.ArrayList)8 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)7 Graph (uk.gov.gchq.gaffer.graph.Graph)7 Context (uk.gov.gchq.gaffer.store.Context)7