use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testRepeatedAnnotation.
@Test
public void testRepeatedAnnotation() {
Configuration config = Configuration.builder().annotationsConfig().annotation("Field", AnnotationElement.AnnotationTarget.FIELD).repeatable("Fields").attribute(AnnotationElement.Annotation.VALUE_DEFAULT_ATTRIBUTE).type(AnnotationElement.AttributeType.BOOLEAN).defaultValue(true).build();
String testProto = "message M {\n" + " /** @Field @Field */\n" + " optional int32 field1 = 1; \n" + "}";
FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
Map<String, AnnotationElement.Annotation> annotations = descriptors.get("test.proto").getMessageTypes().get(0).getFields().get(0).getAnnotations();
assertFalse(annotations.containsKey("Field"));
assertTrue(annotations.containsKey("Fields"));
List<AnnotationElement.Annotation> innerAnnotations = (List<AnnotationElement.Annotation>) annotations.get("Fields").getDefaultAttributeValue().getValue();
assertEquals(2, innerAnnotations.size());
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testNotImportedInAnotherPackage.
@Test
public void testNotImportedInAnotherPackage() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("Failed to resolve type of field \"test2.M2.b\". Type not found : test1.M1");
String file1 = "package test1;\n" + "message M1 {\n" + " required string a = 1;\n" + "}";
String file2 = "package test2;\n" + "message M2 {\n" + " required test1.M1 b = 2;\n" + "}";
FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
fileDescriptorSource.addProtoFile("file1.proto", file1);
fileDescriptorSource.addProtoFile("file2.proto", file2);
parseAndResolve(fileDescriptorSource);
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testAnnotationParserMissingRequiredAttribute.
@Test
public void testAnnotationParserMissingRequiredAttribute() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("org.infinispan.protostream.AnnotationParserException: Attribute 'value' of annotation 'AnnotationWithRequiredAttribute' on M is required");
Configuration config = Configuration.builder().annotationsConfig().annotation("AnnotationWithRequiredAttribute", AnnotationElement.AnnotationTarget.MESSAGE).attribute(AnnotationElement.Annotation.VALUE_DEFAULT_ATTRIBUTE).type(AnnotationElement.AttributeType.BOOLEAN).build();
String testProto = "/** @AnnotationWithRequiredAttribute */\n" + "message M {\n" + " optional int32 field1 = 1; \n" + "}";
FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
parseAndResolve(fileDescriptorSource, config);
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testDuplicateEnumConstantName.
@Test
public void testDuplicateEnumConstantName() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("Enum constant 'A' is already defined in test1.E");
String file1 = "package test1;\n" + "enum E {\n" + " A = 1;\n" + " A = 2;\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 DescriptorsTest method testDuplicateUndefinedAnnotation.
@Test
public void testDuplicateUndefinedAnnotation() {
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 @SomeAnnotation @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");
// 'SomeAnnotation' annotation is not defined, but we accept it silently
assertNull(someAnnotation);
AnnotationElement.Annotation fieldAnnotation = descriptors.get("test.proto").getMessageTypes().get(0).getFields().get(0).getAnnotations().get("Field");
assertNotNull(fieldAnnotation);
assertEquals("Field", fieldAnnotation.getName());
}
Aggregations