use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldNotAddDefaultSecurityHooksIfAlreadyAdded.
@Test
public void shouldNotAddDefaultSecurityHooksIfAlreadyAdded() {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStore.class.getName());
TestStore.mockStore = mock(Store.class);
given(TestStore.mockStore.isSupported(NamedOperation.class)).willReturn(true);
// When
final GraphConfig config = new GraphConfig.Builder().graphId("test").addHook(new FunctionAuthoriser(Lists.newArrayList(Identity.class))).build();
final Graph graph = new Graph.Builder().addSchemas(StreamUtil.schemas(getClass())).storeProperties(storeProperties).config(config).build();
// Then
assertEquals(Arrays.asList(NamedOperationResolver.class, NamedViewResolver.class, FunctionAuthoriser.class), graph.getGraphHooks());
assertEquals(Identity.class, ((FunctionAuthoriser) graph.getConfig().getHooks().get(2)).getUnauthorisedFunctions().get(0));
}
use of uk.gov.gchq.gaffer.store.StoreProperties 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.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldDelegateIsSupportedToStore.
@Test
public void shouldDelegateIsSupportedToStore() {
// 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();
given(store.isSupported(GetElements.class)).willReturn(true);
given(store.isSupported(GetAllElements.class)).willReturn(false);
// When / Then
assertTrue(graph.isSupported(GetElements.class));
assertFalse(graph.isSupported(GetAllElements.class));
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldAddHooksVarArgsAndGetGraphHooks.
@Test
public void shouldAddHooksVarArgsAndGetGraphHooks() throws Exception {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
final GraphHook graphHook1 = mock(GraphHook.class);
final Log4jLogger graphHook2 = mock(Log4jLogger.class);
// When
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId("graphId").addHooks(graphHook1, graphHook2).build()).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).build();
// Then
assertEquals(Arrays.asList(NamedViewResolver.class, graphHook1.getClass(), graphHook2.getClass(), FunctionAuthoriser.class), graph.getGraphHooks());
}
use of uk.gov.gchq.gaffer.store.StoreProperties in project Gaffer by gchq.
the class GraphTest method shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig.
@Test
public void shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig() throws Exception {
// Given
final StoreProperties storeProperties = new StoreProperties();
storeProperties.setStoreClass(TestStoreImpl.class.getName());
final String graphId1 = "graphId1";
final String graphId2 = "graphId2";
final GraphLibrary library1 = mock(GraphLibrary.class);
final GraphLibrary library2 = mock(GraphLibrary.class);
final View view1 = new View.Builder().entity(TestGroups.ENTITY).build();
final View view2 = new View.Builder().edge(TestGroups.EDGE).build();
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final GraphHook hook3 = mock(GraphHook.class);
// When
final GraphConfig config = new GraphConfig.Builder().graphId(graphId2).library(library2).addHook(hook2).view(view2).build();
final Graph graph = new Graph.Builder().graphId(graphId1).library(library1).view(view1).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).addHook(hook1).config(config).addHook(hook3).build();
// Then
assertEquals(graphId2, graph.getGraphId());
assertEquals(view2, graph.getView());
assertEquals(library2, graph.getGraphLibrary());
assertEquals(Arrays.asList(NamedViewResolver.class, hook1.getClass(), hook2.getClass(), hook3.getClass(), FunctionAuthoriser.class), graph.getGraphHooks());
}
Aggregations