Search in sources :

Example 6 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 7 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 8 with CountGroups

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());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Example 9 with CountGroups

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());
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)9 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)9 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)5 Context (uk.gov.gchq.gaffer.store.Context)4 Store (uk.gov.gchq.gaffer.store.Store)4 CountGroupsHandler (uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler)4 Element (uk.gov.gchq.gaffer.data.element.Element)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)3 Builder (uk.gov.gchq.gaffer.operation.OperationChain.Builder)3 User (uk.gov.gchq.gaffer.user.User)3 Response (javax.ws.rs.core.Response)2 ChunkedInput (org.glassfish.jersey.client.ChunkedInput)1