Search in sources :

Example 1 with AutoIdFields

use of net.morimekta.test.providence.testing.AutoIdFields in project providence by morimekta.

the class ProvidenceTest method testAutoIdFields.

@Test
public void testAutoIdFields() throws IOException {
    AutoIdFields af = AutoIdFields.builder().setBooleanValue(false).setByteValue((byte) 4).setShortValue((short) 6).setIntegerValue(8).setLongValue(10L).setDoubleValue(12.12).setStringValue("a string").setBinaryValue(Binary.fromHexString("0123456789abcdef")).setCompactValue(new CompactFields("name", 14, "label")).setEnumValue(Value.SIXTEENTH).build();
    BinarySerializer serializer = new BinarySerializer();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    serializer.serialize(baos, af);
    AutoIdFields af2 = serializer.deserialize(new ByteArrayInputStream(baos.toByteArray()), AutoIdFields.kDescriptor);
    assertThat(af2, is(equalToMessage(af)));
    // An interesting side effect from auto ID fields, is that the numeric
    // order is reverse that of declared order. Always.
    assertEquals("{\n" + "  compactValue = {\n" + "    name = \"name\"\n" + "    id = 14\n" + "    label = \"label\"\n" + "  }\n" + "  enumValue = SIXTEENTH\n" + "  binaryValue = b64(ASNFZ4mrze8)\n" + "  stringValue = \"a string\"\n" + "  doubleValue = 12.12\n" + "  longValue = 10\n" + "  integerValue = 8\n" + "  shortValue = 6\n" + "  byteValue = 4\n" + "  booleanValue = false\n" + "}", debugString(af2));
}
Also used : AutoIdFields(net.morimekta.test.providence.testing.AutoIdFields) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CompactFields(net.morimekta.test.providence.testing.CompactFields) BinarySerializer(net.morimekta.providence.serializer.BinarySerializer) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 BinarySerializer (net.morimekta.providence.serializer.BinarySerializer)1 AutoIdFields (net.morimekta.test.providence.testing.AutoIdFields)1 CompactFields (net.morimekta.test.providence.testing.CompactFields)1 Test (org.junit.Test)1