summaryrefslogtreecommitdiff
path: root/eaaf_core
diff options
context:
space:
mode:
authorThomas <>2022-01-09 16:54:19 +0100
committerThomas <>2022-01-09 16:54:19 +0100
commitb5980663a63b3c128a8714fe7c13339eaa0a2955 (patch)
tree1925491265aa19dcdb221be6ae05fdb4d700e533 /eaaf_core
parente3639ef805f1e525415c43cbda80ed71cc43a70c (diff)
downloadEAAF-Components-b5980663a63b3c128a8714fe7c13339eaa0a2955.tar.gz
EAAF-Components-b5980663a63b3c128a8714fe7c13339eaa0a2955.tar.bz2
EAAF-Components-b5980663a63b3c128a8714fe7c13339eaa0a2955.zip
fix(core): change validation of loaded process-definitions to fix problem of circular-dependencies loading
Diffstat (limited to 'eaaf_core')
-rw-r--r--eaaf_core/pom.xml6
-rw-r--r--eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/process/ProcessEngineImpl.java24
-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
4 files changed, 108 insertions, 20 deletions
diff --git a/eaaf_core/pom.xml b/eaaf_core/pom.xml
index a14c107b..a22c49fe 100644
--- a/eaaf_core/pom.xml
+++ b/eaaf_core/pom.xml
@@ -108,6 +108,12 @@
<scope>test</scope>
<type>test-jar</type>
</dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
<build>
diff --git a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/process/ProcessEngineImpl.java b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/process/ProcessEngineImpl.java
index 6e83a201..6080445d 100644
--- a/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/process/ProcessEngineImpl.java
+++ b/eaaf_core/src/main/java/at/gv/egiz/eaaf/core/impl/idp/process/ProcessEngineImpl.java
@@ -22,8 +22,11 @@ package at.gv.egiz.eaaf.core.impl.idp.process;
import java.io.InputStream;
import java.io.Serializable;
import java.text.MessageFormat;
+import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.collections4.IterableUtils;
@@ -521,18 +524,15 @@ public class ProcessEngineImpl implements ProcessEngine {
* @throws ProcessDefinitionParserException In case of a parser error
*/
private void postValidationOfProcessDefintion(final ProcessDefinition pd)
- throws ProcessDefinitionParserException {
- try {
- for (final TaskInfo task : pd.getTaskInfos().values()) {
- createTaskInstance(task);
- }
-
- } catch (final ProcessExecutionException e) {
- log.error("Post-validation of process definition: {} find an error: {}", pd.getId(),
- e.getMessage());
- throw new ProcessDefinitionParserException(
- "Post-validation find an error in process definition:" + pd.getId(), e);
-
+ throws ProcessDefinitionParserException {
+ List<String> beanNames = Arrays.asList(context.getBeanDefinitionNames());
+ Optional<TaskInfo> missing = pd.getTaskInfos().values().stream()
+ .filter(el -> !beanNames.contains(el.getTaskImplementingClass()))
+ .findFirst();
+ if (missing.isPresent()) {
+ log.error("Post-validation of process definition: {} find an error. Missing bean with name: {}",
+ pd.getId(), missing.get().getTaskImplementingClass());
+
}
}
}
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());
}
}