Search in sources :

Example 6 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor 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);
}
Also used : FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Example 7 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor 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();
}
Also used : Configuration(org.infinispan.protostream.config.Configuration) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Example 8 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor 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));
}
Also used : Configuration(org.infinispan.protostream.config.Configuration) AnnotationElement(org.infinispan.protostream.descriptors.AnnotationElement) Descriptor(org.infinispan.protostream.descriptors.Descriptor) EnumDescriptor(org.infinispan.protostream.descriptors.EnumDescriptor) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) ExtendDescriptor(org.infinispan.protostream.descriptors.ExtendDescriptor) FieldDescriptor(org.infinispan.protostream.descriptors.FieldDescriptor) GenericDescriptor(org.infinispan.protostream.descriptors.GenericDescriptor) List(java.util.List) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Example 9 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor 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());
}
Also used : FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Example 10 with FileDescriptor

use of org.infinispan.protostream.descriptors.FileDescriptor 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());
}
Also used : Configuration(org.infinispan.protostream.config.Configuration) AnnotationElement(org.infinispan.protostream.descriptors.AnnotationElement) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) FileDescriptor(org.infinispan.protostream.descriptors.FileDescriptor) Test(org.junit.Test)

Aggregations

FileDescriptor (org.infinispan.protostream.descriptors.FileDescriptor)43 FileDescriptorSource (org.infinispan.protostream.FileDescriptorSource)24 Test (org.junit.Test)23 Descriptor (org.infinispan.protostream.descriptors.Descriptor)12 Configuration (org.infinispan.protostream.config.Configuration)11 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)11 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)11 List (java.util.List)8 SerializationContext (org.infinispan.protostream.SerializationContext)8 AnnotationElement (org.infinispan.protostream.descriptors.AnnotationElement)8 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 DescriptorParserException (org.infinispan.protostream.DescriptorParserException)5 ExtendDescriptor (org.infinispan.protostream.descriptors.ExtendDescriptor)5 EntityIndexDescriptor (org.kie.kogito.persistence.api.schema.EntityIndexDescriptor)4 HashMap (java.util.HashMap)3 ResolutionContext (org.infinispan.protostream.descriptors.ResolutionContext)3 Ignore (org.junit.Ignore)3 Test (org.junit.jupiter.api.Test)3