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);
}
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);
}
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);
}
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();
}
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);
}
Aggregations