summaryrefslogtreecommitdiff
path: root/eaaf_core/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core/src/test/java')
-rw-r--r--eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/logging/MemoryLoggingAppender.java56
-rw-r--r--eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/process/test/ProcessEngineTest.java42
2 files changed, 90 insertions, 8 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);
+ }
+
+}
diff --git a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/process/test/ProcessEngineTest.java b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/process/test/ProcessEngineTest.java
index 7ce4c6b3..cbd274f2 100644
--- a/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/process/test/ProcessEngineTest.java
+++ b/eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/process/test/ProcessEngineTest.java
@@ -31,6 +31,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
@@ -39,11 +40,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import at.gv.egiz.eaaf.core.api.idp.process.ProcessEngine;
import at.gv.egiz.eaaf.core.exceptions.ProcessExecutionException;
import at.gv.egiz.eaaf.core.exceptions.TaskExecutionException;
+import at.gv.egiz.eaaf.core.impl.idp.auth.logging.MemoryLoggingAppender;
import at.gv.egiz.eaaf.core.impl.idp.module.test.TestRequestImpl;
import at.gv.egiz.eaaf.core.impl.idp.process.ProcessDefinitionParser;
import at.gv.egiz.eaaf.core.impl.idp.process.ProcessDefinitionParserException;
import at.gv.egiz.eaaf.core.impl.idp.process.ProcessEngineImpl;
import at.gv.egiz.eaaf.core.impl.idp.process.ProcessInstance;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import lombok.SneakyThrows;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/process/spring/test/SpringExpressionAwareProcessEngineTest-context.xml")
@@ -57,6 +63,8 @@ public class ProcessEngineTest {
private boolean isInitialized = false;
+ private MemoryLoggingAppender memoryAppender = null;
+
/**
* jUnit test set-up.
*
@@ -98,20 +106,38 @@ public class ProcessEngineTest {
// initHibernateForTesting();
isInitialized = true;
}
+
+ // setup log appender
+ if (memoryAppender == null) {
+ final Logger logger = (Logger) LoggerFactory.getLogger("at.gv.egiz");
+ memoryAppender = new MemoryLoggingAppender();
+ memoryAppender.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
+ logger.setLevel(Level.INFO);
+ logger.addAppender(memoryAppender);
+ memoryAppender.start();
+
+ } else {
+ memoryAppender.reset();
+
+ }
+
}
@Test
+ @SneakyThrows
public void wrongProcessDefinition() throws IOException {
try (InputStream in =
ProcessEngineTest.class.getResourceAsStream("/process/test/SampleProcessDefinition3.xml")) {
- try {
- ((ProcessEngineImpl) pe).registerProcessDefinition(in);
- Assert.fail();
-
- } catch (final ProcessDefinitionParserException e) {
- Assert.assertTrue(
- e.getMessage().contains("Post-validation find an error in process definition"));
- }
+
+ // parse process definition
+ ((ProcessEngineImpl) pe).registerProcessDefinition(in);
+
+ // check if error was logged
+ Assert.assertTrue("No error in log", memoryAppender.getLoggedEvents().stream()
+ .filter(el -> el.getLevel().equals(Level.ERROR))
+ .filter(el -> el.getMessage().contains("Post-validation of process definition"))
+ .findFirst()
+ .isPresent());
}
}