use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class GraphTest method shouldNotAddExtraGroupsFromSchemaViewWithUpdateViewHookWhenInBlacklist.
@Test
public void shouldNotAddExtraGroupsFromSchemaViewWithUpdateViewHookWhenInBlacklist() throws OperationException {
// Given
operation = new GetElements.Builder().build();
final UpdateViewHook updateViewHook = new UpdateViewHook.Builder().addExtraGroups(true).blackListElementGroups(Sets.newHashSet(TestGroups.EDGE_4, 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_4, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_5, new SchemaEdgeDefinition()).edge(TestGroups.EDGE, 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 GraphTest method shouldManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook.
@Test
public void shouldManipulateViewRemovingBlacklistedEdgeLeavingEmptyViewUsingUpdateViewHook() throws OperationException {
// Given
operation = new GetElements.Builder().view(new View.Builder().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().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 FunctionAuthoriserTest method shouldMaintainOperationChainIfItFailsToSerialise.
@Test
public void shouldMaintainOperationChainIfItFailsToSerialise() {
// Given
FunctionAuthoriser authoriser = new FunctionAuthoriser(Lists.newArrayList(Identity.class));
List fakeInput = Lists.newArrayList(new EntitySeed(1), new EntitySeed(2), new EntitySeed(3));
GetElements getElements = new GetElements();
getElements.setInput(fakeInput);
// will fail serialisation
getElements = spy(getElements);
final OperationChain chain = new OperationChain.Builder().first(getElements).then(generateOperation(ToEntityId.class)).build();
// When
authoriser.preExecute(chain, new Context());
// Then
assertEquals(fakeInput, ((Input) chain.getOperations().get(0)).getInput());
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class NamedViewResolverTest method shouldResolveNamedViewAndMergeAnotherNamedView.
@Test
public void shouldResolveNamedViewAndMergeAnotherNamedView() throws CacheOperationFailedException {
// Given
given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(FULL_NAMED_VIEW_DETAIL);
final NamedView namedViewToMerge = new NamedView.Builder().name(NAMED_VIEW_NAME + 1).edge(TestGroups.EDGE).build();
final NamedViewDetail namedViewDetailToMerge = new NamedViewDetail.Builder().name(namedViewToMerge.getName()).view(namedViewToMerge).build();
final View mergedView = new View.Builder().merge(FULL_VIEW).edge(TestGroups.EDGE).build();
given(CACHE.getNamedView(NAMED_VIEW_NAME + 1, CONTEXT.getUser())).willReturn(namedViewDetailToMerge);
final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).merge(namedViewToMerge).build()).build()).build();
// When
RESOLVER.preExecute(opChain, CONTEXT);
GetElements getElements = (GetElements) opChain.getOperations().get(0);
// Then
JsonAssert.assertEquals(mergedView.toCompactJson(), getElements.getView().toCompactJson());
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class NamedViewResolverTest method shouldResolveNamedViewWithParameter.
@Test
public void shouldResolveNamedViewWithParameter() throws CacheOperationFailedException {
Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put(EDGE_NAME_PARAM_KEY, TestGroups.EDGE_2);
ViewParameterDetail param = new ViewParameterDetail.Builder().defaultValue(TestGroups.EDGE).description("edge name param").valueClass(String.class).build();
Map<String, ViewParameterDetail> paramDetailMap = Maps.newHashMap();
paramDetailMap.put(EDGE_NAME_PARAM_KEY, param);
// Make a real View with a parameter
final View extendedView = new View.Builder().edge("${" + EDGE_NAME_PARAM_KEY + "}", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new ExampleFilterFunction()).build()).build()).build();
final NamedViewDetail extendedNamedViewDetail = new NamedViewDetail.Builder().name(NAMED_VIEW_NAME).view(extendedView).parameters(paramDetailMap).build();
given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(extendedNamedViewDetail);
final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).build()).build()).build();
// When
RESOLVER.preExecute(opChain, CONTEXT);
GetElements getElements = (GetElements) opChain.getOperations().get(0);
// Then
assertTrue(getElements.getView().getEdge(TestGroups.EDGE) != null);
assertTrue(getElements.getView().getEdge(TestGroups.EDGE_2) == null);
final OperationChain<?> opChain1 = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).parameters(paramMap).build()).build()).build();
// When
RESOLVER.preExecute(opChain1, CONTEXT);
GetElements getElements1 = (GetElements) opChain1.getOperations().get(0);
// Then
assertTrue(getElements1.getView().getEdge(TestGroups.EDGE_2) != null);
}
Aggregations