Search in sources :

Example 36 with JSONSerialiser

use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.

the class LoadAndQuery3Test 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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 37 with JSONSerialiser

use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.

the class LoadAndQuery4Test 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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 38 with JSONSerialiser

use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.

the class EdgeSeedTest method shouldSerialiseAndDeserialiseCustomVertexObjects.

@Test
public void shouldSerialiseAndDeserialiseCustomVertexObjects() throws SerialisationException {
    // Given
    final CustomVertex source = new CustomVertex();
    source.setType("sourceType");
    source.setValue("sourceValue");
    final CustomVertex destination = new CustomVertex();
    destination.setType("destinationType");
    destination.setValue("destinationValue");
    final boolean directed = true;
    final EdgeSeed seed = new EdgeSeed(source, destination, directed);
    final JSONSerialiser serialiser = new JSONSerialiser();
    // When
    final byte[] bytes = serialiser.serialise(seed);
    final EdgeSeed seedDeserialised = serialiser.deserialise(bytes, EdgeSeed.class);
    // Then
    assertTrue(seedDeserialised.getSource() instanceof CustomVertex);
    assertTrue(seedDeserialised.getDestination() instanceof CustomVertex);
    assertEquals("sourceType", ((CustomVertex) seedDeserialised.getSource()).getType());
    assertEquals("sourceValue", ((CustomVertex) seedDeserialised.getSource()).getValue());
    assertEquals("destinationType", ((CustomVertex) seedDeserialised.getDestination()).getType());
    assertEquals("destinationValue", ((CustomVertex) seedDeserialised.getDestination()).getValue());
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Test(org.junit.Test)

Example 39 with JSONSerialiser

use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.

the class EdgeSeedTest method shouldSerialiseAndDeserialiseIntegersAndLongs.

@Test
public void shouldSerialiseAndDeserialiseIntegersAndLongs() throws SerialisationException {
    // Given
    final Long source = 1L;
    final Integer destination = 2;
    final boolean directed = true;
    final EdgeSeed seed = new EdgeSeed(source, destination, directed);
    final JSONSerialiser serialiser = new JSONSerialiser();
    // When
    final byte[] bytes = serialiser.serialise(seed);
    final EdgeSeed seedDeserialised = serialiser.deserialise(bytes, EdgeSeed.class);
    // Then
    assertEquals(seed, seedDeserialised);
    assertTrue(seedDeserialised.getSource() instanceof Long);
    assertTrue(seedDeserialised.getDestination() instanceof Integer);
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Test(org.junit.Test)

Example 40 with JSONSerialiser

use of uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser in project Gaffer by gchq.

the class EntitySeedTest method shouldSerialiseAndDeserialiseIntegersAndLongs.

@Test
public void shouldSerialiseAndDeserialiseIntegersAndLongs() throws SerialisationException {
    // Given
    final Long vertex1 = 1L;
    final Integer vertex2 = 2;
    final EntitySeed seed1 = new EntitySeed(vertex1);
    final EntitySeed seed2 = new EntitySeed(vertex2);
    final JSONSerialiser serialiser = new JSONSerialiser();
    // When
    final byte[] bytes1 = serialiser.serialise(seed1);
    final byte[] bytes2 = serialiser.serialise(seed2);
    final EntitySeed seed1Deserialised = serialiser.deserialise(bytes1, EntitySeed.class);
    final EntitySeed seed2Deserialised = serialiser.deserialise(bytes2, EntitySeed.class);
    // Then
    assertEquals(seed1, seed1Deserialised);
    assertEquals(seed2, seed2Deserialised);
    assertTrue(seed1Deserialised.getVertex() instanceof Long);
    assertTrue(seed2Deserialised.getVertex() instanceof Integer);
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Test(org.junit.Test)

Aggregations

JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)68 Test (org.junit.Test)67 FilterFunctionTest (uk.gov.gchq.gaffer.function.FilterFunctionTest)23 AggregateFunctionTest (uk.gov.gchq.gaffer.function.AggregateFunctionTest)19 Graph (uk.gov.gchq.gaffer.graph.Graph)11 User (uk.gov.gchq.gaffer.user.User)11 Edge (uk.gov.gchq.gaffer.data.element.Edge)8 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)7 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)4 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)4 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)4 Context (uk.gov.gchq.gaffer.store.Context)4 Store (uk.gov.gchq.gaffer.store.Store)4 Date (java.util.Date)2 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)2 Entity (uk.gov.gchq.gaffer.data.element.Entity)2 ConsumerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)2 GetGafferResultCacheExport (uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport)2