tpalfy commented on code in PR #6703:
URL: https://github.com/apache/nifi/pull/6703#discussion_r1031470829
##########
nifi-nar-bundles/nifi-asn1-bundle/nifi-asn1-services/src/test/java/org/apache/nifi/jasn1/JASN1ReaderTest.java:
##########
@@ -78,4 +89,82 @@ public void testCanLoadClassCompiledFromAsn() throws
Exception {
assertEquals("org.apache.nifi.jasn1.test.RootType",
actualRootModelName);
assertNotNull(actual);
}
+
+ @Test
+ public void testAsnFileDoesntExist() throws Exception {
+ // GIVEN
+ ConfigurationContext context = mock(ConfigurationContext.class,
RETURNS_DEEP_STUBS);
+ when(context.getProperty(ASN_FILES).isSet()).thenReturn(true);
+
when(context.getProperty(ASN_FILES).evaluateAttributeExpressions().getValue()).thenReturn(
+
"src/test/resources/test.asn,src/test/resources/doesnt_exist.asn"
+ );
+
+ // WHEN
+ ProcessException processException = assertThrows(
+ ProcessException.class,
+ () -> testSubject.onEnabled(context)
+ );
+ Throwable cause = processException.getCause();
+
+ assertEquals(FileNotFoundException.class, cause.getClass());
+ assertThat(cause.getMessage(),
containsString("src/test/resources/doesnt_exist.asn"));
+ }
+
+ @Test
+ public void testCantParseAsn() throws Exception {
+ // GIVEN
+ String asnFiles = "src/test/resources/cant_parse.asn";
+
+ List<String> expectedErrorMessages = Arrays.asList(
+ "line 11:5: unexpected token: field3",
+ "line 17:33: unexpected token: ["
+ );
+
+ // WHEN
+ // THEN
+ testError(asnFiles, expectedErrorMessages);
+ }
+
+ @Test
+ public void testCantCompileAsn() throws Exception {
+ // GIVEN
+ String asnFiles = "src/test/resources/cant_compile.asn";
+
+ List<String> expectedErrorMessages = Arrays.asList(
+ "class SAMENAMEWithDifferentCase is public, should be declared
in a file named SAMENAMEWithDifferentCase.java",
+ "cannot find symbol\n" +
+ " symbol: class SameNameWithDifferentCase\n" +
+ " location: class
org.apache.nifi.jasn1.test.SAMENAMEWithDifferentCase",
+ "incompatible types: com.beanit.asn1bean.ber.types.BerInteger
cannot be converted to com.beanit.asn1bean.ber.BerLength",
+ "incompatible types: boolean cannot be converted to
java.io.OutputStream",
+ "Some messages have been simplified; recompile with
-Xdiags:verbose to get full output"
+ );
Review Comment:
I used this approach in `testAsnFileDoesntExist` for example.
However in these cases the error messages by the underlying libraries are
very technical and don't convey the root cause very well if at all. So there
are no good keywords the presence/lack of which would correspond to a given
error.
For the same reason I documented the errors exactly as they appear in the
additionalDetails.html and provided an explanation for them.
I expect the list of known issues to grow but not the existing ones to
change as the underlying apis don't change often. And when they do, we need to
make sure we understand the change.
However I'll update the tests to mention the additionalDetails. This way any
change will be captured by the tests and hopefully the user won't get stuck
with outdated info either.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]