From b5980663a63b3c128a8714fe7c13339eaa0a2955 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Sun, 9 Jan 2022 16:54:19 +0100 Subject: fix(core): change validation of loaded process-definitions to fix problem of circular-dependencies loading --- eaaf_core/pom.xml | 6 +++ .../core/impl/idp/process/ProcessEngineImpl.java | 24 +++++----- .../idp/auth/logging/MemoryLoggingAppender.java | 56 ++++++++++++++++++++++ .../impl/idp/process/test/ProcessEngineTest.java | 42 ++++++++++++---- pom.xml | 11 +++-- 5 files changed, 116 insertions(+), 23 deletions(-) create mode 100644 eaaf_core/src/test/java/at/gv/egiz/eaaf/core/impl/idp/auth/logging/MemoryLoggingAppender.java 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 @@ test test-jar + + ch.qos.logback + logback-classic + test + + 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 beanNames = Arrays.asList(context.getBeanDefinitionNames()); + Optional 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 { + + 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 search(String string) { + return this.list.stream() + .filter(event -> event.getMessage().toString().contains(string)) + .collect(Collectors.toList()); + } + + public List 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 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()); } } diff --git a/pom.xml b/pom.xml index af2cab73..71eaf6fc 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ 1.7.32 2.17.1 - 1.2.10 + 1.2.10 1.15 3.12.0 @@ -480,8 +480,13 @@ ch.qos.logback logback-access - ${ch.qos.logback-access.version} - + ${ch.qos.logback.version} + + + ch.qos.logback + logback-classic + ${ch.qos.logback.version} + commons-codec commons-codec -- cgit v1.2.3