use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testMultipleAnnotationAttribute.
@Test
public void testMultipleAnnotationAttribute() {
Configuration config = Configuration.builder().annotationsConfig().annotation("Xyz", AnnotationElement.AnnotationTarget.MESSAGE).attribute("elem1").type(AnnotationElement.AttributeType.BOOLEAN).defaultValue(true).multiple(true).build();
String testProto = "/** @Xyz(elem1 = {true, false, true}) */\n" + "message M {\n" + " optional int32 field1 = 1; \n" + "}\n";
FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromString("test.proto", testProto);
Map<String, FileDescriptor> descriptors = parseAndResolve(fileDescriptorSource, config);
FileDescriptor fileDescriptor = descriptors.get("test.proto");
List<Descriptor> messageTypes = fileDescriptor.getMessageTypes();
Descriptor messageType = messageTypes.get(0);
assertEquals("M", messageType.getFullName());
AnnotationElement.Annotation annotation = messageType.getAnnotations().get("Xyz");
assertNotNull(annotation);
AnnotationElement.Value attr = annotation.getAttributeValue("elem1");
assertTrue(attr instanceof AnnotationElement.Array);
assertTrue(attr.getValue() instanceof List);
List values = (List) attr.getValue();
assertEquals(3, values.size());
assertEquals(true, values.get(0));
assertEquals(false, values.get(1));
assertEquals(true, values.get(2));
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testDefinitionNameWithDots1.
@Test
public void testDefinitionNameWithDots1() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("Definition names must not be qualified : somePackage.M1");
String file1 = "package test;\n" + "message somePackage.M1 {\n" + " required string a = 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 testDuplicateTypeInFile3.
@Test
public void testDuplicateTypeInFile3() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("Duplicate definition of 'test.E1' in test_proto_path/file1.proto");
String file1 = "package test;\n" + "enum E1 {\n" + " VAL = 1;\n" + "}\n" + "enum E1 {\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 testTransform.
@Test
public void testTransform() throws Exception {
FileDescriptorSource fileDescriptorSource = FileDescriptorSource.fromResources("org/infinispan/protostream/test/message.proto", "org/infinispan/protostream/lib/base.proto", "org/infinispan/protostream/lib/base2.proto");
Map<String, FileDescriptor> files = parseAndResolve(fileDescriptorSource);
FileDescriptor descriptor = files.get("org/infinispan/protostream/test/message.proto");
assertThat(descriptor.getMessageTypes()).hasSize(3);
assertThat(descriptor.getEnumTypes()).hasSize(1);
assertThat(descriptor.getOptions()).hasSize(2);
assertSearchRequest(descriptor.getMessageTypes().get(0));
assertTopLevelEnum(descriptor.getEnumTypes().iterator().next());
assertSearchResponse(descriptor.getMessageTypes().get(1));
assertResult(descriptor.getMessageTypes().get(2));
assertExtensions(descriptor.getExtensionsTypes());
}
use of org.infinispan.protostream.FileDescriptorSource in project protostream by infinispan.
the class DescriptorsTest method testDuplicateTypeInMessage1.
@Test
public void testDuplicateTypeInMessage1() {
exception.expect(DescriptorParserException.class);
exception.expectMessage("Duplicate definition of 'test.M1.M2' in test_proto_path/file1.proto");
String file1 = "package test;\n" + "message M1 {\n" + " required string a = 1;\n" + " message M2 { required string a = 1; }\n" + " message M2 { required string b = 1; }\n" + "}\n";
FileDescriptorSource fileDescriptorSource = new FileDescriptorSource();
fileDescriptorSource.addProtoFile("test_proto_path/file1.proto", file1);
parseAndResolve(fileDescriptorSource);
}
Aggregations