use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.
the class CountGroupsHandlerTest method shouldReturnGroupCountsUpToLimit.
@Test
public void shouldReturnGroupCountsUpToLimit() throws OperationException {
// Given
final CountGroupsHandler handler = new CountGroupsHandler();
final Store store = mock(Store.class);
final CountGroups countGroups = mock(CountGroups.class);
final CloseableIterable<Element> elements = getElements();
final Integer limit = 3;
final Context context = new Context();
given(countGroups.getLimit()).willReturn(limit);
given(countGroups.getElements()).willReturn(elements);
// When
final GroupCounts counts = handler.doOperation(countGroups, context, store);
// Then
assertTrue(counts.isLimitHit());
assertEquals(2, counts.getEntityGroups().size());
assertEquals(2, (int) counts.getEntityGroups().get(GROUP1));
assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
}
use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.
the class CountGroupsHandlerTest method shouldReturnNoCountsIfElementsAreNull.
@Test
public void shouldReturnNoCountsIfElementsAreNull() throws OperationException {
// Given
final CountGroupsHandler handler = new CountGroupsHandler();
final Store store = mock(Store.class);
final CountGroups countGroups = mock(CountGroups.class);
final Context context = new Context();
given(countGroups.getElements()).willReturn(null);
// When
final GroupCounts counts = handler.doOperation(countGroups, context, store);
// Then
assertFalse(counts.isLimitHit());
assertEquals(0, counts.getEntityGroups().size());
assertEquals(0, counts.getEdgeGroups().size());
}
use of uk.gov.gchq.gaffer.operation.impl.CountGroups 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.CountGroups 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