Search in sources :

Example 11 with CountGroups

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);
}
Also used : Response(javax.ws.rs.core.Response) ChunkedInput(org.glassfish.jersey.client.ChunkedInput) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 12 with CountGroups

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Element(uk.gov.gchq.gaffer.data.element.Element) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 13 with CountGroups

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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) CountGroupsHandler(uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 14 with CountGroups

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));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Operation(uk.gov.gchq.gaffer.operation.Operation) Count(uk.gov.gchq.gaffer.operation.impl.Count) SplitStoreFromFile(uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 15 with CountGroups

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();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Store(uk.gov.gchq.gaffer.store.Store) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.jupiter.api.Test)

Aggregations

CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)21 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)16 Context (uk.gov.gchq.gaffer.store.Context)13 Test (org.junit.jupiter.api.Test)12 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)12 Test (org.junit.Test)9 Store (uk.gov.gchq.gaffer.store.Store)8 User (uk.gov.gchq.gaffer.user.User)8 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)6 Operation (uk.gov.gchq.gaffer.operation.Operation)5 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)5 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)5 SplitStoreFromFile (uk.gov.gchq.gaffer.operation.impl.SplitStoreFromFile)5 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)5 Response (javax.ws.rs.core.Response)4 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)4 Element (uk.gov.gchq.gaffer.data.element.Element)4 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)4 Count (uk.gov.gchq.gaffer.operation.impl.Count)4 Validate (uk.gov.gchq.gaffer.operation.impl.Validate)4