use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.
the class EntitySeedTest method shouldSerialiseAndDeserialiseCustomVertexObjects.
@Test
public void shouldSerialiseAndDeserialiseCustomVertexObjects() throws SerialisationException {
// Given
final CustomVertex vertex = new CustomVertex();
vertex.setType("type");
vertex.setValue("value");
final EntitySeed seed = new EntitySeed(vertex);
final JSONSerialiser serialiser = new JSONSerialiser();
// When
final byte[] bytes = serialiser.serialise(seed);
final EntitySeed seedDeserialised = serialiser.deserialise(bytes, EntitySeed.class);
// Then
assertTrue(seedDeserialised.getVertex() instanceof CustomVertex);
assertEquals("type", ((CustomVertex) seedDeserialised.getVertex()).getType());
assertEquals("value", ((CustomVertex) seedDeserialised.getVertex()).getValue());
}
use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.
the class LoadAndQueryTest method shouldReturnExpectedEntitiesViaJson.
@Test
public void shouldReturnExpectedEntitiesViaJson() throws OperationException, SerialisationException {
// Given
final User user = new User.Builder().userId("user02").dataAuth(Certificate.U.name()).dataAuth(Certificate.PG.name()).dataAuth(Certificate._12A.name()).dataAuth(Certificate._15.name()).dataAuth(Certificate._18.name()).build();
final JSONSerialiser serialiser = new JSONSerialiser();
final OperationChain<Void> populateChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, "/example/films/json/load.json"), OperationChain.class);
final OperationChain<CloseableIterable<Entity>> queryChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, "/example/films/json/query.json"), OperationChain.class);
// Setup graph
final Graph graph = new Graph.Builder().storeProperties(StreamUtil.openStream(LoadAndQuery.class, "/example/films/mockaccumulostore.properties")).addSchemas(StreamUtil.openStreams(LoadAndQuery.class, "/example/films/schema")).build();
// When
// Execute the populate operation chain on the graph
graph.execute(populateChain, user);
// Execute the query operation chain on the graph.
final CloseableIterable<Entity> results = graph.execute(queryChain, user);
// Then
verifyResults(results);
}
use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.
the class LoadAndQuery15Test method shouldReturnExpectedEdgesViaJson.
@Test
public void shouldReturnExpectedEdgesViaJson() throws OperationException, SerialisationException {
// Given
final User user = new User("user01");
final JSONSerialiser serialiser = new JSONSerialiser();
final AddElements addElements = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), AddElements.class);
final GetEdges<?> getRelatedEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetEdges.class);
// Setup graph
final Graph graph = new Graph.Builder().storeProperties(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_PREFIX + "mockaccumulostore.properties")).addSchemas(StreamUtil.openStreams(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "schema")).build();
// When
// Execute the add operation chain on the graph
graph.execute(addElements, user);
// Execute the query operation on the graph.
final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
// Then
verifyResults(results);
}
use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.
the class LoadAndQuery1Test method shouldReturnExpectedEdgesViaJson.
@Test
public void shouldReturnExpectedEdgesViaJson() throws OperationException, SerialisationException {
// Given
final User user = new User("user01");
final JSONSerialiser serialiser = new JSONSerialiser();
final AddElements addElements = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), AddElements.class);
final GetEdges<?> getRelatedEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetEdges.class);
// Setup graph
final Graph graph = new Graph.Builder().storeProperties(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_PREFIX + "mockaccumulostore.properties")).addSchemas(StreamUtil.openStreams(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "schema")).build();
// When
// Execute the add operation chain on the graph
graph.execute(addElements, user);
// Execute the query operation on the graph.
final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
// Then
verifyResults(results);
}
use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.
the class LoadAndQuery2Test method shouldReturnExpectedEdgesViaJson.
@Test
public void shouldReturnExpectedEdgesViaJson() throws OperationException, SerialisationException {
// Given
final User user = new User("user01");
final JSONSerialiser serialiser = new JSONSerialiser();
final AddElements addElements = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), AddElements.class);
final GetEdges<?> getRelatedEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetEdges.class);
// Setup graph
final Graph graph = new Graph.Builder().storeProperties(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_PREFIX + "mockaccumulostore.properties")).addSchemas(StreamUtil.openStreams(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "schema")).build();
// When
// Execute the add operation chain on the graph
graph.execute(addElements, user);
// Execute the query operation on the graph.
final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
// Then
verifyResults(results);
}
Aggregations