Search in sources :

Example 16 with FileDescriptorSource

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

the class DescriptorsTest method testDuplicateTypeInPackage2.

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

Example 17 with FileDescriptorSource

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

the class DescriptorsTest method testDuplicateTypeIdInSameFile.

@Test
public void testDuplicateTypeIdInSameFile() {
    exception.expect(DescriptorParserException.class);
    exception.expectMessage("Duplicate type id 100010 for type test1.M2. Already used by test1.M1");
    String file1 = "package test1;\n" + "/**@TypeId(100010)*/\n" + "message M1 {\n" + "   optional string a = 1;\n" + "}" + "/**@TypeId(100010)*/\n" + "message M2 {\n" + "   optional string b = 1;\n" + "}";
    FileDescriptorSource source = new FileDescriptorSource();
    source.addProtoFile("file1.proto", file1);
    parseAndResolve(source);
}
Also used : FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) Test(org.junit.Test)

Example 18 with FileDescriptorSource

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

the class DescriptorsTest method testIndirectlyImportSameFile.

@Test
public void testIndirectlyImportSameFile() {
    String file1 = "import public \"test2.proto\";\n" + "import public \"test3.proto\";" + "message M1 { optional M4 a = 1; }";
    String file2 = "import public \"test4.proto\";";
    String file3 = "import public \"test4.proto\";";
    String file4 = "message M4 { optional string a = 1; }";
    FileDescriptorSource source = new FileDescriptorSource();
    source.addProtoFile("test1.proto", file1);
    source.addProtoFile("test2.proto", file2);
    source.addProtoFile("test3.proto", file3);
    source.addProtoFile("test4.proto", file4);
    Map<String, FileDescriptor> files = parseAndResolve(source);
    FileDescriptor descriptor1 = files.get("test1.proto");
    assertThat(descriptor1.getMessageTypes()).hasSize(1);
}
Also used : FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Example 19 with FileDescriptorSource

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

the class DescriptorsTest method testBrokenUndefinedAnnotation.

@Test
public void testBrokenUndefinedAnnotation() {
    exception.expect(AnnotationParserException.class);
    exception.expectMessage("Error: 2,21: ')' expected");
    Configuration config = Configuration.builder().annotationsConfig().annotation("Field", AnnotationElement.AnnotationTarget.FIELD).attribute(AnnotationElement.Annotation.VALUE_DEFAULT_ATTRIBUTE).type(AnnotationElement.AttributeType.BOOLEAN).defaultValue(true).build();
    String testProto = "message M {\n" + "  /** Here we have an annotation that fails to parse\n" + "  @SomeAnnotation(777 @Field */\n" + "  optional int32 field1 = 1; \n" + "}";
    FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
    Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
    // todo [anistor] The processing of annotations is waaay too lazy
    descriptors.get("test.proto").getMessageTypes().get(0).getFields().get(0).getAnnotations();
}
Also used : Configuration(org.infinispan.protostream.config.Configuration) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Example 20 with FileDescriptorSource

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

the class DescriptorsTest method testDuplicateTypeInFile1.

@Test
public void testDuplicateTypeInFile1() {
    exception.expect(DescriptorParserException.class);
    exception.expectMessage("Duplicate definition of 'test.M1' in test_proto_path/file1.proto");
    String file1 = "package test;\n" + "message M1 {\n" + "  required string a = 1;\n" + "}\n" + "message M1 {\n" + "  required string a = 1;\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)

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