summaryrefslogtreecommitdiff
path: root/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/logging/MemoryLoggingAppender.java
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/logging/MemoryLoggingAppender.java')
-rw-r--r--eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/logging/MemoryLoggingAppender.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/logging/MemoryLoggingAppender.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/logging/MemoryLoggingAppender.java
new file mode 100644
index 00000000..2b885d59
--- /dev/null
+++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/logging/MemoryLoggingAppender.java
@@ -0,0 +1,56 @@
+package at.gv.egiz.eaaf.core.impl.idp.auth.logging;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
+
+/**
+ * In-Memory Logging-Appender to check log messages.
+ *
+ * @author tlenz
+ *
+ */
+public class MemoryLoggingAppender extends ListAppender<ILoggingEvent> {
+
+ public void reset() {
+ this.list.clear();
+ }
+
+ public boolean contains(String string, Level level) {
+ return this.list.stream()
+ .anyMatch(event -> event.getMessage().toString().contains(string)
+ && event.getLevel().equals(level));
+ }
+
+ public int countEventsForLogger(String loggerName) {
+ return (int) this.list.stream()
+ .filter(event -> event.getLoggerName().contains(loggerName))
+ .count();
+ }
+
+ public List<ILoggingEvent> search(String string) {
+ return this.list.stream()
+ .filter(event -> event.getMessage().toString().contains(string))
+ .collect(Collectors.toList());
+ }
+
+ public List<ILoggingEvent> search(String string, Level level) {
+ return this.list.stream()
+ .filter(event -> event.getMessage().toString().contains(string)
+ && event.getLevel().equals(level))
+ .collect(Collectors.toList());
+ }
+
+ public int getSize() {
+ return this.list.size();
+ }
+
+ public List<ILoggingEvent> getLoggedEvents() {
+ return Collections.unmodifiableList(this.list);
+ }
+
+}