use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GeneratorsIT method shouldConvertFromDomainObjects.
@Test
public void shouldConvertFromDomainObjects() throws OperationException, UnsupportedEncodingException {
// Given
final OperationChain<Void> opChain = new OperationChain.Builder().first(new GenerateElements.Builder<DomainObject>().generator(new BasicGenerator()).objects(Arrays.asList(new EntityDomainObject(NEW_VERTEX, "1", null), new EdgeDomainObject(NEW_SOURCE, NEW_DEST, false, 1, 1L))).build()).then(new AddElements()).build();
// When - add
graph.execute(opChain, getUser());
// Then - check they were added correctly
final List<Element> results = Lists.newArrayList(graph.execute(new GetElements.Builder<>().addSeed(new EntitySeed(NEW_VERTEX)).addSeed(new EdgeSeed(NEW_SOURCE, NEW_DEST, false)).build(), getUser()));
final Edge expectedEdge = new Edge(TestGroups.EDGE, NEW_SOURCE, NEW_DEST, false);
expectedEdge.putProperty(TestPropertyNames.INT, 1);
expectedEdge.putProperty(TestPropertyNames.COUNT, 1L);
final Entity expectedEntity = new Entity(TestGroups.ENTITY, NEW_VERTEX);
expectedEntity.putProperty(TestPropertyNames.STRING, "1");
assertNotNull(results);
assertEquals(2, results.size());
assertThat(results, IsCollectionContaining.hasItems(expectedEntity, expectedEdge));
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GeneratorsIT method shouldConvertToDomainObjects.
@Test
public void shouldConvertToDomainObjects() throws OperationException, UnsupportedEncodingException {
// Given
final OperationChain<CloseableIterable<DomainObject>> opChain = new OperationChain.Builder().first(new GetElements.Builder<>().addSeed(new EntitySeed(SOURCE_1)).build()).then(new GenerateObjects.Builder<Element, DomainObject>().generator(new BasicGenerator()).outputType(new TypeReference<CloseableIterable<DomainObject>>() {
}).build()).build();
// When
final List<DomainObject> results = Lists.newArrayList(graph.execute(opChain, getUser()));
final EntityDomainObject entityDomainObject = new EntityDomainObject(SOURCE_1, "3", null);
final EdgeDomainObject edgeDomainObject = new EdgeDomainObject(SOURCE_1, DEST_1, false, 1, 1L);
// Then
assertNotNull(results);
assertEquals(2, results.size());
assertThat(results, IsCollectionContaining.hasItems(entityDomainObject, edgeDomainObject));
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetAllElementsIT method shouldGetAllElements.
protected void shouldGetAllElements(boolean includeEntities, final IncludeEdgeType includeEdgeType) throws Exception {
// Given
final List<Element> expectedElements = new ArrayList<>();
if (includeEntities) {
expectedElements.addAll(getEntities().values());
}
for (final Edge edge : getEdges().values()) {
if (IncludeEdgeType.ALL == includeEdgeType || (edge.isDirected() && IncludeEdgeType.DIRECTED == includeEdgeType) || (!edge.isDirected() && IncludeEdgeType.UNDIRECTED == includeEdgeType)) {
expectedElements.add(edge);
}
}
final GetAllElements<Element> op = new GetAllElements.Builder<>().includeEntities(includeEntities).includeEdges(includeEdgeType).populateProperties(true).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).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 ElementSeed seed = ElementSeed.createSeed(result);
if (result instanceof Entity) {
Entity entity = (Entity) result;
assertTrue("Entity was not expected: " + entity, expectedElements.contains(entity));
} else {
Edge edge = (Edge) result;
if (edge.isDirected()) {
assertTrue("Edge was not expected: " + edge, expectedElements.contains(edge));
} else {
final Edge edgeReversed = new Edge(TestGroups.EDGE, edge.getDestination(), edge.getSource(), edge.isDirected());
expectedElementsCopy.remove(edgeReversed);
assertTrue("Edge was not expected: " + seed, expectedElements.contains(result) || expectedElements.contains(edgeReversed));
}
}
expectedElementsCopy.remove(result);
}
assertEquals("The number of elements returned was not as expected. Missing elements: " + expectedElementsCopy, expectedElements.size(), Lists.newArrayList(results).size());
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetAllElementsIT method shouldGetAllElementsFilteredOnGroup.
@TraitRequirement({ StoreTrait.PRE_AGGREGATION_FILTERING, StoreTrait.STORE_AGGREGATION })
@Test
public void shouldGetAllElementsFilteredOnGroup() throws Exception {
final GetAllElements<Element> op = new GetAllElements.Builder<>().populateProperties(true).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
// When
final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
// Then
final List<Element> resultList = Lists.newArrayList(results);
assertEquals(getEntities().size(), resultList.size());
for (final Element element : resultList) {
assertEquals(TestGroups.ENTITY, element.getGroup());
}
}
use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.
the class GetElementsIT method shouldGetElements.
private void shouldGetElements(final List<Element> expectedElements, final SeedMatchingType seedMatching, final IncludeEdgeType includeEdgeType, final Boolean includeEntities, final IncludeIncomingOutgoingType inOutType, final Iterable<ElementSeed> seeds) throws IOException, OperationException {
// Given
final User user = new User();
final GetElements<ElementSeed, Element> op = new GetElements.Builder<>().seedMatching(seedMatching).build();
op.setSeeds(seeds);
op.setIncludeEntities(includeEntities);
op.setIncludeEdges(includeEdgeType);
op.setIncludeIncomingOutGoing(inOutType);
op.setView(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build());
// When
final CloseableIterable<? extends Element> results = graph.execute(op, user);
// Then
final List<Element> expectedElementsCopy = Lists.newArrayList(expectedElements);
for (final Element result : results) {
final ElementSeed seed = ElementSeed.createSeed(result);
if (result instanceof Entity) {
Entity entity = (Entity) result;
final Collection<Element> listOfElements = new LinkedList<>();
Iterables.addAll(listOfElements, results);
assertTrue("Entity was not expected: " + entity, expectedElements.contains(entity));
} else {
Edge edge = (Edge) result;
if (edge.isDirected()) {
assertTrue("Edge was not expected: " + edge, expectedElements.contains(edge));
} else {
final Edge edgeReversed = new Edge(TestGroups.EDGE, edge.getDestination(), edge.getSource(), edge.isDirected());
Properties properties = edge.getProperties();
edgeReversed.copyProperties(properties);
expectedElementsCopy.remove(edgeReversed);
assertTrue("Edge was not expected: " + seed, expectedElements.contains(result) || expectedElements.contains(edgeReversed));
}
}
expectedElementsCopy.remove(result);
}
assertEquals("The number of elements returned was not as expected. Missing elements: " + expectedElementsCopy + ". Seeds: " + seeds, expectedElements.size(), Lists.newArrayList(results).size());
assertEquals(new HashSet<>(expectedElements), Sets.newHashSet(results));
}
Aggregations