use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class FederatedOperationOutputHandlerTest method shouldReturnEmptyIterableWhenNoResults.
@Test
public void shouldReturnEmptyIterableWhenNoResults() throws Exception {
// Given
final OP op = getExampleOperation();
op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, TEST_GRAPH_ID);
Schema unusedSchema = new Schema.Builder().build();
StoreProperties storeProperties = new StoreProperties();
Store mockStoreInner = Mockito.mock(Store.class);
given(mockStoreInner.getSchema()).willReturn(unusedSchema);
given(mockStoreInner.getProperties()).willReturn(storeProperties);
given(mockStoreInner.execute(any(OperationChain.class), eq(context))).willReturn(null);
FederatedStore mockStore = Mockito.mock(FederatedStore.class);
HashSet<Graph> filteredGraphs = Sets.newHashSet(getGraphWithMockStore(mockStoreInner));
Mockito.when(mockStore.getGraphs(user, TEST_GRAPH_ID, op)).thenReturn(filteredGraphs);
// When
final O results = getFederatedHandler().doOperation(op, context, mockStore);
assertEquals(0, Iterables.size((Iterable) results));
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class FederatedOperationOutputHandlerTest method shouldNotThrowException.
@Test
public void shouldNotThrowException() throws Exception {
// Given
// Given
final OP op = getExampleOperation();
op.addOption(KEY_OPERATION_OPTIONS_GRAPH_IDS, "1,3");
op.addOption(KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE, String.valueOf(true));
Schema unusedSchema = new Schema.Builder().build();
StoreProperties storeProperties = new StoreProperties();
Store mockStore1 = getMockStore(unusedSchema, storeProperties, o1);
Store mockStore2 = getMockStore(unusedSchema, storeProperties, o2);
Store mockStore3 = Mockito.mock(Store.class);
given(mockStore3.getSchema()).willReturn(unusedSchema);
given(mockStore3.getProperties()).willReturn(storeProperties);
given(mockStore3.execute(any(OperationChain.class), eq(context))).willThrow(new RuntimeException("Test Exception"));
Store mockStore4 = getMockStore(unusedSchema, storeProperties, o4);
FederatedStore mockStore = Mockito.mock(FederatedStore.class);
LinkedHashSet<Graph> filteredGraphs = Sets.newLinkedHashSet();
filteredGraphs.add(getGraphWithMockStore(mockStore1));
filteredGraphs.add(getGraphWithMockStore(mockStore3));
Mockito.when(mockStore.getGraphs(user, "1,3", op)).thenReturn(filteredGraphs);
// When
O theMergedResultsOfOperation = null;
try {
theMergedResultsOfOperation = getFederatedHandler().doOperation(op, context, mockStore);
} catch (Exception e) {
fail("Exception should not have been thrown: " + e.getMessage());
}
// Then
validateMergeResultsFromFieldObjects(theMergedResultsOfOperation, o1);
ArgumentCaptor<Context> context1Captor = ArgumentCaptor.forClass(Context.class);
verify(mockStore1).execute(any(OperationChain.class), context1Captor.capture());
assertNotEquals(context.getJobId(), context1Captor.getValue().getJobId());
assertEquals(context.getUser(), context1Captor.getValue().getUser());
verify(mockStore2, never()).execute(any(OperationChain.class), any(Context.class));
ArgumentCaptor<Context> context3Captor = ArgumentCaptor.forClass(Context.class);
verify(mockStore3).execute(any(OperationChain.class), context3Captor.capture());
assertNotEquals(context.getJobId(), context3Captor.getValue().getJobId());
assertEquals(context.getUser(), context3Captor.getValue().getUser());
verify(mockStore4, never()).execute(any(OperationChain.class), any(Context.class));
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class AddGraphWithHooksTest method builderShouldCreatePopulatedOperation.
@Test
@Override
public void builderShouldCreatePopulatedOperation() {
Schema expectedSchema = new Schema.Builder().build();
StoreProperties storeProperties = new AccumuloProperties();
Log4jLogger log4jLogger = new Log4jLogger();
AddGraphWithHooks op = new Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(storeProperties).hooks(log4jLogger).readAccessPredicate(READ_ACCESS_PREDICATE).writeAccessPredicate(WRITE_ACCESS_PREDICATE).build();
assertEquals(EXPECTED_GRAPH_ID, op.getGraphId());
assertEquals(expectedSchema, op.getSchema());
assertNotNull(op.getStoreProperties().getStorePropertiesClassName());
assertEquals(AccumuloProperties.class, op.getStoreProperties().getStorePropertiesClass());
assertThat(op.getHooks()).hasSize(1);
assertEquals(log4jLogger, op.getHooks()[0]);
assertEquals(READ_ACCESS_PREDICATE, op.getReadAccessPredicate());
assertEquals(WRITE_ACCESS_PREDICATE, op.getWriteAccessPredicate());
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldThrowExceptionWithInvalidSchema.
@Test
public void shouldThrowExceptionWithInvalidSchema() {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
// When / Then
try {
new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).addSchema(new Schema.Builder().edge("group", new SchemaEdgeDefinition()).entity("group", new SchemaEntityDefinition()).build()).storeProperties(storeProperties).build();
} catch (final SchemaException e) {
assertTrue(e.getMessage().contains("Schema is not valid"));
}
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook.
@Test
public void shouldManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook() throws OperationException {
// Given
operation = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE_5).edge(TestGroups.EDGE).build()).build();
final UpdateViewHook updateViewHook = new UpdateViewHook.Builder().blackListElementGroups(Collections.singleton(TestGroups.EDGE)).build();
given(opChain.getOperations()).willReturn(Lists.newArrayList(operation));
given(opChain.shallowClone()).willReturn(clonedOpChain);
given(clonedOpChain.getOperations()).willReturn(Lists.newArrayList(operation));
given(clonedOpChain.flatten()).willReturn(Arrays.asList(operation));
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema());
given(store.getProperties()).willReturn(new StoreProperties());
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(updateViewHook).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).build();
final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
final ArgumentCaptor<Context> contextCaptor1 = ArgumentCaptor.forClass(Context.class);
given(store.execute(captor.capture(), contextCaptor1.capture())).willReturn(new ArrayList<>());
// When / Then
graph.execute(opChain, user);
final List<Operation> ops = captor.getValue().getOperations();
JsonAssert.assertEquals(new View.Builder().edge(TestGroups.EDGE_5).build().toCompactJson(), ((GetElements) ops.get(0)).getView().toCompactJson());
}
Aggregations