use of org.infinispan.protostream.DescriptorParserException in project kogito-apps by kiegroup.
the class ProtoIndexParserTest method testConfigureBuilderWithInvalidFile.
@Test
void testConfigureBuilderWithInvalidFile() {
SerializationContext ctx = new SerializationContextImpl(configureBuilder().build());
FileDescriptorSource invalidFileDescriptorSource = FileDescriptorSource.fromString("invalid", "invalid");
try {
ctx.registerProtoFiles(invalidFileDescriptorSource);
fail("Failed to process invalid proto file");
} catch (DescriptorParserException ex) {
// Successfully throw exception
}
}
use of org.infinispan.protostream.DescriptorParserException 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());
}
use of org.infinispan.protostream.DescriptorParserException in project protostream by infinispan.
the class SerializationContextImplTest method testFileCannotExistWithParsingErrors.
/**
* Test that files with syntax errors DO NOT get registered if there is no progress callback present.
*/
@Test
public void testFileCannotExistWithParsingErrors() {
SerializationContext ctx = createContext();
FileDescriptorSource source = FileDescriptorSource.fromString("file1.proto", "this is bogus");
try {
ctx.registerProtoFiles(source);
fail("DescriptorParserException expected");
} catch (DescriptorParserException e) {
assertEquals("java.lang.IllegalStateException: Syntax error in file1.proto at 1:5: unexpected label: this", e.getMessage());
}
FileDescriptor fileDescriptor = ctx.getFileDescriptors().get("file1.proto");
assertNull(fileDescriptor);
}
use of org.infinispan.protostream.DescriptorParserException in project protostream by infinispan.
the class SerializationContextImplTest method testTwoFilesWithErrorsAtOnce.
@Test
public void testTwoFilesWithErrorsAtOnce() {
SerializationContext ctx = createContext();
Map<String, Throwable> errors = new HashMap<>();
List<String> successful = new ArrayList<>();
FileDescriptorSource source = FileDescriptorSource.fromString("test1.proto", "kabooom1").addProtoFile("test2.proto", "kabooom2").withProgressCallback(new FileDescriptorSource.ProgressCallback() {
@Override
public void handleError(String fileName, DescriptorParserException ex) {
errors.put(fileName, ex);
}
@Override
public void handleSuccess(String fileName) {
successful.add(fileName);
}
});
ctx.registerProtoFiles(source);
assertTrue(successful.isEmpty());
assertEquals(2, errors.size());
assertTrue(errors.containsKey("test1.proto"));
assertTrue(errors.containsKey("test2.proto"));
assertEquals("java.lang.IllegalStateException: Syntax error in test1.proto at 1:9: unexpected label: kabooom1", errors.get("test1.proto").getMessage());
assertEquals("java.lang.IllegalStateException: Syntax error in test2.proto at 1:9: unexpected label: kabooom2", errors.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());
}
use of org.infinispan.protostream.DescriptorParserException in project protostream by infinispan.
the class SerializationContextImplTest method testUnregisterFileWithErrors.
@Test
public void testUnregisterFileWithErrors() {
SerializationContext ctx = createContext();
Map<String, Throwable> errors = new HashMap<>();
List<String> successful = new ArrayList<>();
FileDescriptorSource source = FileDescriptorSource.fromString("test.proto", "kabooom").withProgressCallback(new FileDescriptorSource.ProgressCallback() {
@Override
public void handleError(String fileName, DescriptorParserException ex) {
errors.put(fileName, ex);
}
@Override
public void handleSuccess(String fileName) {
successful.add(fileName);
}
});
ctx.registerProtoFiles(source);
assertTrue(successful.isEmpty());
assertEquals(1, errors.size());
assertTrue(errors.containsKey("test.proto"));
assertEquals("java.lang.IllegalStateException: Syntax error in test.proto at 1:8: unexpected label: kabooom", errors.get("test.proto").getMessage());
assertTrue(ctx.getFileDescriptors().containsKey("test.proto"));
assertFalse(ctx.getFileDescriptors().get("test.proto").isResolved());
ctx.unregisterProtoFile("test.proto");
assertFalse(ctx.getFileDescriptors().containsKey("test.proto"));
}
Aggregations