Search in sources :

Example 1 with ReflectionTypeFactory

use of org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory in project protostream by infinispan.

the class ReservedProcessorTest method testEmpty.

@Test
public void testEmpty() {
    XClass classToTest = new ReflectionTypeFactory().fromClass(Integer.class);
    ReservedProcessor rp = new ReservedProcessor();
    rp.scan(classToTest);
    IndentWriter iw = new IndentWriter();
    rp.generate(iw);
    assertEquals("", iw.toString());
}
Also used : XClass(org.infinispan.protostream.annotations.impl.types.XClass) ReflectionTypeFactory(org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory) Test(org.junit.Test)

Example 2 with ReflectionTypeFactory

use of org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory in project protostream by infinispan.

the class ReservedProcessorTest method testDuplicateReservedNumber.

@Test
public void testDuplicateReservedNumber() {
    expectedException.expect(ProtoSchemaBuilderException.class);
    expectedException.expectMessage("Found duplicate @ProtoReserved number 1 in org.infinispan.protostream.annotations.impl.ReservedProcessorTest.DuplicateNumber");
    XClass classToTest = new ReflectionTypeFactory().fromClass(DuplicateNumber.class);
    new ReservedProcessor().scan(classToTest);
}
Also used : XClass(org.infinispan.protostream.annotations.impl.types.XClass) ReflectionTypeFactory(org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory) Test(org.junit.Test)

Example 3 with ReflectionTypeFactory

use of org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory in project protostream by infinispan.

the class ProtoSchemaBuilder method build.

/**
 * Builds the Protocol Buffers schema file defining the types and generates marshaller implementations for these
 * types and registers everything with the given {@link SerializationContext}.The generated classes are defined in
 * the given ClassLoader.
 *
 * @param serializationContext
 * @param classLoader          the ClassLoader in which the generated classes will be defined. If {@code null}, this
 *                             behaves as {@link #build(SerializationContext)}
 * @return the generated Protocol Buffers schema file text
 * @throws ProtoSchemaBuilderException
 * @throws IOException
 */
public String build(SerializationContext serializationContext, ClassLoader classLoader) throws ProtoSchemaBuilderException, IOException {
    ReflectionTypeFactory typeFactory = new ReflectionTypeFactory();
    Set<XClass> xclasses = classes.stream().map(typeFactory::fromClass).collect(Collectors.toCollection(LinkedHashSet::new));
    BaseProtoSchemaGenerator.generateSchemaDebugComments = generateSchemaDebugComments;
    return new RuntimeProtoSchemaGenerator(typeFactory, serializationContext, generator, fileName, packageName, xclasses, autoImportClasses, classLoader).generateAndRegister();
}
Also used : RuntimeProtoSchemaGenerator(org.infinispan.protostream.annotations.impl.RuntimeProtoSchemaGenerator) ReflectionTypeFactory(org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory) XClass(org.infinispan.protostream.annotations.impl.types.XClass)

Example 4 with ReflectionTypeFactory

use of org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory in project protostream by infinispan.

the class ReservedProcessorTest method testDuplicateReservedName.

@Test
public void testDuplicateReservedName() {
    expectedException.expect(ProtoSchemaBuilderException.class);
    expectedException.expectMessage("Found duplicate @ProtoReserved name \"triceratops\" in org.infinispan.protostream.annotations.impl.ReservedProcessorTest.DuplicateName");
    XClass classToTest = new ReflectionTypeFactory().fromClass(DuplicateName.class);
    new ReservedProcessor().scan(classToTest);
}
Also used : XClass(org.infinispan.protostream.annotations.impl.types.XClass) ReflectionTypeFactory(org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory) Test(org.junit.Test)

Example 5 with ReflectionTypeFactory

use of org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory in project protostream by infinispan.

the class ReservedProcessorTest method testReservedNumbers.

@Test
public void testReservedNumbers() {
    XClass classToTest = new ReflectionTypeFactory().fromClass(TestingReserved.class);
    ReservedProcessor rp = new ReservedProcessor();
    rp.scan(classToTest);
    IndentWriter iw = new IndentWriter();
    rp.generate(iw);
    assertEquals("//reserved 1 to 7;\n//reserved \"a\", \"b\";\n", iw.toString());
}
Also used : XClass(org.infinispan.protostream.annotations.impl.types.XClass) ReflectionTypeFactory(org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory) Test(org.junit.Test)

Aggregations

ReflectionTypeFactory (org.infinispan.protostream.annotations.impl.types.ReflectionTypeFactory)5 XClass (org.infinispan.protostream.annotations.impl.types.XClass)5 Test (org.junit.Test)4 RuntimeProtoSchemaGenerator (org.infinispan.protostream.annotations.impl.RuntimeProtoSchemaGenerator)1