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