Search in sources :

Example 6 with Store

use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.

the class GraphTest method shouldCallAllGraphHooksAfterJobExecuted.

@Test
public void shouldCallAllGraphHooksAfterJobExecuted() throws OperationException {
    // Given
    final User user = mock(User.class);
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final Store store = mock(Store.class);
    final Schema schema = new Schema();
    final JobDetail result1 = mock(JobDetail.class);
    final JobDetail result2 = mock(JobDetail.class);
    final JobDetail result3 = mock(JobDetail.class);
    final OperationChain opChain = mock(OperationChain.class);
    given(store.getSchema()).willReturn(schema);
    given(hook1.postExecute(result1, opChain, user)).willReturn(result2);
    given(hook2.postExecute(result2, opChain, user)).willReturn(result3);
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).addHook(hook1).addHook(hook2).build();
    given(opChain.getOperations()).willReturn(Collections.singletonList(mock(Operation.class)));
    given(store.executeJob(opChain, user)).willReturn(result1);
    // When
    final JobDetail actualResult = graph.executeJob(opChain, user);
    // Then
    final InOrder inOrder = inOrder(hook1, hook2);
    inOrder.verify(hook1).postExecute(result1, opChain, user);
    inOrder.verify(hook2).postExecute(result2, opChain, user);
    assertSame(actualResult, result3);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 7 with Store

use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.

the class GraphTest method shouldSetGraphViewOnOperationAndDelegateDoOperationToStore.

@Test
public void shouldSetGraphViewOnOperationAndDelegateDoOperationToStore() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    final View view = mock(View.class);
    final Graph graph = new Graph.Builder().store(store).view(view).build();
    final User user = new User();
    final int expectedResult = 5;
    final Operation<?, Integer> operation = mock(Operation.class);
    given(operation.getView()).willReturn(null);
    final OperationChain<Integer> opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(Collections.<Operation>singletonList(operation));
    given(store.execute(opChain, user)).willReturn(expectedResult);
    // When
    int result = graph.execute(opChain, user);
    // Then
    assertEquals(expectedResult, result);
    verify(store).execute(opChain, user);
    verify(operation).setView(view);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Store(uk.gov.gchq.gaffer.store.Store) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 8 with Store

use of uk.gov.gchq.gaffer.store.Store in project Gaffer by gchq.

the class GraphTest method shouldConstructGraphAndCreateViewWithGroups.

@Test
public void shouldConstructGraphAndCreateViewWithGroups() {
    // Given
    final Store store = mock(Store.class);
    final Schema schema = mock(Schema.class);
    given(store.getSchema()).willReturn(schema);
    final Set<String> edgeGroups = new HashSet<>();
    edgeGroups.add("edge1");
    edgeGroups.add("edge2");
    edgeGroups.add("edge3");
    edgeGroups.add("edge4");
    given(schema.getEdgeGroups()).willReturn(edgeGroups);
    final Set<String> entityGroups = new HashSet<>();
    entityGroups.add("entity1");
    entityGroups.add("entity2");
    entityGroups.add("entity3");
    entityGroups.add("entity4");
    given(schema.getEntityGroups()).willReturn(entityGroups);
    // When
    final View resultView = new Graph.Builder().store(store).build().getView();
    // Then
    assertNotSame(schema, resultView);
    assertArrayEquals(entityGroups.toArray(), resultView.getEntityGroups().toArray());
    assertArrayEquals(edgeGroups.toArray(), resultView.getEdgeGroups().toArray());
    for (final ViewElementDefinition resultElementDef : resultView.getEntities().values()) {
        assertNotNull(resultElementDef);
        assertEquals(0, resultElementDef.getTransientProperties().size());
        assertNull(resultElementDef.getTransformer());
    }
    for (final ViewElementDefinition resultElementDef : resultView.getEdges().values()) {
        assertNotNull(resultElementDef);
        assertEquals(0, resultElementDef.getTransientProperties().size());
        assertNull(resultElementDef.getTransformer());
    }
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Store

use of uk.gov.gchq.gaffer.store.Store 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 10 with Store

use of uk.gov.gchq.gaffer.store.Store 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)

Aggregations

Store (uk.gov.gchq.gaffer.store.Store)37 Test (org.junit.Test)35 Context (uk.gov.gchq.gaffer.store.Context)17 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)13 User (uk.gov.gchq.gaffer.user.User)11 Element (uk.gov.gchq.gaffer.data.element.Element)10 Schema (uk.gov.gchq.gaffer.store.schema.Schema)9 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)6 GetIterableOperation (uk.gov.gchq.gaffer.operation.GetIterableOperation)5 GroupCounts (uk.gov.gchq.gaffer.data.GroupCounts)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 Graph (uk.gov.gchq.gaffer.graph.Graph)4 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)4 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)4 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)4 CountGroups (uk.gov.gchq.gaffer.operation.impl.CountGroups)4 CountGroupsHandler (uk.gov.gchq.gaffer.store.operation.handler.CountGroupsHandler)4 HashSet (java.util.HashSet)3 InOrder (org.mockito.InOrder)3 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)3