Search in sources :

Example 46 with JSONSerialiser

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

the class MultiRegexTest method shouldJsonSerialiseAndDeserialise.

@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
    // Given
    Pattern[] patterns = new Pattern[2];
    patterns[0] = Pattern.compile("test");
    patterns[1] = Pattern.compile("test2");
    final MultiRegex filter = new MultiRegex(patterns);
    // When
    final String json = new String(new JSONSerialiser().serialise(filter, true));
    // Then
    JsonUtil.assertEquals(String.format("{%n" + "  \"class\" : \"uk.gov.gchq.gaffer.function.filter.MultiRegex\",%n" + "  \"value\" : [ {%n" + "    \"java.util.regex.Pattern\" : \"test\"%n" + "  }, {%n" + "    \"java.util.regex.Pattern\" : \"test2\"%n" + "  } ]%n" + "}"), json);
    // When 2
    final MultiRegex deserialisedFilter = new JSONSerialiser().deserialise(json.getBytes(), MultiRegex.class);
    // Then 2
    assertNotNull(deserialisedFilter);
    assertEquals(patterns[0].pattern(), deserialisedFilter.getPatterns()[0].pattern());
    assertEquals(patterns[1].pattern(), deserialisedFilter.getPatterns()[1].pattern());
}
Also used : Pattern(java.util.regex.Pattern) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Example 47 with JSONSerialiser

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

the class RegexTest method shouldJsonSerialiseAndDeserialise.

@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
    // Given
    final Regex filter = new Regex("test");
    // When
    final String json = new String(new JSONSerialiser().serialise(filter, true));
    // Then
    JsonUtil.assertEquals(String.format("{%n" + "  \"class\" : \"uk.gov.gchq.gaffer.function.filter.Regex\",%n" + "  \"value\" : {%n" + "    \"java.util.regex.Pattern\" : \"test\"%n" + "  }%n" + "}"), json);
    // When 2
    final Regex deserialisedFilter = new JSONSerialiser().deserialise(json.getBytes(), Regex.class);
    // Then 2
    assertEquals(filter.getControlValue().pattern(), deserialisedFilter.getControlValue().pattern());
    assertNotNull(deserialisedFilter);
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest) Test(org.junit.Test)

Example 48 with JSONSerialiser

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

the class AndTest method shouldJsonSerialiseAndDeserialise.

@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
    // Given
    final And filter = new And(Collections.singletonList(new ConsumerFunctionContext<Integer, FilterFunction>(new And(), Arrays.asList(0, 1, 2))));
    // When
    final String json = new String(new JSONSerialiser().serialise(filter, true));
    // Then
    JsonUtil.assertEquals(String.format("{%n" + "  \"class\" : \"uk.gov.gchq.gaffer.function.filter.And\",%n" + "  \"functions\" : [ {%n" + "    \"function\" : {%n" + "      \"class\" : \"uk.gov.gchq.gaffer.function.filter.And\",%n" + "      \"functions\" : [ ]%n" + "    },%n" + "    \"selection\" : [ 0, 1, 2 ]%n" + "  } ]%n" + "}"), json);
    // When 2
    final And deserialisedFilter = new JSONSerialiser().deserialise(json.getBytes(), And.class);
    // Then 2
    assertNotNull(deserialisedFilter);
}
Also used : ConsumerFunctionContext(uk.gov.gchq.gaffer.function.context.ConsumerFunctionContext) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest) Test(org.junit.Test)

Example 49 with JSONSerialiser

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

the class CollectionContainsTest method shouldJsonSerialiseAndDeserialise.

@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
    // Given
    final CollectionContains filter = new CollectionContains(VALUE1);
    // When
    final String json = new String(new JSONSerialiser().serialise(filter, true));
    // Then
    JsonUtil.assertEquals(String.format("{%n" + "  \"class\" : \"uk.gov.gchq.gaffer.function.filter.CollectionContains\",%n" + "  \"value\" : \"value1\"%n" + "}"), json);
    // When 2
    final CollectionContains deserialisedFilter = new JSONSerialiser().deserialise(json.getBytes(), CollectionContains.class);
    // Then 2
    assertNotNull(deserialisedFilter);
    assertEquals(VALUE1, deserialisedFilter.getValue());
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

Example 50 with JSONSerialiser

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

the class FreqMapIsMoreThanTest method shouldJsonSerialiseAndDeserialise.

@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
    // Given
    final MapFilter filter = new MapFilter(KEY1, new IsMoreThan(1L, true));
    // When
    final String json = new String(new JSONSerialiser().serialise(filter, true));
    // Then
    JsonUtil.assertEquals(String.format("{%n" + "  \"class\" : \"uk.gov.gchq.gaffer.function.MapFilter\",%n" + "  \"function\" : {%n" + "    \"class\" : \"uk.gov.gchq.gaffer.function.filter.IsMoreThan\",%n" + "    \"orEqualTo\" : true,%n" + "    \"value\" : {%n" + "      \"java.lang.Long\" : 1%n" + "    }%n" + "  },%n" + "  \"key\" : \"key1\"%n" + "}"), json);
    // When 2
    final MapFilter deserialisedFilter = new JSONSerialiser().deserialise(json.getBytes(), MapFilter.class);
    // Then 2
    assertNotNull(deserialisedFilter);
    assertEquals(KEY1, deserialisedFilter.getKey());
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) MapFilter(uk.gov.gchq.gaffer.function.MapFilter) Test(org.junit.Test) FilterFunctionTest(uk.gov.gchq.gaffer.function.FilterFunctionTest)

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