diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/at/gv/egiz/moazs/LogResponseSinkTest.java | 78 | ||||
-rw-r--r-- | src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java | 2 |
2 files changed, 79 insertions, 1 deletions
diff --git a/src/test/java/at/gv/egiz/moazs/LogResponseSinkTest.java b/src/test/java/at/gv/egiz/moazs/LogResponseSinkTest.java new file mode 100644 index 0000000..9e7c49d --- /dev/null +++ b/src/test/java/at/gv/egiz/moazs/LogResponseSinkTest.java @@ -0,0 +1,78 @@ +package at.gv.egiz.moazs; + +import at.gv.egiz.moazs.backend.LogResponseSink; +import at.gv.egiz.moazs.scheme.Marshaller; +import at.gv.egiz.moazs.scheme.NotificationResponse; +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.Appender; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.slf4j.LoggerFactory; + +import static at.gv.zustellung.msg.xsd.DeliveryNotificationType.deliveryNotificationTypeBuilder; +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.Mockito.verify; + +@RunWith(MockitoJUnitRunner.class) +public class LogResponseSinkTest { + + private LogResponseSink logResponseSink; + + @Mock + private Appender appender; + private ch.qos.logback.classic.Logger logger; + + @Before + public void setup() { + logResponseSink = new LogResponseSink(new Marshaller(false)); + logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(LogResponseSink.class); + logger.addAppender(appender); + } + + @Test + public void logNotification() { + setLogLevel(Level.INFO); + var appDeliveryID = "log-notification-id"; + var notification = setupNotification(appDeliveryID); + + logResponseSink.log(notification) + .thenRun(expectSubstringSentToAppender(appDeliveryID)); + } + + @Test + public void warnWhenLogDisabled() { + setLogLevel(Level.WARN); + var appDeliveryID = "log-info-disabled"; + var notification = setupNotification(appDeliveryID); + + logResponseSink.log(notification) + .thenRun(expectSubstringSentToAppender("WARN")); + } + + private Runnable expectSubstringSentToAppender(String expectedSubstring) { + return ()-> verify(appender).doAppend(argThat(argument -> { + var message = ((ILoggingEvent) argument).getFormattedMessage(); + return message.contains(expectedSubstring); + })); + } + + private NotificationResponse setupNotification(String appDeliveryID) { + + var notification = deliveryNotificationTypeBuilder() + .withAppDeliveryID(appDeliveryID) + .build(); + + return new NotificationResponse(notification); + + } + + private void setLogLevel(Level level) { + logger.setLevel(level); + } + + +} diff --git a/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java b/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java index 9ddd37e..58efe6a 100644 --- a/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java +++ b/src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java @@ -63,7 +63,7 @@ public class SaveResponseToFileSinkTest { var fileContent = "<xml>some content</xml>"; var status = setupMocks(fileContent); - sink.apply(status) + sink.save(status) .thenRun(() -> assertFilesCreatedAndContentMatches(fileContent)); } |