From d392ef47de5ba1db5e22e8186f5cda2c7ac3c346 Mon Sep 17 00:00:00 2001 From: Michal Somora Date: Mon, 23 Oct 2023 09:15:01 +0200 Subject: [PATCH] feat:mdc errorKey test --- .../log/cdi/test/ErrorDataServiceTest.java | 12 ++++++++++-- .../cdi/test/app/DummyLogFriendlyException.java | 15 +++++++++++++++ .../log/cdi/test/app/ErrorDataService.java | 4 ++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/app/DummyLogFriendlyException.java 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..4edd22d 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 @@ -28,7 +28,15 @@ 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") + .assertLines(91); + } + + @Test + public void error2Test() { + Assertions.assertThrows(RuntimeException.class, () -> service.error2()); + assertLogs().assertLines(91) .assertContains(0, "ERROR [org.tki.qua.log.cdi.tes.app.ErrorDataService] (main) error1(Error) throw java.lang.RuntimeException: Error"); } @@ -44,7 +52,7 @@ public void noStacktraceTest() { @Test public void wrapperTest() { Assertions.assertThrows(RuntimeException.class, () -> wrapper.wrapperMethod("WrapperError")); - assertLogs()/*.assertLines(104)*/ + assertLogs().assertLines(104) .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..19a0167 --- /dev/null +++ b/extensions/log/cdi/deployment/src/test/java/org/tkit/quarkus/log/cdi/test/app/DummyLogFriendlyException.java @@ -0,0 +1,15 @@ +package org.tkit.quarkus.log.cdi.test.app; + +import org.tkit.quarkus.log.cdi.LogFriendlyException; + +public class DummyLogFriendlyException extends RuntimeException implements LogFriendlyException { + @Override + public String getErrorNumber() { + return "DummyErrorNUmber"; + } + + @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");