Search in sources :

Example 1 with XmlMessageSerDe

use of com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe in project chassis by Kixeye.

the class SerDeTest method testSerDes.

@Test
public void testSerDes() throws Exception {
    for (MessageSerDe serDe : Lists.newArrayList(new BsonJacksonMessageSerDe(), new JsonJacksonMessageSerDe(), new ProtobufMessageSerDe(), new XmlMessageSerDe(), new YamlJacksonMessageSerDe())) {
        logger.info("Testing SerDe: [{}], for serialization of: [{}]", serDe.getClass().getSimpleName(), serDe.getMessageFormatName());
        TestObject testObject = TestObject.generateRandom(1, true);
        logger.info("Generated test object for serialization: [{}]", testObject);
        // serialize object
        byte[] serializedTestObject = serDe.serialize(testObject);
        dumpBytes(serializedTestObject);
        // test deserialization
        Assert.assertEquals(testObject, serDe.deserialize(serializedTestObject, 0, serializedTestObject.length, TestObject.class));
        Assert.assertEquals(testObject, serDe.deserialize(new ByteArrayInputStream(serializedTestObject), TestObject.class));
        // serialize object
        ByteArrayOutputStream serializedTestObjectStream = new ByteArrayOutputStream();
        serDe.serialize(testObject, serializedTestObjectStream);
        serializedTestObject = serializedTestObjectStream.toByteArray();
        dumpBytes(serializedTestObject);
        // test deserialization
        Assert.assertEquals(testObject, serDe.deserialize(serializedTestObject, 0, serializedTestObject.length, TestObject.class));
        Assert.assertEquals(testObject, serDe.deserialize(new ByteArrayInputStream(serializedTestObject), TestObject.class));
    }
}
Also used : XmlMessageSerDe(com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe) JsonJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe) YamlJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe) XmlMessageSerDe(com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe) BsonJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.BsonJacksonMessageSerDe) ProtobufMessageSerDe(com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe) ProtobufMessageSerDe(com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe) ByteArrayOutputStream(java.io.ByteArrayOutputStream) YamlJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe) BsonJacksonMessageSerDe(com.kixeye.chassis.transport.serde.converter.BsonJacksonMessageSerDe) Test(org.junit.Test)

Example 2 with XmlMessageSerDe

use of com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe in project chassis by Kixeye.

the class ScalaCaseClassTest method testXmlSerDe.

@Test
@Ignore("Maybe fix this?")
public void testXmlSerDe() throws Exception {
    final XmlMessageSerDe serDe = new XmlMessageSerDe();
    final TestObject obj = new TestObject(RandomStringUtils.randomAlphanumeric(64), new SomeOtherObject(RandomStringUtils.randomAlphanumeric(64)));
    final byte[] serializedObj = serDe.serialize(obj);
    dumpToLog(serDe, serializedObj);
    final TestObject deserializedObj = serDe.deserialize(serializedObj, 0, serializedObj.length, TestObject.class);
    Assert.assertEquals(obj, deserializedObj);
}
Also used : XmlMessageSerDe(com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)2 Test (org.junit.Test)2 BsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.BsonJacksonMessageSerDe)1 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)1 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)1 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Ignore (org.junit.Ignore)1