Search in sources :

Example 26 with JSONSerialiser

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

the class IsLessThanTest method shouldJsonSerialiseAndDeserialise.

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

Example 27 with JSONSerialiser

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

the class IsMoreThanTest method shouldJsonSerialiseAndDeserialise.

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

Example 28 with JSONSerialiser

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

the class IsShorterThanTest method shouldJsonSerialiseAndDeserialise.

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

Example 29 with JSONSerialiser

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

the class MinTest method shouldJsonSerialiseAndDeserialise.

@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
    // Given
    final Min aggregator = new Min();
    // 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.Min\",%n" + "  \"mode\" : \"AUTO\"%n" + "}"), json);
    // When 2
    final Min deserialisedAggregator = new JSONSerialiser().deserialise(json.getBytes(), Min.class);
    // Then 2
    assertNotNull(deserialisedAggregator);
}
Also used : JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Test(org.junit.Test) AggregateFunctionTest(uk.gov.gchq.gaffer.function.AggregateFunctionTest)

Example 30 with JSONSerialiser

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

the class StringConcatTest method shouldJsonSerialiseAndDeserialise.

@Test
public void shouldJsonSerialiseAndDeserialise() throws SerialisationException {
    // Given
    final StringConcat aggregator = new StringConcat();
    // 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.StringConcat\",%n" + "  \"separator\" : \",\"%n" + "}"), json);
    // When 2
    final StringConcat 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)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