Search in sources :

Example 1 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class OperationServiceIT method shouldReturnGroupCounts.

@Test
public void shouldReturnGroupCounts() 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 GroupCounts groupCounts = response.readEntity(new GenericType<GroupCounts>() {
    });
    verifyGroupCounts(groupCounts);
}
Also used : Response(javax.ws.rs.core.Response) 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 2 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class CountGroupsHandlerTest method shouldReturnGroupCountsWithoutLimit.

@Test
public void shouldReturnGroupCountsWithoutLimit() 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 Context context = new Context();
    given(countGroups.getLimit()).willReturn(null);
    given(countGroups.getElements()).willReturn(elements);
    // When
    final GroupCounts counts = handler.doOperation(countGroups, context, store);
    // Then
    assertFalse(counts.isLimitHit());
    assertEquals(2, counts.getEntityGroups().size());
    assertEquals(3, (int) counts.getEntityGroups().get(GROUP1));
    assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
    assertEquals(2, counts.getEdgeGroups().size());
    assertEquals(1, (int) counts.getEdgeGroups().get(GROUP1));
    assertEquals(3, (int) counts.getEdgeGroups().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 3 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class CountGroupsHandlerTest method shouldReturnAllGroupCountsWhenLessThanLimit.

@Test
public void shouldReturnAllGroupCountsWhenLessThanLimit() 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 = 10;
    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
    assertFalse(counts.isLimitHit());
    assertEquals(2, counts.getEntityGroups().size());
    assertEquals(3, (int) counts.getEntityGroups().get(GROUP1));
    assertEquals(1, (int) counts.getEntityGroups().get(GROUP2));
    assertEquals(2, counts.getEdgeGroups().size());
    assertEquals(1, (int) counts.getEdgeGroups().get(GROUP1));
    assertEquals(3, (int) counts.getEdgeGroups().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 4 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class OperationServiceIT method shouldReturnGroupCounts.

@Test
public void shouldReturnGroupCounts() throws IOException {
    // Given
    client.addElements(DEFAULT_ELEMENTS);
    // When
    final Response response = client.executeOperationChunked(new OperationChain.Builder().first(new GetAllElements()).then(new CountGroups()).build());
    // Then
    final GroupCounts groupCounts = response.readEntity(new GenericType<GroupCounts>() {
    });
    verifyGroupCounts(groupCounts);
}
Also used : Response(javax.ws.rs.core.Response) 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.jupiter.api.Test)

Example 5 with CountGroups

use of uk.gov.gchq.gaffer.operation.impl.CountGroups in project Gaffer by gchq.

the class AddOperationsToChainTest method shouldAddAllOperationsGivenJson.

@Test
public void shouldAddAllOperationsGivenJson() throws IOException {
    // Given
    final byte[] bytes;
    try (final InputStream inputStream = StreamUtil.openStream(getClass(), ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH)) {
        bytes = IOUtils.toByteArray(inputStream);
    }
    final AddOperationsToChain hook = fromJson(bytes);
    Operation discardOutput = new DiscardOutput();
    Operation splitStore = new SplitStoreFromFile();
    Operation validate = new Validate();
    Operation getAdjacentIds = new GetAdjacentIds();
    Operation count = new Count<>();
    Operation countGroups = new CountGroups();
    Operation getElements = new GetElements();
    Operation getAllElements = new GetAllElements();
    Operation limit = new Limit<>();
    final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).build();
    // When
    hook.preExecute(opChain, new Context(new User()));
    // Then
    final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).then(count).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) User(uk.gov.gchq.gaffer.user.User) InputStream(java.io.InputStream) 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) Validate(uk.gov.gchq.gaffer.operation.impl.Validate) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) 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