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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations