Search in sources :

Example 1 with SquareProtoParser

use of org.infinispan.protostream.impl.parser.SquareProtoParser in project protostream by infinispan.

the class ProtoSchemaBuilderTest method testDocumentation.

@Test
public void testDocumentation() throws Exception {
    SerializationContext ctx = createContext();
    ProtoSchemaBuilder protoSchemaBuilder = new ProtoSchemaBuilder();
    String schemaFile = protoSchemaBuilder.fileName("test1.proto").packageName("test_package1").addClass(TestEnum.class).addClass(TestClass.class).build(ctx);
    FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test1.proto", schemaFile);
    Map<String, FileDescriptor> fileDescriptors = new SquareProtoParser(ctx.getConfiguration()).parse(fileDescriptorSource);
    FileDescriptor fd = fileDescriptors.get("test1.proto");
    assertNotNull(fd);
    Map<String, EnumDescriptor> enums = new HashMap<>();
    for (EnumDescriptor e : fd.getEnumTypes()) {
        enums.put(e.getFullName(), e);
    }
    Map<String, Descriptor> messages = new HashMap<>();
    for (Descriptor m : fd.getMessageTypes()) {
        messages.put(m.getFullName(), m);
    }
    EnumDescriptor testEnum = enums.get("test_package1.TestEnumABC");
    assertNotNull(testEnum);
    assertEquals("bla bla bla\nand some more bla\n@TypeId(100777)", testEnum.getDocumentation());
    assertEquals("This should never be read.", testEnum.getValues().get(0).getDocumentation());
    Descriptor testClass = messages.get("test_package1.TestClass");
    assertNotNull(testClass);
    assertEquals("@Indexed()\nbla bla bla\nand some more bla", testClass.getDocumentation());
    assertEquals("The surname, of course", testClass.getFields().get(0).getDocumentation());
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) ProtoSchemaBuilder(org.infinispan.protostream.annotations.ProtoSchemaBuilder) HashMap(java.util.HashMap) TestClass(org.infinispan.protostream.annotations.impl.testdomain.TestClass) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) SquareProtoParser(org.infinispan.protostream.impl.parser.SquareProtoParser) Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) Test(org.junit.Test) AbstractProtoStreamTest(org.infinispan.protostream.test.AbstractProtoStreamTest)

Aggregations

HashMap (java.util.HashMap)1 FileDescriptorSource (org.infinispan.protostream.FileDescriptorSource)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 ProtoSchemaBuilder (org.infinispan.protostream.annotations.ProtoSchemaBuilder)1 TestClass (org.infinispan.protostream.annotations.impl.testdomain.TestClass)1 Descriptor (org.infinispan.protostream.descriptors.Descriptor)1 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)1 FileDescriptor (org.infinispan.protostream.descriptors.FileDescriptor)1 SquareProtoParser (org.infinispan.protostream.impl.parser.SquareProtoParser)1 AbstractProtoStreamTest (org.infinispan.protostream.test.AbstractProtoStreamTest)1 Test (org.junit.Test)1