use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition 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.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class GraphTest method shouldConstructGraphAndCreateViewWithGroups.
@Test
public void shouldConstructGraphAndCreateViewWithGroups() {
// Given
final Store store = mock(Store.class);
given(store.getGraphId()).willReturn(GRAPH_ID);
given(store.getProperties()).willReturn(new StoreProperties());
Map<String, SchemaEdgeDefinition> edges = new HashMap<>();
edges.put("edge1", new SchemaEdgeDefinition());
edges.put("edge2", new SchemaEdgeDefinition());
edges.put("edge3", new SchemaEdgeDefinition());
edges.put("edge4", new SchemaEdgeDefinition());
Map<String, SchemaEntityDefinition> entities = new HashMap<>();
entities.put("entity1", new SchemaEntityDefinition());
entities.put("entity2", new SchemaEntityDefinition());
entities.put("entity3", new SchemaEntityDefinition());
entities.put("entity4", new SchemaEntityDefinition());
Schema schema = new Schema.Builder().edges(edges).entities(entities).build();
given(store.getSchema()).willReturn(schema);
// When
final View resultView = new Graph.Builder().store(store).build().getView();
// Then
assertNotSame(schema, resultView);
assertArrayEquals(entities.keySet().toArray(), resultView.getEntityGroups().toArray());
assertArrayEquals(edges.keySet().toArray(), resultView.getEdgeGroups().toArray());
for (final ViewElementDefinition resultElementDef : resultView.getEntities().values()) {
assertNotNull(resultElementDef);
assertEquals(0, resultElementDef.getTransientProperties().size());
assertNull(resultElementDef.getTransformer());
}
for (final ViewElementDefinition resultElementDef : resultView.getEdges().values()) {
assertNotNull(resultElementDef);
assertEquals(0, resultElementDef.getTransientProperties().size());
assertNull(resultElementDef.getTransformer());
}
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition in project Gaffer by gchq.
the class GraphTest method shouldAddSchemaGroupsIfNotIncludedInJob.
@Test
public void shouldAddSchemaGroupsIfNotIncludedInJob() throws OperationException {
// given
final Job job = new Job(null, new OperationChain.Builder().first(new GetAllElements()).build());
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition()).edge(TestGroups.EDGE, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition()).build());
given(store.getProperties()).willReturn(new StoreProperties());
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).build();
final ArgumentCaptor<Job> jobCaptor = ArgumentCaptor.forClass(Job.class);
final ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
given(store.executeJob(jobCaptor.capture(), contextCaptor.capture())).willReturn(new JobDetail());
// when
graph.executeJob(job, context);
// then
final GetAllElements operation = (GetAllElements) ((OperationChain) jobCaptor.getValue().getOperation()).getOperations().get(0);
assertEquals(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition()).edge(TestGroups.EDGE, new ViewElementDefinition()).edge(TestGroups.EDGE_2, new ViewElementDefinition()).build(), operation.getView());
}
use of uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition 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.store.schema.SchemaEdgeDefinition 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());
}
Aggregations