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