use of uk.gov.gchq.gaffer.operation.impl.CountGroups 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.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 AddOperationsToChainTest method shouldHandleIfOperationWithNoConditionalOrOtherwise.
@Test
public void shouldHandleIfOperationWithNoConditionalOrOtherwise() throws SerialisationException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
If ifOp = new If.Builder<>().then(new GetElements()).build();
final OperationChain opChain = new OperationChain.Builder().first(ifOp).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(new If.Builder<>().then(new OperationChain<>(new CountGroups(), new GetElements())).build()).then(new Count()).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
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, IOException {
// Given
final CountGroupsHandler handler = new CountGroupsHandler();
final Store store = mock(Store.class);
final CountGroups countGroups = mock(CountGroups.class);
final CloseableIterable elements = getElements();
final Integer limit = 3;
final Context context = new Context();
given(countGroups.getLimit()).willReturn(limit);
given(countGroups.getInput()).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));
verify(countGroups).close();
}
Aggregations