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());
}
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);
}
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);
}
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());
}
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());
}
Aggregations