use of uk.gov.gchq.gaffer.operation.Operation 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.Operation 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.Operation in project Gaffer by gchq.
the class GraphTest method shouldDelegateGetSupportedOperationsToStore.
@Test
public void shouldDelegateGetSupportedOperationsToStore() {
// Given
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).build()).store(store).build();
final Set<Class<? extends Operation>> expectedSupportedOperations = mock(Set.class);
given(store.getSupportedOperations()).willReturn(expectedSupportedOperations);
// When
final Set<Class<? extends Operation>> supportedOperations = graph.getSupportedOperations();
// Then
assertSame(expectedSupportedOperations, supportedOperations);
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class GraphRequestTest method graphRequestEqualsCoverage.
@Test
public void graphRequestEqualsCoverage() {
// Given
final GetAllElements operation = new GetAllElements();
final Context context = new Context();
// When
final GraphRequest<Operation> request = new GraphRequest<Operation>(operation, context);
final GraphRequest<Operation> expected = new GraphRequest<Operation>(operation, context);
// Then
assertEquals(expected, request);
}
use of uk.gov.gchq.gaffer.operation.Operation in project Gaffer by gchq.
the class ViewMigration method createMigrationOps.
public static List<Operation> createMigrationOps(final boolean aggregateAfter, final Iterable<ViewMigration> views) {
final ViewMigration viewMig = new ViewMigration(aggregateAfter);
for (final ViewMigration view : views) {
viewMig.edgesPostAggregationFilter.putAll(view.edgesPostAggregationFilter);
viewMig.entitiesPostAggregationFilter.putAll(view.entitiesPostAggregationFilter);
viewMig.edgesPostTransformFilter.putAll(view.edgesPostTransformFilter);
viewMig.entitiesPostTransformFilter.putAll(view.entitiesPostTransformFilter);
viewMig.edgesTransformer.putAll(view.edgesTransformer);
viewMig.entitiesTransformer.putAll(view.entitiesTransformer);
}
final List<Operation> updatedOps = new ArrayList<>();
if (aggregateAfter) {
final Aggregate aggregate = new Aggregate();
updatedOps.add(aggregate);
if (!viewMig.entitiesPostAggregationFilter.isEmpty() || !viewMig.edgesPostAggregationFilter.isEmpty()) {
final Filter postAggregationFilter = new Filter.Builder().entities(viewMig.entitiesPostAggregationFilter).edges(viewMig.edgesPostAggregationFilter).build();
updatedOps.add(postAggregationFilter);
}
if (!viewMig.entitiesTransformer.isEmpty() || !viewMig.edgesTransformer.isEmpty()) {
final Transform transformFunction = new Transform.Builder().entities(viewMig.entitiesTransformer).edges(viewMig.edgesTransformer).build();
updatedOps.add(transformFunction);
}
if (!viewMig.edgesPostTransformFilter.isEmpty() || !viewMig.entitiesPostTransformFilter.isEmpty()) {
final Filter postTransformFilter = new Filter.Builder().entities(viewMig.entitiesPostTransformFilter).edges(viewMig.edgesPostTransformFilter).build();
updatedOps.add(postTransformFilter);
}
}
return updatedOps;
}
Aggregations