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);
}
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());
}
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());
}
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);
}
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);
}
Aggregations