use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.
the class GraphConfigurationControllerTest method shouldSerialiseAndDeserialiseGetStoreTraits.
@Test
public void shouldSerialiseAndDeserialiseGetStoreTraits() throws SerialisationException {
// Given
Store store = mock(Store.class);
Schema schema = new Schema();
StoreProperties props = new StoreProperties();
Set<StoreTrait> storeTraits = Sets.newHashSet(INGEST_AGGREGATION, PRE_AGGREGATION_FILTERING, POST_AGGREGATION_FILTERING);
when(store.getSchema()).thenReturn(schema);
when(store.getProperties()).thenReturn(props);
when(store.getTraits()).thenReturn(storeTraits);
Graph graph = new Graph.Builder().config(new GraphConfig("id")).addSchema(new Schema()).store(store).build();
when(graphFactory.getGraph()).thenReturn(graph);
GraphConfigurationController controller = new GraphConfigurationController(graphFactory);
// When
byte[] bytes = JSONSerialiser.serialise(controller.getStoreTraits());
final Set<String> traits = JSONSerialiser.deserialise(bytes, Set.class);
// Then
assertEquals(Sets.newHashSet(INGEST_AGGREGATION.name(), PRE_AGGREGATION_FILTERING.name(), POST_AGGREGATION_FILTERING.name()), traits);
}
use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.
the class GraphConfigurationControllerIT method shouldReturn500WhenANonExistentClassIsProvidedForGetFilterFunctions.
@Test
public void shouldReturn500WhenANonExistentClassIsProvidedForGetFilterFunctions() {
// Given
Graph emptyGraph = new Graph.Builder().config(new GraphConfig.Builder().graphId("id").build()).storeProperties(new MapStoreProperties()).addSchema(new Schema()).build();
when(graphFactory.getGraph()).thenReturn(emptyGraph);
// When
ResponseEntity<Error> response = get("/graph/config/filterFunctions/a.random.thing", Error.class);
// Then
checkResponse(response, 500);
assertThat(response.getBody().getSimpleMessage()).isEqualTo("Could not find input class: a.random.thing");
}
use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.
the class GraphConfigurationControllerIT method shouldReturn200WhenReturningGraphId.
@Test
public void shouldReturn200WhenReturningGraphId() {
// Given
Graph emptyGraph = new Graph.Builder().config(new GraphConfig.Builder().graphId("id").description("test description").build()).storeProperties(new MapStoreProperties()).addSchema(new Schema()).build();
when(graphFactory.getGraph()).thenReturn(emptyGraph);
// When
ResponseEntity<String> response = get("/graph/config/graphId", String.class);
// Then
checkResponse(response, 200);
assertThat(response.getBody()).isEqualTo("id");
}
use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.
the class FederatedAddGraphHandlerTest method shouldAddGraphIDOnlyWithAuths.
@Test
public void shouldAddGraphIDOnlyWithAuths() throws Exception {
federatedStoreProperties.setCustomPropertyAuths("auth1,auth2");
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
Schema expectedSchema = new Schema.Builder().build();
assertEquals(0, store.getGraphs(testUser, null, ignore).size());
FederatedAddGraphHandler federatedAddGraphHandler = new FederatedAddGraphHandler();
try {
federatedAddGraphHandler.doOperation(new AddGraph.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).build(), new Context(testUser), store);
fail(EXCEPTION_EXPECTED);
} catch (OperationException e) {
assertTrue(e.getMessage().contains(String.format(FederatedAddGraphHandler.USER_IS_LIMITED_TO_ONLY_USING_PARENT_PROPERTIES_ID_FROM_GRAPHLIBRARY_BUT_FOUND_STORE_PROPERTIES_S, "")));
}
federatedAddGraphHandler.doOperation(new AddGraph.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).build(), new Context(authUser), store);
final Collection<Graph> graphs = store.getGraphs(authUser, null, ignore);
assertThat(graphs).hasSize(1);
assertEquals(0, store.getGraphs(testUser, null, ignore).size());
assertEquals(EXPECTED_GRAPH_ID, graphs.iterator().next().getGraphId());
}
use of uk.gov.gchq.gaffer.graph.Graph in project Gaffer by gchq.
the class FederatedAddGraphHandlerTest method shouldAddDisabledByDefaultGraph.
@Test
public void shouldAddDisabledByDefaultGraph() throws Exception {
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
Schema expectedSchema = new Schema.Builder().build();
assertEquals(0, store.getGraphs(testUser, null, ignore).size());
FederatedAddGraphHandler federatedAddGraphHandler = new FederatedAddGraphHandler();
federatedAddGraphHandler.doOperation(new AddGraph.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).disabledByDefault(true).build(), new Context(testUser), store);
Collection<Graph> enabledGraphs = store.getGraphs(testUser, null, ignore);
assertThat(enabledGraphs).isEmpty();
Collection<Graph> expectedGraphs = store.getGraphs(testUser, EXPECTED_GRAPH_ID, ignore);
assertThat(expectedGraphs).hasSize(1);
assertEquals(EXPECTED_GRAPH_ID, expectedGraphs.iterator().next().getGraphId());
}
Aggregations