Search in sources :

Example 56 with JSONSerialiser

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

the class MapFilterTest method shouldJsonSerialiseAndDeserialise.

@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
    // Given
    final MapFilter mapFilter = new MapFilter(DATE_KEY, new IsA(Map.class));
    // When
    final String json = new String(new JSONSerialiser().serialise(mapFilter, true));
    // Then
    JsonUtil.assertEquals(String.format("{\n" + "  \"class\" : \"uk.gov.gchq.gaffer.function.MapFilter\",\n" + "  \"function\" : {\n" + "    \"class\" : \"uk.gov.gchq.gaffer.function.IsA\",\n" + "    \"type\" : \"java.util.Map\"\n" + "  },\n" + "  \"key\" : {\n" + "    \"java.util.Date\" : " + DATE_KEY.getTime() + "%n" + "  }\n" + "}"), json);
    // When 2
    final MapFilter deserialisedFilter = new JSONSerialiser().deserialise(json.getBytes(), MapFilter.class);
    // Then 2
    assertNotNull(deserialisedFilter);
    assertEquals(DATE_KEY, deserialisedFilter.getKey());
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Map(java.util.Map) Test(org.junit.Test)

Example 57 with JSONSerialiser

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

the class ArrayListConcatTest method shouldJsonSerialiseAndDeserialise.

@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
    // Given
    final ArrayListConcat aggregator = new ArrayListConcat();
    // When 1
    final String json = new String(new JSONSerialiser().serialise(aggregator, true));
    // Then 1
    JsonUtil.assertEquals(String.format("{%n" + "  \"class\" : \"uk.gov.gchq.gaffer.function.aggregate.ArrayListConcat\"%n" + "}"), json);
    // When 2
    final ArrayListConcat deserialisedAggregator = new JSONSerialiser().deserialise(json.getBytes(), getFunctionClass());
    // Then 2
    assertNotNull(deserialisedAggregator);
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Test(org.junit.Test) AggregateFunctionTest(uk.gov.gchq.gaffer.function.AggregateFunctionTest)

Aggregations

JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)57 Test (org.junit.Test)56 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)6 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)2 Entity (uk.gov.gchq.gaffer.data.element.Entity)2 ConsumerFunctionContext (uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 IsA (uk.gov.gchq.gaffer.function.IsA)1 MapFilter (uk.gov.gchq.gaffer.function.MapFilter)1 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)1 GetAllEntities (uk.gov.gchq.gaffer.operation.impl.get.GetAllEntities)1