aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-12 15:40:05 +0200
committerChristof Rabensteiner <christof.rabensteiner@iaik.tugraz.at>2019-07-12 15:40:05 +0200
commit25d68c8900c2cc791f03ea3db173955ca237fd55 (patch)
treef4d28b97845d10a709590dce480195b322ba019b /src/test
parent9dc0e72571a895e34a55c11d015c5d359b485aff (diff)
downloadmoa-zs-25d68c8900c2cc791f03ea3db173955ca237fd55.tar.gz
moa-zs-25d68c8900c2cc791f03ea3db173955ca237fd55.tar.bz2
moa-zs-25d68c8900c2cc791f03ea3db173955ca237fd55.zip
Allow App To Choose Between MsgResponse Sinks
- MZS Schema Change: Add "MsgResponseSinks" element to mzs:DeliveryRequest/Config that allows sender to configure how MsgResponses should be archived. - ConfigUtil: Interpret MsgResponseSink parameters from Spring Environment and merge with ConfigType. - MsgResponseBackend: Send responses to sinks according to MsgResponseSinks in Config - application.yaml: Add MsgResponseSinks parameter to configuration. - Uncouple Sink implementations from java.util.function.Function, because the sink interfaces are going to differ and there is no need to unite them under one interface. - Add and test LogResponseSink, which logs responses to it's logger. - MsgResponse: Add JAXB getter for response. Reason: Can be passed to marshaller.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/at/gv/egiz/moazs/LogResponseSinkTest.java78
-rw-r--r--src/test/java/at/gv/egiz/moazs/SaveResponseToFileSinkTest.java2
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));
}