use of com.kixeye.chassis.transport.serde.converter.BsonJacksonMessageSerDe in project chassis by Kixeye.
the class ScalaCaseClassTest method testBsonSerDe.
@Test
public void testBsonSerDe() throws Exception {
final BsonJacksonMessageSerDe serDe = new BsonJacksonMessageSerDe();
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);
}
use of com.kixeye.chassis.transport.serde.converter.BsonJacksonMessageSerDe 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));
}
}
Aggregations