use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testDuplicateTypeInFile2.
@Test
public void testDuplicateTypeInFile2() {
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" + "enum M1 {\n" + " VAL = 1;\n" + "}\n";
FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
fileDescriptorSource.addProtoFile("test_proto_path/file1.proto", file1);
parseAndResolve(fileDescriptorSource);
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testDefinitionNameWithDots2.
@Test
public void testDefinitionNameWithDots2() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("Definition names must not be qualified : somePackage.E1");
String file1 = "package testPackage;\n" + "enum somePackage.E1 {\n" + " VAL = 1;\n" + "}";
FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
fileDescriptorSource.addProtoFile("file1.proto", file1);
parseAndResolve(fileDescriptorSource);
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testUndefinedAnnotation.
@Test
public void testUndefinedAnnotation() {
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" + " /** @SomeAnnotation(x=777, y=\"YES\") @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
AnnotationElement.Annotation someAnnotation = descriptors.get("test.proto").getMessageTypes().get(0).getFields().get(0).getAnnotations().get("SomeAnnotation");
assertNull(someAnnotation);
AnnotationElement.Annotation fieldAnnotation = descriptors.get("test.proto").getMessageTypes().get(0).getFields().get(0).getAnnotations().get("Field");
assertNotNull(fieldAnnotation);
assertEquals("Field", fieldAnnotation.getName());
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testDuplicateEnumConstantValue.
@Test
public void testDuplicateEnumConstantValue() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("java.lang.IllegalStateException: Duplicate tag 1 in test1.E");
String file1 = "package test1;\n" + "enum E {\n" + " A = 1;\n" + " B = 1;\n" + "}";
FileDescriptorSource source = new FileDescriptorSource();
source.addProtoFile("test.proto", file1);
parseAndResolve(source);
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class SerializationContextImplTest method testTwoFilesWithErrorsSeparately.
@Test
public void testTwoFilesWithErrorsSeparately() {
SerializationContext ctx = createContext();
Map<String, Throwable> errors1 = new HashMap<>();
List<String> successful1 = new ArrayList<>();
FileDescriptorSource source1 = FileDescriptorSource.fromString("test1.proto", "kabooom1").withProgressCallback(new FileDescriptorSource.ProgressCallback() {
@Override
public void handleError(String fileName, DescriptorParserException ex) {
errors1.put(fileName, ex);
}
@Override
public void handleSuccess(String fileName) {
successful1.add(fileName);
}
});
Map<String, Throwable> errors2 = new HashMap<>();
List<String> successful2 = new ArrayList<>();
FileDescriptorSource source2 = FileDescriptorSource.fromString("test2.proto", "kabooom2").withProgressCallback(new FileDescriptorSource.ProgressCallback() {
@Override
public void handleError(String fileName, DescriptorParserException ex) {
errors2.put(fileName, ex);
}
@Override
public void handleSuccess(String fileName) {
successful2.add(fileName);
}
});
ctx.registerProtoFiles(source1);
ctx.registerProtoFiles(source2);
assertTrue(successful1.isEmpty());
assertTrue(successful2.isEmpty());
assertEquals(1, errors1.size());
assertEquals(2, errors2.size());
assertTrue(errors1.containsKey("test1.proto"));
assertTrue(errors2.containsKey("test1.proto"));
assertTrue(errors2.containsKey("test2.proto"));
assertEquals("java.lang.IllegalStateException: Syntax error in test1.proto at 1:9: unexpected label: kabooom1", errors1.get("test1.proto").getMessage());
assertEquals("java.lang.IllegalStateException: Syntax error in test1.proto at 1:9: unexpected label: kabooom1", errors2.get("test1.proto").getMessage());
assertEquals("java.lang.IllegalStateException: Syntax error in test2.proto at 1:9: unexpected label: kabooom2", errors2.get("test2.proto").getMessage());
assertTrue(ctx.getFileDescriptors().containsKey("test1.proto"));
assertTrue(ctx.getFileDescriptors().containsKey("test2.proto"));
assertFalse(ctx.getFileDescriptors().get("test1.proto").isResolved());
assertFalse(ctx.getFileDescriptors().get("test2.proto").isResolved());
}
Aggregations