/** * Generates a schema from the given class. */ public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass, IdStrategy strategy) { return createFrom(typeClass, NO_EXCLUSIONS, strategy); }
/** * Generates a schema from the given class. * <p> * Method overload for backwards compatibility. */ public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass) { return createFrom(typeClass, NO_EXCLUSIONS, ID_STRATEGY); }
/** * Generates a schema from the given class. * <p> * Method overload for backwards compatibility. */ public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass) { return createFrom(typeClass, NO_EXCLUSIONS, ID_STRATEGY); }
/** * Generates a schema from the given class. */ public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass, IdStrategy strategy) { return createFrom(typeClass, NO_EXCLUSIONS, strategy); }
/** * Generates a schema from the given class with the exclusion of certain fields. */ public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass, String[] exclusions, IdStrategy strategy) { HashSet<String> set = new HashSet<String>(); for (String exclusion : exclusions) set.add(exclusion); return createFrom(typeClass, set, strategy); }
/** * Generates a schema from the given class with the exclusion of certain fields. */ public static <T> RuntimeSchema<T> createFrom(Class<T> typeClass, String[] exclusions, IdStrategy strategy) { HashSet<String> set = new HashSet<String>(); for (String exclusion : exclusions) set.add(exclusion); return createFrom(typeClass, set, strategy); }
@Test(expected = IllegalArgumentException.class) public void testTooBigTag() throws Exception { RuntimeSchema.createFrom(TooBigTag.class); }
@Test(expected = IllegalArgumentException.class) public void testZeroTag() throws Exception { RuntimeSchema.createFrom(ZeroTag.class); }
@Test(expected = IllegalArgumentException.class) public void testNegativeTag() throws Exception { RuntimeSchema.createFrom(NegativeTag.class); }
/** * {@link io.protostuff.runtime.RuntimeSchema#createFrom(Class)} should not throw * {@linkplain java.lang.OutOfMemoryError} when tag value is too big */ @Test public void testMaxTag() throws Exception { RuntimeSchema<MaxTag> schema = RuntimeSchema.createFrom(MaxTag.class); Assert.assertNotNull(schema); }
@Test public void testWriteNumericEnum() throws Exception { RuntimeSchema<A> schema = RuntimeSchema.createFrom(A.class); A a = new A(TaggedEnum.TEN); Output output = Mockito.mock(Output.class); schema.writeTo(output, a); Mockito.verify(output).writeEnum(1, 10, false); Mockito.verifyNoMoreInteractions(output); }
return RuntimeSchema.createFrom(typeClass, this);
return RuntimeSchema.createFrom(typeClass, this);
return RuntimeSchema.createFrom(typeClass, this);
return RuntimeSchema.createFrom(typeClass, this);
@Setup public void prepare() throws IOException int1RuntimeSchema = RuntimeSchema.createFrom(Int1.class); int10RuntimeSchema = RuntimeSchema.createFrom(Int10.class); sparseInt1RuntimeSchema = RuntimeSchema.createFrom(SparseInt1.class); sparseInt10RuntimeSchema = RuntimeSchema.createFrom(SparseInt10.class); generatedInt1Schema = GeneratedInt1.getSchema(); generatedInt10Schema = GeneratedInt10.getSchema();
@Test public void testEmptyFieldsPojo() { RuntimeSchema<EmptyFieldsPojo> schema = RuntimeSchema.createFrom(EmptyFieldsPojo.class, RuntimeEnv.ID_STRATEGY); Assert.assertNotNull(schema); Assert.assertEquals(0, schema.getFieldCount()); }
@Test public void testSerializeDeserializeNumericEnum() throws Exception { RuntimeSchema<A> schema = RuntimeSchema.createFrom(A.class); A source = new A(TaggedEnum.TEN); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LinkedBuffer buffer = LinkedBuffer.allocate(); ProtostuffIOUtil.writeTo(outputStream, source, schema, buffer); byte[] bytes = outputStream.toByteArray(); A newMessage = schema.newMessage(); ProtostuffIOUtil.mergeFrom(bytes, newMessage, schema); Assert.assertEquals(source, newMessage); }
/** * Simple serialization/deserialization test * * @throws Exception */ @Test public void testSerializeDeserialize() throws Exception { RuntimeSchema<A6> schema = RuntimeSchema.createFrom(A6.class); A6 source = new A6(42); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LinkedBuffer buffer = LinkedBuffer.allocate(); ProtostuffIOUtil.writeTo(outputStream, source, schema, buffer); byte[] bytes = outputStream.toByteArray(); A6 newMessage = schema.newMessage(); ProtostuffIOUtil.mergeFrom(bytes, newMessage, schema); Assert.assertEquals(source, newMessage); }
private WrapSchema createWrapSchema(WrapClassConfig config) { Class<?> cls = JavassistUtils.createClass(classLoader, config); Schema<?> schema = RuntimeSchema.createFrom(cls); return WrapSchemaFactory.createSchema(schema, config.getType()); }