public void testFoo() throws Exception { Schema<Foo> schema = RuntimeSchema.getSchema(Foo.class); Foo fooCompare = foo; Foo dfoo = new Foo(); byte[] deferred = toByteArray(fooCompare, schema); // ComputedSizeOutput is format compatible with protobuf // E.g collections are not serialized ... only its members/elements are. if (!RuntimeEnv.COLLECTION_SCHEMA_ON_REPEATED_FIELDS) assertTrue(deferred.length == ComputedSizeOutput.getSize( fooCompare, schema)); ProtostuffIOUtil.mergeFrom(deferred, dfoo, schema); SerializableObjects.assertEquals(fooCompare, dfoo); }
public void testBaz() throws Exception { Schema<Baz> schema = RuntimeSchema.getSchema(Baz.class); for (Baz bazCompare : new Baz[] { baz, negativeBaz }) { Baz dbaz = new Baz(); int expectedSize = ComputedSizeOutput.getSize(bazCompare, schema); byte[] deferred = toByteArray(bazCompare, schema); assertTrue(deferred.length == expectedSize); ProtostuffIOUtil.mergeFrom(deferred, dbaz, schema); SerializableObjects.assertEquals(bazCompare, dbaz); // System.err.println(dbaz.getId()); // System.err.println(dbaz.getName()); // System.err.println(dbaz.getTimestamp()); } }
public void testPojoWithArrayAndSet() throws Exception { PojoWithArrayAndSet pojoCompare = filledPojoWithArrayAndSet(); Schema<PojoWithArrayAndSet> schema = RuntimeSchema .getSchema(PojoWithArrayAndSet.class); PojoWithArrayAndSet dpojo = new PojoWithArrayAndSet(); int expectedSize = ComputedSizeOutput .getSize(pojoCompare, schema, true); byte[] deferred = toByteArray(pojoCompare, schema); assertTrue(deferred.length == expectedSize); ProtostuffIOUtil.mergeFrom(deferred, dpojo, schema); assertEquals(pojoCompare, dpojo); // System.err.println(dpojo.getSomeEnumAsSet()); // System.err.println(dpojo.getSomeFloatAsSet()); }
static void assertEquals(HasBar h1, HasBar h2) { // true if both are null if (h1 == h2) return; assertTrue(h1.getId() == h2.getId()); assertEquals(h1.getName(), h2.getName()); SerializableObjects.assertEquals(h1.getBar(), h2.getBar()); }
public void testBar() throws Exception { Schema<Bar> schema = RuntimeSchema.getSchema(Bar.class); for (Bar barCompare : new Bar[] { bar, negativeBar }) { Bar dbar = new Bar(); int expectedSize = ComputedSizeOutput.getSize(barCompare, schema); byte[] deferred = toByteArray(barCompare, schema); assertTrue(deferred.length == expectedSize); ProtostuffIOUtil.mergeFrom(deferred, dbar, schema); SerializableObjects.assertEquals(barCompare, dbar); // System.err.println(dbar.getSomeInt()); // System.err.println(dbar.getSomeLong()); // System.err.println(dbar.getSomeFloat()); // System.err.println(dbar.getSomeDouble()); // System.err.println(dbar.getSomeBytes()); // System.err.println(dbar.getSomeString()); // System.err.println(dbar.getSomeEnum()); // System.err.println(dbar.getSomeBoolean()); } }
/** * HasHasBar wraps an object without a schema. That object will have to be serialized via the default java * serialization and it will be delimited. * <p> * HasBar wraps a message {@link Bar}. */ public void testJavaSerializable() throws Exception { Schema<HasHasBar> schema = RuntimeSchema.getSchema(HasHasBar.class); HasHasBar hhbCompare = new HasHasBar("hhb", new HasBar(12345, "hb", SerializableObjects.bar)); HasHasBar dhhb = new HasHasBar(); int expectedSize = ComputedSizeOutput.getSize(hhbCompare, schema); byte[] deferred = toByteArray(hhbCompare, schema); assertTrue(deferred.length == expectedSize); ProtostuffIOUtil.mergeFrom(deferred, dhhb, schema); assertEquals(hhbCompare, dhhb); }