Search in sources :

Example 6 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.

the class TypeSubTypeValueSerialiserTest method shouldDeserialiseEmptyBytes.

@Override
public void shouldDeserialiseEmptyBytes() throws SerialisationException {
    // When
    final TypeSubTypeValue value = serialiser.deserialiseEmptyBytes();
    // Then
    assertEquals(new TypeSubTypeValue(), value);
}
Also used : TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue)

Example 7 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.

the class TypeSubTypeValueSerialiserTest method testCanSerialiseDeSerialiseCorrectlyTypeValueOnly.

@Test
public void testCanSerialiseDeSerialiseCorrectlyTypeValueOnly() throws SerialisationException {
    TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue();
    typeSubTypeValue.setValue("testValue");
    typeSubTypeValue.setType("testType");
    byte[] bytes = serialiser.serialise(typeSubTypeValue);
    String serialisedForm = new String(bytes);
    assertEquals("testType\0\0testValue", serialisedForm);
    TypeSubTypeValue deSerialisedTypeSubTypeValue = (TypeSubTypeValue) serialiser.deserialise(bytes);
    assertEquals(typeSubTypeValue.getType(), deSerialisedTypeSubTypeValue.getType());
    assertNull(deSerialisedTypeSubTypeValue.getSubType());
    assertEquals(typeSubTypeValue.getValue(), deSerialisedTypeSubTypeValue.getValue());
    assertEquals(typeSubTypeValue, deSerialisedTypeSubTypeValue);
}
Also used : TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) Test(org.junit.Test)

Example 8 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.

the class TypeSubTypeValueSerialiserTest method testCanSerialiseDeSerialiseCorrectly.

@Test
public void testCanSerialiseDeSerialiseCorrectly() throws SerialisationException {
    TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue("testType", "testSubType", "testValue");
    byte[] bytes = serialiser.serialise(typeSubTypeValue);
    String serialisedForm = new String(bytes);
    assertEquals("testType\0testSubType\0testValue", serialisedForm);
    TypeSubTypeValue deSerialisedTypeSubTypeValue = (TypeSubTypeValue) serialiser.deserialise(bytes);
    assertEquals(typeSubTypeValue.getType(), deSerialisedTypeSubTypeValue.getType());
    assertEquals(typeSubTypeValue.getSubType(), deSerialisedTypeSubTypeValue.getSubType());
    assertEquals(typeSubTypeValue.getValue(), deSerialisedTypeSubTypeValue.getValue());
    assertEquals(typeSubTypeValue, deSerialisedTypeSubTypeValue);
}
Also used : TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) Test(org.junit.Test)

Example 9 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.

the class TypeSubTypeValueSerialiserTest method testCanSerialiseDeSerialiseCorrectlyTypeOnly.

@Test
public void testCanSerialiseDeSerialiseCorrectlyTypeOnly() throws SerialisationException {
    TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue();
    typeSubTypeValue.setType("testType");
    byte[] bytes = serialiser.serialise(typeSubTypeValue);
    String serialisedForm = new String(bytes);
    assertEquals("testType\0\0", serialisedForm);
    TypeSubTypeValue deSerialisedTypeSubTypeValue = (TypeSubTypeValue) serialiser.deserialise(bytes);
    assertEquals(typeSubTypeValue.getType(), deSerialisedTypeSubTypeValue.getType());
    assertNull(deSerialisedTypeSubTypeValue.getSubType());
    assertNull(typeSubTypeValue.getValue(), deSerialisedTypeSubTypeValue.getValue());
    assertEquals(typeSubTypeValue, deSerialisedTypeSubTypeValue);
}
Also used : TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) Test(org.junit.Test)

Example 10 with TypeSubTypeValue

use of uk.gov.gchq.gaffer.types.TypeSubTypeValue in project Gaffer by gchq.

the class TypeSubTypeValueSerialiser method deserialise.

@Override
public TypeSubTypeValue deserialise(final byte[] bytes) throws SerialisationException {
    int lastDelimiter = 0;
    TypeSubTypeValue typeSubTypeValue = new TypeSubTypeValue();
    for (int i = 0; i < bytes.length; i++) {
        if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
            if (i > 0) {
                try {
                    typeSubTypeValue.setType(new String(ByteArrayEscapeUtils.unEscape(Arrays.copyOfRange(bytes, lastDelimiter, i)), CommonConstants.UTF_8));
                } catch (UnsupportedEncodingException e) {
                    throw new SerialisationException("Failed to deserialise the Type from TypeSubTypeValue Object", e);
                }
            }
            lastDelimiter = i + 1;
            break;
        }
    }
    for (int i = lastDelimiter; i < bytes.length; i++) {
        if (bytes[i] == ByteArrayEscapeUtils.DELIMITER) {
            if (i > lastDelimiter) {
                try {
                    typeSubTypeValue.setSubType(new String(ByteArrayEscapeUtils.unEscape(Arrays.copyOfRange(bytes, lastDelimiter, i)), CommonConstants.UTF_8));
                } catch (UnsupportedEncodingException e) {
                    throw new SerialisationException("Failed to deserialise the SubType from TypeSubTypeValue Object", e);
                }
            }
            lastDelimiter = i + 1;
            break;
        }
    }
    if (bytes.length > lastDelimiter) {
        try {
            typeSubTypeValue.setValue(new String(ByteArrayEscapeUtils.unEscape(Arrays.copyOfRange(bytes, lastDelimiter, bytes.length)), CommonConstants.UTF_8));
        } catch (UnsupportedEncodingException e) {
            throw new SerialisationException("Failed to deserialise the Value from TypeSubTypeValue Object", e);
        }
    }
    return typeSubTypeValue;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) TypeSubTypeValue(uk.gov.gchq.gaffer.types.TypeSubTypeValue) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

TypeSubTypeValue (uk.gov.gchq.gaffer.types.TypeSubTypeValue)10 Test (org.junit.Test)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1