diff --git a/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceTest.java b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceTest.java index 7ae2e57..f470c46 100644 --- a/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceTest.java +++ b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/ErrorDataServiceTest.java @@ -5,17 +5,20 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import org.tkit.quarkus.log.cdi.test.app.DummyLogFriendlyException; import org.tkit.quarkus.log.cdi.test.app.ErrorDataService; import org.tkit.quarkus.log.cdi.test.app.ErrorWrapperService; import io.quarkus.test.QuarkusUnitTest; +import static org.tkit.quarkus.log.cdi.test.app.DummyLogFriendlyException.DUMMY_ERROR_NUMBER; + public class ErrorDataServiceTest extends AbstractTest { @RegisterExtension static final QuarkusUnitTest config = new QuarkusUnitTest() .withApplicationRoot((jar) -> jar - .addClasses(ErrorDataService.class, ErrorWrapperService.class) + .addClasses(ErrorDataService.class, ErrorWrapperService.class, DummyLogFriendlyException.class) .addAsResource("default.properties", "application.properties")); @Inject @@ -28,9 +31,16 @@ public class ErrorDataServiceTest extends AbstractTest { public void error1Test() { Assertions.assertThrows(RuntimeException.class, () -> service.error1("Error")); assertLogs() - /*.assertLines(91)*/ .assertContains(0, - "ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error1(Error) throw java.lang.RuntimeException: Error"); + "ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error1(Error) throw java.lang.RuntimeException: Error") + .assertLines(90); + } + + @Test + public void error2Test() { + Assertions.assertThrows(RuntimeException.class, () -> service.error2()); + assertLogs().assertContains(0, + DUMMY_ERROR_NUMBER +" ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error2() throw org.tkit.quarkus.log.cdi.test.app.DummyLogFriendlyException"); } @Test @@ -44,7 +54,7 @@ public void noStacktraceTest() { @Test public void wrapperTest() { Assertions.assertThrows(RuntimeException.class, () -> wrapper.wrapperMethod("WrapperError")); - assertLogs()/*.assertLines(104)*/ + assertLogs().assertLines(103) .assertContains(0, "ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error1(WrapperError) throw java.lang.RuntimeException: WrapperError"); } diff --git a/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/app/DummyLogFriendlyException.java b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/app/DummyLogFriendlyException.java new file mode 100644 index 0000000..78c03e9 --- /dev/null +++ b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/app/DummyLogFriendlyException.java @@ -0,0 +1,18 @@ +package org.tkit.quarkus.log.cdi.test.app; + +import org.tkit.quarkus.log.cdi.LogFriendlyException; + +public class DummyLogFriendlyException extends RuntimeException implements LogFriendlyException { + + public static final String DUMMY_ERROR_NUMBER = "DummyErrorNumber"; + + @Override + public String getErrorNumber() { + return DUMMY_ERROR_NUMBER; + } + + @Override + public boolean shouldLogStacktrace() { + return false; + } +} diff --git a/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/app/ErrorDataService.java b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/app/ErrorDataService.java index 59931b7..a43d9c2 100644 --- a/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/app/ErrorDataService.java +++ b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/app/ErrorDataService.java @@ -12,6 +12,10 @@ public void error1(String error) { throw new RuntimeException(error); } + public void error2() { + throw new DummyLogFriendlyException(); + } + @LogService(stacktrace = false) public void noStacktrace() { throw new RuntimeException("Error1"); diff --git a/extensions/log/cdi/deployment/src/test/resources/default.properties b/extensions/log/cdi/deployment/src/test/resources/default.properties index e69de29..a7ee9cf 100644 --- a/extensions/log/cdi/deployment/src/test/resources/default.properties +++ b/extensions/log/cdi/deployment/src/test/resources/default.properties @@ -0,0 +1 @@ +quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %X{business_information_errorNumber} %-5p [%c{3.}] (%t) %s%e%n \ No newline at end of file