Search in sources :

Example 26 with FileDescriptorSource

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

Example 27 with 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);
}
Also used : FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) Test(org.junit.Test)

Example 28 with 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());
}
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)

Example 29 with FileDescriptorSource

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

Example 30 with FileDescriptorSource

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());
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) DescriptorParserException(org.infinispan.protostream.DescriptorParserException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FileDescriptorSource(org.infinispan.protostream.FileDescriptorSource) Test(org.junit.Test)

Aggregations

FileDescriptorSource (org.infinispan.protostream.FileDescriptorSource)74 Test (org.junit.Test)61 FileDescriptor (org.infinispan.protostream.descriptors.FileDescriptor)24 SerializationContext (org.infinispan.protostream.SerializationContext)23 Configuration (org.infinispan.protostream.config.Configuration)13 DescriptorParserException (org.infinispan.protostream.DescriptorParserException)9 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)8 HashMap (java.util.HashMap)7 AnnotationElement (org.infinispan.protostream.descriptors.AnnotationElement)7 Descriptor (org.infinispan.protostream.descriptors.Descriptor)7 List (java.util.List)6 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ExtendDescriptor (org.infinispan.protostream.descriptors.ExtendDescriptor)5 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)5 TagReader (org.infinispan.protostream.TagReader)4 SerializationContextImpl (org.infinispan.protostream.impl.SerializationContextImpl)4 Map (java.util.Map)3 ReadContext (org.infinispan.protostream.ProtobufTagMarshaller.ReadContext)3