use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldAddAllOperationsWithFirstAuthsGivenPath.
@Test
public void shouldAddAllOperationsWithFirstAuthsGivenPath() throws IOException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
User user = new User.Builder().opAuths("auth1", "auth2").build();
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation getAdjacentIds = new GetAdjacentIds();
Operation getElements = new GetElements();
Operation getAllElements = new GetAllElements();
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(getElements).then(getAllElements).build();
// When
hook.preExecute(opChain, new Context(user));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(getAdjacentIds).then(getElements).then(getAllElements).then(splitStore).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldClearListWhenAddingOperations.
@Test
public void shouldClearListWhenAddingOperations() throws IOException {
// Given
final AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
hook.setBefore(null);
hook.setAfter(null);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation count = new Count<>();
Operation getElements = new GetElements();
final OperationChain opChain = new OperationChain.Builder().first(getElements).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(getElements).then(count).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldAddAllOperationsToGetWalksOperation.
@Test
public void shouldAddAllOperationsToGetWalksOperation() throws SerialisationException {
// Given
final AddOperationsToChain hook = new AddOperationsToChain();
final java.util.Map<String, List<Operation>> after = new HashMap<>();
after.put(GetElements.class.getName(), Lists.newArrayList(new Limit()));
hook.setAfter(after);
hook.setEnd(Lists.newArrayList(new Limit()));
final GetElements getElements = new GetElements();
final Limit limit = new Limit();
final OperationChain getWalksOperations = new OperationChain.Builder().first(getElements).build();
final GetWalks getWalks = new GetWalks.Builder().operations(getWalksOperations).build();
final OperationChain opChain = new OperationChain.Builder().first(getWalks).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final GetWalks expectedGetWalks = new GetWalks.Builder().operations(new OperationChain(getElements, limit)).build();
final OperationChain expectedOpChain = new OperationChain.Builder().first(expectedGetWalks).then(limit).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class AddOperationsToChainTest method shouldHandleNestedOperationChain.
@Test
public void shouldHandleNestedOperationChain() throws SerialisationException {
// Given
AddOperationsToChain hook = fromJson(ADD_OPERATIONS_TO_CHAIN_RESOURCE_PATH);
Operation discardOutput = new DiscardOutput();
Operation splitStore = new SplitStoreFromFile();
Operation validate = new Validate();
Operation getAdjacentIds = new GetAdjacentIds();
Operation count = new Count<>();
Operation countGroups = new CountGroups();
Operation getElements = new GetElements();
If ifOp = new If.Builder<>().conditional(new Conditional(new Exists(), new GetElements())).then(new GetElements()).otherwise(new GetAllElements()).build();
Operation getAllElements = new GetAllElements();
Operation limit = new Limit<>();
final OperationChain opChain = new OperationChain.Builder().first(getAdjacentIds).then(new OperationChain.Builder().first(getElements).then(getAllElements).build()).then(ifOp).build();
// When
hook.preExecute(opChain, new Context(new User()));
// Then
final OperationChain expectedOpChain = new OperationChain.Builder().first(discardOutput).then(splitStore).then(validate).then(getAdjacentIds).then(count).then(discardOutput).then((Operation) new OperationChain.Builder().first(countGroups).then(getElements).then(getAllElements).then(limit).then(validate).build()).then(new If.Builder<>().conditional(new Conditional(new Exists(), new OperationChain<>(new CountGroups(), new GetElements()))).then(new OperationChain<>(new CountGroups(), new GetElements())).otherwise(new OperationChain<>(new GetAllElements(), new Limit<>(), new Validate())).build()).then(new Count()).build();
JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.
the class GraphTest method shouldExpandGlobalEdges.
@Test
public void shouldExpandGlobalEdges() throws OperationException {
final Schema twoEdgesNoEntities = new Schema.Builder().type(TestTypes.PROP_STRING, new TypeDefinition.Builder().clazz(String.class).build()).type("vertex", new TypeDefinition.Builder().clazz(String.class).build()).edge("firstEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).edge("secondEdge", new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, TestTypes.PROP_STRING).aggregate(false).source("vertex").destination("vertex").directed(DIRECTED_EITHER).build()).build();
final Store store = mock(Store.class);
final ArgumentCaptor<OperationChain> capturedOperation = ArgumentCaptor.forClass(OperationChain.class);
final ArgumentCaptor<Context> capturedContext = ArgumentCaptor.forClass(Context.class);
given(store.getSchema()).willReturn(twoEdgesNoEntities);
given(store.getProperties()).willReturn(mock(StoreProperties.class));
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(twoEdgesNoEntities).build();
final ElementFilter filter = mock(ElementFilter.class);
final GlobalViewElementDefinition globalEdgeAggregate = new GlobalViewElementDefinition.Builder().postAggregationFilter(filter).build();
final View view = new View.Builder().globalEdges(globalEdgeAggregate).build();
operation = new GetElements.Builder().view(view).build();
opChain = new OperationChain.Builder().first(operation).build();
graph.execute(opChain, context);
Mockito.verify(store, Mockito.times(1)).execute(capturedOperation.capture(), capturedContext.capture());
assertEquals(1, capturedOperation.getAllValues().size());
final OperationChain transformedOpChain = capturedOperation.getAllValues().get(0);
assertEquals(1, transformedOpChain.getOperations().size());
assertEquals(GetElements.class, transformedOpChain.getOperations().get(0).getClass());
final View mergedView = ((GetElements) transformedOpChain.getOperations().get(0)).getView();
assertTrue(mergedView.getGlobalEdges() == null || mergedView.getGlobalEdges().size() == 0);
assertEquals(2, mergedView.getEdges().size());
for (final Map.Entry<String, ViewElementDefinition> e : mergedView.getEdges().entrySet()) {
assertNotNull(e.getValue().getPostAggregationFilter());
}
}
Aggregations