use of org.infinispan.protostream.config.Configuration in project protostream by infinispan.
the class DescriptorsTest method testAnnotationTarget.
@Test
public void testAnnotationTarget() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("Annotation '@Field()' cannot be applied to message types.");
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 = "/** @Field */\n" + "message M {\n" + " optional int32 field1 = 1; \n" + "}";
FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
parseAndResolve(fileDescriptorSource, config);
}
use of org.infinispan.protostream.config.Configuration in project protostream by infinispan.
the class DescriptorsTest method testDuplicateAnnotation.
@Test
public void testDuplicateAnnotation() {
exception.expect(AnnotationParserException.class);
exception.expectMessage("Error: 1,8: duplicate annotation definition \"Field\"");
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" + " /** @Field @Field */\n" + " optional int32 field1 = 1; \n" + "}";
FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
// todo [anistor] this is waaay too lazy
descriptors.get("test.proto").getMessageTypes().get(0).getFields().get(0).getAnnotations();
}
use of org.infinispan.protostream.config.Configuration in project protostream by infinispan.
the class DescriptorsTest method testDocAnnotations.
@Test
public void testDocAnnotations() {
String file1 = "package test1;\n" + "/** \n" + " * @Foo(fooValue) \n" + " * some more doc text \n" + " **/\n\n" + "message X {\n" + " /**\n" + " * @Bar(barValue) \n\n" + " */\n" + " optional int32 field1 = 1;\n" + "}\n";
Configuration config = Configuration.builder().annotationsConfig().annotation("Foo", AnnotationElement.AnnotationTarget.MESSAGE).attribute(AnnotationElement.Annotation.VALUE_DEFAULT_ATTRIBUTE).type(AnnotationElement.AttributeType.IDENTIFIER).metadataCreator((descriptor, annotation) -> annotation.getDefaultAttributeValue().getValue()).annotation("Bar", AnnotationElement.AnnotationTarget.FIELD).attribute(AnnotationElement.Annotation.VALUE_DEFAULT_ATTRIBUTE).type(AnnotationElement.AttributeType.IDENTIFIER).metadataCreator((fieldDescriptor, annotation) -> annotation.getDefaultAttributeValue().getValue()).build();
FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
fileDescriptorSource.addProtoFile("file1.proto", file1);
Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
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("@Foo(fooValue) \n some more doc text", typeX.getDocumentation());
Map<String, AnnotationElement.Annotation> typeAnnotations = typeX.getAnnotations();
assertEquals("fooValue", typeAnnotations.get("Foo").getDefaultAttributeValue().getValue());
assertEquals("fooValue", typeX.getProcessedAnnotation("Foo"));
assertEquals("@Bar(barValue)", field1.getDocumentation());
Map<String, AnnotationElement.Annotation> fieldAnnotations = field1.getAnnotations();
assertEquals("barValue", fieldAnnotations.get("Bar").getDefaultAttributeValue().getValue());
assertEquals("barValue", field1.getProcessedAnnotation("Bar"));
}
Aggregations