use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class GraphTest method shouldSetGraphViewOnOperationAndDelegateDoOperationToStore.
@Test
public void shouldSetGraphViewOnOperationAndDelegateDoOperationToStore() throws OperationException {
// Given
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema());
given(store.getProperties()).willReturn(new StoreProperties());
final View view = new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build();
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).view(view).build()).store(store).build();
final Integer expectedResult = 5;
final GetElements operation = new GetElements();
final OperationChain<Integer> opChain = mock(OperationChain.class);
final OperationChain clonedOpChain = mock(OperationChain.class);
given(opChain.shallowClone()).willReturn(clonedOpChain);
given(clonedOpChain.getOperations()).willReturn(Lists.newArrayList(operation));
given(store.execute(clonedOpChain, clonedContext)).willReturn(expectedResult);
// When
Integer result = graph.execute(opChain, context);
// Then
assertEquals(expectedResult, result);
verify(store).execute(clonedOpChain, clonedContext);
JsonAssert.assertEquals(view.toJson(false), operation.getView().toJson(false));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class GraphTest method shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook.
@Test
public void shouldFillSchemaViewAndManipulateViewRemovingBlacklistedEdgeUsingUpdateViewHook() throws OperationException {
// Given
operation = new GetElements.Builder().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.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_5, new SchemaEdgeDefinition()).build());
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());
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class NamedOperationResolverTest method shouldExecuteNamedOperationWithoutOverridingInput.
@Test
public void shouldExecuteNamedOperationWithoutOverridingInput() throws OperationException, CacheOperationFailedException {
// Given
final String opName = "opName";
final NamedOperationCache cache = mock(NamedOperationCache.class);
final NamedOperationResolver resolver = new NamedOperationResolver(cache);
final User user = mock(User.class);
final NamedOperationDetail extendedNamedOperation = mock(NamedOperationDetail.class);
final GetAdjacentIds op1 = mock(GetAdjacentIds.class);
final GetElements op2 = mock(GetElements.class);
final OperationChain namedOpChain = new OperationChain(Arrays.asList(op1, op2));
final Iterable<?> input = mock(CloseableIterable.class);
final Map<String, Object> params = null;
given(op1.getInput()).willReturn(mock(CloseableIterable.class));
given(cache.getNamedOperation(opName, user)).willReturn(extendedNamedOperation);
given(extendedNamedOperation.getOperationChain(params)).willReturn(namedOpChain);
// When
final OperationChain<Object> opChain = new OperationChain.Builder().first(new NamedOperation.Builder<>().name(opName).input(input).build()).build();
resolver.preExecute(opChain, new Context(user));
// Then
assertSame(op1, opChain.getOperations().get(0));
verify(op1, never()).setInput((Iterable) input);
assertSame(op2, opChain.getOperations().get(1));
verify(op2, never()).setInput((Iterable) input);
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class OperationAuthoriserTest method shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForNestedOperations.
@Test
public void shouldRejectOperationChainWhenUserDoesntHaveAllOpAuthsForNestedOperations() {
// Given
final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
final OperationChain opChain = new OperationChain.Builder().first(new GetElements()).then(new GenerateObjects<>()).then(new DiscardOutput()).then(new TestOperationsImpl(Collections.singletonList(new GetAllElements()))).build();
final User user = new User.Builder().opAuths("SuperUser", "ReadUser", "User").build();
// When/Then
assertThatExceptionOfType(UnauthorisedException.class).isThrownBy(() -> hook.preExecute(opChain, new Context(user))).extracting("message").isNotNull();
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class OperationAuthoriserTest method shouldAcceptOperationChainWhenUserHasAllOpAuths.
@Test
public void shouldAcceptOperationChainWhenUserHasAllOpAuths() {
// Given
final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
final OperationChain opChain = new OperationChain.Builder().first(new GetElements()).then(new GenerateObjects<>()).then(new DiscardOutput()).then(new TestOperationsImpl(Collections.singletonList(new Sort()))).build();
final User user = new User.Builder().opAuths("SuperUser", "ReadUser", "User").build();
// When
hook.preExecute(opChain, new Context(user));
// Then - no exceptions
}
Aggregations