use of uk.gov.gchq.gaffer.operation.impl.get.GetAllElements 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.operation.impl.get.GetAllElements 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.operation.impl.get.GetAllElements in project Gaffer by gchq.
the class OperationServiceIT method shouldReturnChunkedGroupCounts.
@Test
public void shouldReturnChunkedGroupCounts() throws IOException {
// Given
RestApiTestUtil.addElements(DEFAULT_ELEMENTS);
// When
final Response response = RestApiTestUtil.executeOperationChainChunked(new OperationChain.Builder().first(new GetAllElements<>()).then(new CountGroups()).build());
// Then
final List<GroupCounts> results = readChunkedResults(response, new GenericType<ChunkedInput<GroupCounts>>() {
});
assertEquals(1, results.size());
final GroupCounts groupCounts = results.get(0);
verifyGroupCounts(groupCounts);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAllElements in project Gaffer by gchq.
the class CountGroupsIT method shouldCountGroupsOfElementsWhenLessElementsThanLimit.
@Test
public void shouldCountGroupsOfElementsWhenLessElementsThanLimit() throws OperationException, InterruptedException {
// Given
final User user = new User();
final Integer limit = getEntities().size() + getEdges().size() + 1;
final Entity entity = new Entity(TestGroups.ENTITY_2, VERTEX);
entity.putProperty(TestPropertyNames.INT, 100);
// When
final GroupCounts counts = graph.execute(new Builder().first(new GetAllElements<>()).then(new CountGroups(limit)).build(), user);
// Then
assertEquals(1, counts.getEntityGroups().size());
assertEquals(getEntities().size(), (int) counts.getEntityGroups().get(TestGroups.ENTITY));
assertEquals(1, counts.getEdgeGroups().size());
assertEquals(getEdges().size(), (int) counts.getEdgeGroups().get(TestGroups.EDGE));
assertFalse(counts.isLimitHit());
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetAllElements in project Gaffer by gchq.
the class CountGroupsIT method shouldCountGroupsOfElements.
@Test
public void shouldCountGroupsOfElements() throws OperationException, InterruptedException {
// Given
final User user = new User();
final Entity entity = new Entity(TestGroups.ENTITY_2, VERTEX);
entity.putProperty(TestPropertyNames.INT, 100);
// When
final GroupCounts counts = graph.execute(new Builder().first(new GetAllElements<>()).then(new CountGroups()).build(), user);
// Then
assertEquals(1, counts.getEntityGroups().size());
assertEquals(getEntities().size(), (int) counts.getEntityGroups().get(TestGroups.ENTITY));
assertEquals(1, counts.getEdgeGroups().size());
assertEquals(getEdges().size(), (int) counts.getEdgeGroups().get(TestGroups.EDGE));
assertFalse(counts.isLimitHit());
}
Aggregations