Skip to content

Commit

Permalink
feat:mdc errorKey test
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsomora committed Oct 23, 2023
1 parent 65c6377 commit 8a8906b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(91);
}

@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
Expand All @@ -44,7 +54,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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8a8906b

Please sign in to comment.