Search in sources :

Example 21 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)

Example 22 with Store

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

the class ExamplesServiceTest method setup.

@Before
public void setup() {
    schema = new Schema.Builder().type("string", String.class).type("true", Boolean.class).entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().property("entityProperties", "string").vertex("string").build()).edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property("edgeProperties", "string").source("string").destination("string").directed("true").build()).build();
    final Store store = mock(Store.class);
    given(store.getSchema()).willReturn(schema);
    final Graph graph = new Graph.Builder().store(store).build();
    given(graphFactory.getGraph()).willReturn(graph);
}
Also used : Graph(uk.gov.gchq.gaffer.graph.Graph) Store(uk.gov.gchq.gaffer.store.Store) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) Before(org.junit.Before)

Example 23 with Store

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

the class GraphTest method shouldCallAllGraphHooksAfterOperationChainExecuted.

@Test
public void shouldCallAllGraphHooksAfterOperationChainExecuted() 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 Object result1 = mock(Object.class);
    final Object result2 = mock(Object.class);
    final Object result3 = mock(Object.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.execute(opChain, user)).willReturn(result1);
    // When
    final Object actualResult = graph.execute(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 : 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 24 with Store

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

the class GraphTest method shouldNotSetGraphViewOnOperationWhenOperationViewIsNotNull.

@Test
public void shouldNotSetGraphViewOnOperationWhenOperationViewIsNotNull() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    final View opView = mock(View.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(opView);
    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, Mockito.never()).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 25 with Store

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

the class GraphTest method shouldCallAllGraphHooksAfterOperationExecuted.

@Test
public void shouldCallAllGraphHooksAfterOperationExecuted() throws OperationException {
    // Given
    final Operation operation = mock(Operation.class);
    final OperationChain opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(Collections.singletonList(operation));
    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 Object result1 = mock(Object.class);
    final Object result2 = mock(Object.class);
    final Object result3 = mock(Object.class);
    final Schema schema = new Schema();
    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();
    final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
    given(store.execute(captor.capture(), Mockito.eq(user))).willReturn(result1);
    // When
    final Object actualResult = graph.execute(opChain, user);
    // Then
    final InOrder inOrder = inOrder(hook1, hook2);
    inOrder.verify(hook1).postExecute(result1, captor.getValue(), user);
    inOrder.verify(hook2).postExecute(result2, captor.getValue(), user);
    final List<Operation> ops = captor.getValue().getOperations();
    assertEquals(1, ops.size());
    assertSame(operation, ops.get(0));
    assertSame(actualResult, result3);
}
Also used : User(uk.gov.gchq.gaffer.user.User) InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) Operation(uk.gov.gchq.gaffer.operation.Operation) 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