Search in sources :

Example 6 with FileDescriptorSource

use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.

the class DescriptorsTest method testEmptyPackageName.

@Test
public void testEmptyPackageName() {
    // package name cannot be empty
    exception.expect(DescriptorParserException.class);
    exception.expectMessage("Syntax error in file1.proto at 1:9: expected a word");
    String file1 = "package ;\n" + "message M1 {\n" + "  required string a = 1;\n" + "}";
    FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
    fileDescriptorSource.addProtoFile("file1.proto", file1);
    parseAndResolve(fileDescriptorSource);
}
Also used : FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) Test(org.junit.Test)

Example 7 with FileDescriptorSource

use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.

the class DescriptorsTest method testDuplicateTypeInMessage2.

@Test
public void testDuplicateTypeInMessage2() {
    exception.expect(DescriptorParserException.class);
    exception.expectMessage("Duplicate definition of 'test.M1.E1' in test_proto_path/file1.proto");
    String file1 = "package test;\n" + "message M1 {\n" + "  required string a = 1;\n" + "  enum E1 { VAL1 = 1; }\n" + "  enum E1 { VAL2 = 2; }\n" + "}\n";
    FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
    fileDescriptorSource.addProtoFile("test_proto_path/file1.proto", file1);
    parseAndResolve(fileDescriptorSource);
}
Also used : FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) Test(org.junit.Test)

Example 8 with FileDescriptorSource

use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.

the class DescriptorsTest method testDuplicateOptionInFile.

@Test
public void testDuplicateOptionInFile() {
    exception.expect(DescriptorParserException.class);
    exception.expectMessage("test_proto_path/file1.proto: Option \"custom_option\" was already set.");
    String file1 = "package test;\n" + "option custom_option = true;\n" + "option custom_option = true;\n";
    FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
    fileDescriptorSource.addProtoFile("test_proto_path/file1.proto", file1);
    parseAndResolve(fileDescriptorSource);
}
Also used : FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) Test(org.junit.Test)

Example 9 with FileDescriptorSource

use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.

the class DescriptorsTest method testDocComment.

@Test
public void testDocComment() {
    String file1 = "package test1;\n" + "/**  \n" + " *    some doc text \n" + "  *    some more doc text \n" + "      **/\n\n" + "message X {\n" + " /**\n" + "  * field doc text  \n\n" + "  */\n" + "  optional int32 field1 = 1;\n" + "}\n";
    FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
    fileDescriptorSource.addProtoFile("file1.proto", file1);
    Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource);
    assertEquals(1, descriptors.size());
    assertTrue(descriptors.containsKey("file1.proto"));
    Map<String, GenericDescriptor> types = descriptors.get("file1.proto").getTypes();
    Descriptor typeX = (Descriptor) types.get("test1.X");
    assertNotNull(typeX);
    assertEquals(1, typeX.getFields().size());
    FieldDescriptor field1 = typeX.getFields().get(0);
    assertEquals("some doc text \n   some more doc text", typeX.getDocumentation());
    assertEquals("field doc text", field1.getDocumentation());
}
Also used : GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) ExtendDescriptor(org.infinispan.protostream.descriptors.ExtendDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) Test(org.junit.Test)

Example 10 with FileDescriptorSource

use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.

the class DescriptorsTest method testArrayAnnotationAttributeNormalizing.

@Test
public void testArrayAnnotationAttributeNormalizing() {
    Configuration config = Configuration.builder().annotationsConfig().annotation("Xyz", AnnotationElement.AnnotationTarget.MESSAGE).attribute("elem1").type(AnnotationElement.AttributeType.BOOLEAN).defaultValue(true).multiple(true).build();
    String testProto = "/** @Xyz(elem1 = true) */\n" + "message M {\n" + "  optional int32 field1 = 1; \n" + "}\n";
    FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
    Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
    FileDescriptor fileDescriptor = descriptors.get("test.proto");
    List<Descriptor> messageTypes = fileDescriptor.getMessageTypes();
    Descriptor messageType = messageTypes.get(0);
    assertEquals("M", messageType.getFullName());
    AnnotationElement.Annotation annotation = messageType.getAnnotations().get("Xyz");
    assertNotNull(annotation);
    AnnotationElement.Value attr = annotation.getAttributeValue("elem1");
    assertTrue(attr instanceof AnnotationElement.Array);
    assertTrue(attr.getValue() instanceof List);
    List values = (List) attr.getValue();
    assertEquals(1, values.size());
    assertEquals(true, values.get(0));
}
Also used : Configuration(org.infinispan.protostream.config.Configuration) AnnotationElement(org.infinispan.protostream.descriptors.AnnotationElement) Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) ExtendDescriptor(org.infinispan.protostream.descriptors.ExtendDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) List(java.util.List) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Aggregations

FileDescriptorSource (org.infinispan.protostream.FileDescriptorSource)74 Test (org.junit.Test)61 FileDescriptor (org.infinispan.protostream.descriptors.FileDescriptor)24 SerializationContext (org.infinispan.protostream.SerializationContext)23 Configuration (org.infinispan.protostream.config.Configuration)13 DescriptorParserException (org.infinispan.protostream.DescriptorParserException)9 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)8 HashMap (java.util.HashMap)7 AnnotationElement (org.infinispan.protostream.descriptors.AnnotationElement)7 Descriptor (org.infinispan.protostream.descriptors.Descriptor)7 List (java.util.List)6 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ExtendDescriptor (org.infinispan.protostream.descriptors.ExtendDescriptor)5 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)5 TagReader (org.infinispan.protostream.TagReader)4 SerializationContextImpl (org.infinispan.protostream.impl.SerializationContextImpl)4 Map (java.util.Map)3 ReadContext (org.infinispan.protostream.ProtobufTagMarshaller.ReadContext)3