diff --git a/pom.xml b/pom.xml index d3842f60..a791d3eb 100644 --- a/pom.xml +++ b/pom.xml @@ -183,18 +183,10 @@ ca.mcgill.sable soot - 3.0.0-SNAPSHOT + 3.2.0 - - - soot-snapshot - soot snapshots - https://soot-build.cs.uni-paderborn.de/nexus/repository/soot-snapshot/ - - - release-sign-artifacts @@ -342,7 +334,7 @@ org.owasp dependency-check-maven - 3.3.4 + 4.0.2 owasp-dependency-check-suppressions.xml diff --git a/src/main/java/de/viadee/bpm/vPAV/BpmnScanner.java b/src/main/java/de/viadee/bpm/vPAV/BpmnScanner.java index bb2f0a71..fd807f09 100644 --- a/src/main/java/de/viadee/bpm/vPAV/BpmnScanner.java +++ b/src/main/java/de/viadee/bpm/vPAV/BpmnScanner.java @@ -31,23 +31,17 @@ */ package de.viadee.bpm.vPAV; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import de.viadee.bpm.vPAV.constants.BpmnConstants; +import org.w3c.dom.*; +import org.xml.sax.SAXException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.constants.BpmnConstants; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; public class BpmnScanner { diff --git a/src/main/java/de/viadee/bpm/vPAV/FileScanner.java b/src/main/java/de/viadee/bpm/vPAV/FileScanner.java index afa82569..972354c6 100644 --- a/src/main/java/de/viadee/bpm/vPAV/FileScanner.java +++ b/src/main/java/de/viadee/bpm/vPAV/FileScanner.java @@ -31,22 +31,11 @@ */ package de.viadee.bpm.vPAV; -import java.io.File; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.ConfigItemNotFoundException; +import de.viadee.bpm.vPAV.processing.checker.VersioningChecker; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.DirectoryFileFilter; import org.apache.commons.io.filefilter.TrueFileFilter; @@ -60,11 +49,14 @@ import org.camunda.bpm.model.dmn.DmnModelInstance; import org.camunda.bpm.model.dmn.instance.Decision; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.ConfigItemNotFoundException; -import de.viadee.bpm.vPAV.processing.checker.VersioningChecker; +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * scans maven project for files, which are necessary for the later analysis diff --git a/src/main/java/de/viadee/bpm/vPAV/OuterProcessVariablesScanner.java b/src/main/java/de/viadee/bpm/vPAV/OuterProcessVariablesScanner.java deleted file mode 100644 index 715ce0dc..00000000 --- a/src/main/java/de/viadee/bpm/vPAV/OuterProcessVariablesScanner.java +++ /dev/null @@ -1,377 +0,0 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import org.apache.commons.io.IOUtils; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.types.Resource; - -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import groovyjarjarasm.asm.ClassReader; -import groovyjarjarasm.asm.ClassVisitor; -import groovyjarjarasm.asm.FieldVisitor; -import groovyjarjarasm.asm.Opcodes; - -/** - * scan process variables, which are set in outer java classes - * - */ -public class OuterProcessVariablesScanner { - - private Set javaResources; - - private Map> messageIdToVariableMap = new HashMap>(); - - private Map> processIdToVariableMap = new HashMap>(); - - private Collection initialProcessVariables = new ArrayList(); - - private Collection initialProcessVariablesLocation = new ArrayList(); - - public OuterProcessVariablesScanner(final Set javaResources) { - this.javaResources = javaResources; - } - - /** - * scan variables - * - * @throws IOException - * possible exception if filepath can not be resolved - */ - public void scanProcessVariables() throws IOException { - for (final String filePath : javaResources) { - if (!filePath.startsWith("javax")) { - final String content = readResourceFile(filePath); - if (content != null) { - final Collection initialProcessVariablesInFilePath = readVariablesOfInnerClassInitialProcessVariables( - filePath); - if (!initialProcessVariablesInFilePath.isEmpty()) { - initialProcessVariables.addAll(initialProcessVariablesInFilePath); - initialProcessVariablesLocation.add(filePath); - // if correlateMessage and startProcessInstanceByMessage called - // together in one class take the intersection to avoid duplicates - final Set messageIds = new HashSet(); - messageIds.addAll(checkStartProcessByMessageIdPattern(content)); - messageIds.addAll(checkStartProcessByMessageAndProcessDefinitionId(content)); - messageIds.addAll(checkCorrelateMessagePattern(content)); - for (final String messageId : messageIds) { - if (messageIdToVariableMap.containsKey(messageId)) { - // if messageId is already set, create intersection of variables and overwrite map - // item - final Collection existingProcessVariables = messageIdToVariableMap - .get(messageId); - final List intersectionProcessVariables = existingProcessVariables.stream() - .filter(initialProcessVariablesInFilePath::contains) - .collect(Collectors.toList()); - - messageIdToVariableMap.put(messageId, intersectionProcessVariables); - } else { - messageIdToVariableMap.put(messageId, initialProcessVariablesInFilePath); - } - } - - final Set processIds = new HashSet(); - processIds.addAll(checkStartProcessByKeyPattern(content)); - processIds.addAll(checkStartProcessByIdPattern(content)); - - for (final String processId : processIds) { - processIdToVariableMap.put(processId, initialProcessVariablesInFilePath); - } - } - } - } - } - } - - - /** - * get list of locations where initial process variables have been found - * - * @return returns list of locations - */ - public Collection getInitialProcessVariablesLocation() { - return initialProcessVariablesLocation; - } - - - /** - * get mapping for message id - * - * @return messageIdToVariableMap returns messageIdToVariableMap - */ - public Map> getMessageIdToVariableMap() { - return messageIdToVariableMap; - } - - /** - * get mapping for process id - * - * @return processIdToVariableMap returns processIdToVariableMap - */ - public Map> getProcessIdToVariableMap() { - return processIdToVariableMap; - } - - /** - * read resource file - * - * @param filePath - * path of the file - * @return methodBody returns methodBody - */ - private String readResourceFile(final String filePath) { - String methodBody = ""; - - if (filePath != null && filePath.trim().length() > 0) { - try { - final DirectoryScanner scanner = new DirectoryScanner(); - - if (RuntimeConfig.getInstance().isTest()) { - scanner.setBasedir(ConfigConstants.TEST_JAVAPATH); - } else { - scanner.setBasedir(ConfigConstants.JAVAPATH); - } - - Resource s = scanner.getResource(filePath); - - if (s.isExists()) { - - InputStreamReader resource = new InputStreamReader(new FileInputStream(s.toString())); - - methodBody = IOUtils.toString(resource); - - } else { - - } - } catch (final IOException ex) { - throw new RuntimeException( - "resource '" + filePath + "' could not be read: " + ex.getMessage()); - } - - } - - return methodBody; - - } - - /** - * check pattern for startProcessInstanceByMessage - * - * @param code - * @return message ids - */ - private Collection checkStartProcessByMessageIdPattern(final String code) { - - // remove special characters from code - final String FILTER_PATTERN = "'|\"| "; - final String cleanedCode = code.replaceAll(FILTER_PATTERN, ""); - - // search locations where variables are read - final Pattern pattern = Pattern.compile("\\.(startProcessInstanceByMessage)(\\()([a-z0-9_.]+)(,.?)*(\\n?)([a-z0-9_.()])*(,?)([a-z0-9_.()])*\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); - final Matcher matcher = pattern.matcher(cleanedCode); - - final Collection messageIds = new ArrayList(); - while (matcher.find()) { - final String match = matcher.group(3); - messageIds.add(match); - } - - return messageIds; - } - - /** - * check pattern for startProcessInstanceById - * - * @param code - * @return message ids - */ - private Collection checkStartProcessByIdPattern(final String code) { - - // remove special characters from code - final String FILTER_PATTERN = "'|\"| "; - final String cleanedCode = code.replaceAll(FILTER_PATTERN, ""); - - // search locations where variables are read - final Pattern pattern = Pattern.compile("\\.(startProcessInstanceById)(\\()([a-z0-9_.]+)(,.?)*(\\n?)([a-z0-9_.()])*(,?)([a-z0-9_.()])*\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); - final Matcher matcher = pattern.matcher(cleanedCode); - - final Collection processIds = new ArrayList(); - while (matcher.find()) { - final String match = matcher.group(3); - processIds.add(match); - } - - return processIds; - } - - - /** - * check pattern for startProcessInstanceByMessageAndProcessDefinitionId - * - * @param code - * @return message ids - */ - private Collection checkStartProcessByMessageAndProcessDefinitionId(final String code) { - - // remove special characters from code - final String FILTER_PATTERN = "'|\"| "; - final String cleanedCode = code.replaceAll(FILTER_PATTERN, ""); - - // search locations where variables are read - final Pattern pattern = Pattern.compile("\\.(startProcessInstanceByMessageAndProcessDefinitionId)(\\()([a-z0-9_.]+)(,.?)*(\\n?)([a-z0-9_.()])*(,?)([a-z0-9_.()])*\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); - final Matcher matcher = pattern.matcher(cleanedCode); - - final Collection messageAndProcessIds = new ArrayList(); - while (matcher.find()) { - final String match = matcher.group(3); - messageAndProcessIds.add(match); - } - - return messageAndProcessIds; - } - - /** - * check pattern for startProcessInstanceByKey - * - * @param code - * @return process keys - */ - private Collection checkStartProcessByKeyPattern(final String code) { - - // remove special characters from code - final String FILTER_PATTERN = "'|\"| "; - final String cleanedCode = code.replaceAll(FILTER_PATTERN, ""); - - // search locations where variables are read - final Pattern pattern = Pattern.compile("\\.(startProcessInstanceByKey)(\\()([a-z0-9_.]+)(,.?)*(\\n?)([a-z0-9_.()])*(,?)([a-z0-9_.()])*\\)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); - final Matcher matcher = pattern.matcher(cleanedCode); - - final Collection processIds = new ArrayList(); - while (matcher.find()) { - final String match = matcher.group(3); - processIds.add(match); - } - - return processIds; - } - - /** - * check pattern for correlateMessage - * - * @param code - * @return message ids - */ - private Collection checkCorrelateMessagePattern(final String code) { - - // remove special characters from code - final String FILTER_PATTERN = "'|\"| "; - final String cleanedCode = code.replaceAll(FILTER_PATTERN, ""); - - // search locations where variables are read - final Pattern pattern = Pattern.compile("\\.correlateMessage\\((\\w+),(.*)"); - final Matcher matcher = pattern.matcher(cleanedCode); - - final Collection messageIds = new ArrayList(); - while (matcher.find()) { - final String match = matcher.group(1); - messageIds.add(match); - } - - return messageIds; - } - - /** - * For given filePath returns fields of class InitialProcessVariables (either separate or inner class). This class is used to initialize the - * process - * - * @param filePath - * @return - * @throws IOException - */ - private Collection readVariablesOfInnerClassInitialProcessVariables(final String filePath) - throws IOException { - - final Collection processVariables = new ArrayList(); - - if (filePath != null) { - final String[] splittedFilePath = filePath.split("\\."); - if (splittedFilePath.length > 0) { - ClassVisitor cl = new ClassVisitor(Opcodes.ASM4) { - - @Override - public FieldVisitor visitField(int access, String name, String desc, String signature, - Object value) { - if (!name.startsWith("this")) { - processVariables.add(name); - } - super.visitField(access, name, desc, signature, value); - return null; - } - }; - - InputStream in = null; - if (splittedFilePath[0].contains(ConfigConstants.INITIAL_VARIABLES)) { - in = RuntimeConfig.getInstance().getClassLoader().getResourceAsStream(filePath.replace(".java", ".class")); - } else { - in = RuntimeConfig.getInstance().getClassLoader() - .getResourceAsStream(splittedFilePath[0] + "$InitialProcessVariables.class"); - } - - if (in != null) { - ClassReader classReader = new ClassReader(in); - classReader.accept(cl, 0); - } - } - } - return processVariables; - } - - - public Collection getInitialProcessVariables() { - return initialProcessVariables; - } -} diff --git a/src/main/java/de/viadee/bpm/vPAV/ProcessApplicationValidator.java b/src/main/java/de/viadee/bpm/vPAV/ProcessApplicationValidator.java index a600a235..43a56764 100644 --- a/src/main/java/de/viadee/bpm/vPAV/ProcessApplicationValidator.java +++ b/src/main/java/de/viadee/bpm/vPAV/ProcessApplicationValidator.java @@ -31,16 +31,15 @@ */ package de.viadee.bpm.vPAV; -import java.util.ArrayList; -import java.util.Collection; - -import de.viadee.bpm.vPAV.processing.dataflow.DataFlowRule; -import org.springframework.context.ApplicationContext; - import de.viadee.bpm.vPAV.beans.BeanMappingGenerator; import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.dataflow.DataFlowRule; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.springframework.context.ApplicationContext; + +import java.util.ArrayList; +import java.util.Collection; public class ProcessApplicationValidator { diff --git a/src/main/java/de/viadee/bpm/vPAV/ProcessApplicationVariableParser.java b/src/main/java/de/viadee/bpm/vPAV/ProcessApplicationVariableParser.java index 63c88aa0..c6c30d23 100644 --- a/src/main/java/de/viadee/bpm/vPAV/ProcessApplicationVariableParser.java +++ b/src/main/java/de/viadee/bpm/vPAV/ProcessApplicationVariableParser.java @@ -31,25 +31,24 @@ */ package de.viadee.bpm.vPAV; -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; - -import javax.xml.parsers.ParserConfigurationException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.springframework.context.ApplicationContext; -import org.xml.sax.SAXException; - import de.viadee.bpm.vPAV.beans.BeanMappingGenerator; import de.viadee.bpm.vPAV.constants.ConfigConstants; import de.viadee.bpm.vPAV.processing.BpmnModelDispatcher; import de.viadee.bpm.vPAV.processing.ElementGraphBuilder; +import de.viadee.bpm.vPAV.processing.ProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.ProcessVariable; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.springframework.context.ApplicationContext; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.HashMap; public class ProcessApplicationVariableParser { @@ -60,7 +59,7 @@ public static Collection parseProcessVariables(File modelFile, FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.JAVAPATH); - OuterProcessVariablesScanner variableScanner = readOuterProcessVariables(fileScanner); + ProcessVariablesScanner variableScanner = readOuterProcessVariables(fileScanner); BpmnScanner bpmnScanner = createScanner(modelFile); final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(modelFile); @@ -86,9 +85,9 @@ public static Collection parseProcessVariables(File modelFile, * @param fileScanner * FileScanner */ - private static OuterProcessVariablesScanner readOuterProcessVariables(final FileScanner fileScanner) throws RuntimeException { + private static ProcessVariablesScanner readOuterProcessVariables(final FileScanner fileScanner) throws RuntimeException { try { - OuterProcessVariablesScanner variableScanner = new OuterProcessVariablesScanner(fileScanner.getJavaResourcesFileInputStream()); + ProcessVariablesScanner variableScanner = new ProcessVariablesScanner(fileScanner.getJavaResourcesFileInputStream()); variableScanner.scanProcessVariables(); return variableScanner; } catch (final IOException e) { diff --git a/src/main/java/de/viadee/bpm/vPAV/Runner.java b/src/main/java/de/viadee/bpm/vPAV/Runner.java index d9ddf128..3573a0b5 100644 --- a/src/main/java/de/viadee/bpm/vPAV/Runner.java +++ b/src/main/java/de/viadee/bpm/vPAV/Runner.java @@ -31,51 +31,36 @@ */ package de.viadee.bpm.vPAV; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Logger; - import de.viadee.bpm.vPAV.config.model.Rule; import de.viadee.bpm.vPAV.config.reader.ConfigReaderException; import de.viadee.bpm.vPAV.config.reader.XmlConfigReader; import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.output.IssueOutputWriter; -import de.viadee.bpm.vPAV.output.JsOutputWriter; -import de.viadee.bpm.vPAV.output.JsonOutputWriter; -import de.viadee.bpm.vPAV.output.OutputWriterException; -import de.viadee.bpm.vPAV.output.RuleSetOutputWriter; -import de.viadee.bpm.vPAV.output.XmlOutputWriter; +import de.viadee.bpm.vPAV.output.*; import de.viadee.bpm.vPAV.processing.BpmnModelDispatcher; import de.viadee.bpm.vPAV.processing.ConfigItemNotFoundException; +import de.viadee.bpm.vPAV.processing.ProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.dataflow.DataFlowRule; import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.ModelDispatchResult; import de.viadee.bpm.vPAV.processing.model.data.ProcessVariable; +import java.io.*; +import java.net.MalformedURLException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.*; +import java.util.logging.Logger; + public class Runner { private static Logger logger = Logger.getLogger(Runner.class.getName()); private FileScanner fileScanner; - private OuterProcessVariablesScanner variableScanner; + private ProcessVariablesScanner variableScanner; private Collection issues; @@ -230,7 +215,7 @@ private void getProcessVariables(final Map rules) { if (rules.get("ProcessVariablesModelChecker").isActive() || rules.get("ProcessVariablesNameConventionChecker").isActive() || rules.get("DataFlowChecker").isActive()) { - variableScanner = new OuterProcessVariablesScanner(getFileScanner().getJavaResourcesFileInputStream()); + variableScanner = new ProcessVariablesScanner(getFileScanner().getJavaResourcesFileInputStream()); readOuterProcessVariables(variableScanner); setCheckProcessVariables(true); } else { @@ -320,10 +305,7 @@ private void createvPAVFolder() { } /** - * Delete files from destinations - * - * @param destinations - * List of destinations who will be deleted + * Delete files from validation folder */ private void deleteFiles() { File index = new File(ConfigConstants.VALIDATION_FOLDER); @@ -586,7 +568,7 @@ private FileReader createFileReader(final String filePath) { * ConfigItem not found */ private Collection checkModels(final Map rules, final FileScanner fileScanner, - final OuterProcessVariablesScanner variableScanner, Collection dataFlowRules) + final ProcessVariablesScanner variableScanner, Collection dataFlowRules) throws RuntimeException { final Collection issues = new ArrayList(); @@ -601,8 +583,6 @@ private Collection checkModels(final Map rules, fina * * @param rules * all rules of ruleSet.xml - * @param beanMapping - * beanMapping if spring context is available * @param processdef * processdefintion * @param fileScanner @@ -612,7 +592,7 @@ private Collection checkModels(final Map rules, fina * @return modelIssues */ private Collection checkModel(final Map rules, final String processdef, - final FileScanner fileScanner, final OuterProcessVariablesScanner variableScanner, + final FileScanner fileScanner, final ProcessVariablesScanner variableScanner, Collection dataFlowRules) { BpmnModelDispatcher bpmnModelDispatcher = new BpmnModelDispatcher(); ModelDispatchResult dispatchResult; @@ -641,7 +621,7 @@ private Collection checkModel(final Map rules, final * @throws IOException * Outer process variables couldn't be read */ - private void readOuterProcessVariables(final OuterProcessVariablesScanner scanner) throws RuntimeException { + private void readOuterProcessVariables(final ProcessVariablesScanner scanner) throws RuntimeException { try { scanner.scanProcessVariables(); } catch (final IOException e) { diff --git a/src/main/java/de/viadee/bpm/vPAV/RuntimeConfig.java b/src/main/java/de/viadee/bpm/vPAV/RuntimeConfig.java index 246b2e47..d9e95600 100644 --- a/src/main/java/de/viadee/bpm/vPAV/RuntimeConfig.java +++ b/src/main/java/de/viadee/bpm/vPAV/RuntimeConfig.java @@ -31,22 +31,17 @@ */ package de.viadee.bpm.vPAV; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import org.springframework.context.ApplicationContext; + import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; +import java.util.*; import java.util.logging.Logger; -import org.springframework.context.ApplicationContext; - -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.constants.ConfigConstants; - public class RuntimeConfig { private static RuntimeConfig instance; diff --git a/src/main/java/de/viadee/bpm/vPAV/beans/BeanMappingGenerator.java b/src/main/java/de/viadee/bpm/vPAV/beans/BeanMappingGenerator.java index 3c807890..ce492930 100644 --- a/src/main/java/de/viadee/bpm/vPAV/beans/BeanMappingGenerator.java +++ b/src/main/java/de/viadee/bpm/vPAV/beans/BeanMappingGenerator.java @@ -31,11 +31,11 @@ */ package de.viadee.bpm.vPAV.beans; +import org.springframework.context.ApplicationContext; + import java.util.HashMap; import java.util.Map; -import org.springframework.context.ApplicationContext; - /** * Helper methods for Maven Plugin CamundaStaticValidator */ diff --git a/src/main/java/de/viadee/bpm/vPAV/config/reader/ConfigReader.java b/src/main/java/de/viadee/bpm/vPAV/config/reader/ConfigReader.java index 052ef7df..485338d9 100644 --- a/src/main/java/de/viadee/bpm/vPAV/config/reader/ConfigReader.java +++ b/src/main/java/de/viadee/bpm/vPAV/config/reader/ConfigReader.java @@ -1,41 +1,41 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.config.reader; - -import java.util.Map; - -import de.viadee.bpm.vPAV.config.model.Rule; - -public interface ConfigReader { - - Map read(final String file) throws ConfigReaderException; -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.config.reader; + +import de.viadee.bpm.vPAV.config.model.Rule; + +import java.util.Map; + +public interface ConfigReader { + + Map read(final String file) throws ConfigReaderException; +} diff --git a/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlConfigReader.java b/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlConfigReader.java index bfb19010..15cc3d06 100644 --- a/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlConfigReader.java +++ b/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlConfigReader.java @@ -1,179 +1,174 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.config.reader; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; - -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.ElementConvention; -import de.viadee.bpm.vPAV.config.model.ElementFieldTypes; -import de.viadee.bpm.vPAV.config.model.ModelConvention; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; - -/** - * Used to read the config file (ruleSet.xml) and extract the configured rules - * Requirements: Exisiting ruleSet.xml in src/test/resources - */ -public final class XmlConfigReader implements ConfigReader { - - /** - * @throws ConfigReaderException - * If file can not be found in classpath - */ - @Override - public Map read(final String file) throws ConfigReaderException { - - try { - final JAXBContext jaxbContext = JAXBContext.newInstance(XmlRuleSet.class); - final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - - InputStream fRuleSet = RuntimeConfig.getInstance().getClassLoader().getResourceAsStream(file); - - if (fRuleSet != null) { - final XmlRuleSet ruleSet = (XmlRuleSet) jaxbUnmarshaller.unmarshal(fRuleSet); - return transformFromXmlDatastructues(ruleSet); - } else { - throw new ConfigReaderException("ConfigFile could not be found"); - } - } catch (JAXBException e) { - throw new ConfigReaderException(e); - } - } - - /** - * Retrieves all rules, by default deactivated - * - * @return rules - */ - public Map getDeactivatedRuleSet() { - final Map rules = new HashMap(); - - for (String name : RuntimeConfig.getInstance().getViadeeRules()) { - if (name.equals("CreateOutputHTML")) { - rules.put(name, new Rule(name, true, null, new HashMap(), - new ArrayList(), new ArrayList())); - } else { - rules.put(name, new Rule(name, false, null, new HashMap(), - new ArrayList(), new ArrayList())); - } - } - - return rules; - } - - /** - * Transforms XmlRuleSet to rules - * - * @param ruleSet - * @return rules - * @throws ConfigReaderException - * If file could not be read properly - */ - private static Map transformFromXmlDatastructues(final XmlRuleSet ruleSet) - throws ConfigReaderException { - final Map rules = new HashMap(); - - final Collection xmlRules = ruleSet.getRules(); - for (final XmlRule rule : xmlRules) { - final String name = rule.getName(); - if (name == null) - throw new ConfigReaderException("rule name is not set"); - final boolean state = rule.isState(); - final String ruleDescription = rule.getDescription(); - final Collection xmlElementConventions = rule.getElementConventions(); - final ArrayList elementConventions = new ArrayList(); - if (xmlElementConventions != null) { - for (final XmlElementConvention xmlElementConvention : xmlElementConventions) { - final XmlElementFieldTypes xmlElementFieldTypes = xmlElementConvention.getElementFieldTypes(); - ElementFieldTypes elementFieldTypes = null; - if (xmlElementFieldTypes != null) { - elementFieldTypes = new ElementFieldTypes(xmlElementFieldTypes.getElementFieldTypes(), - xmlElementFieldTypes.isExcluded()); - } - if (!checkRegEx(xmlElementConvention.getPattern())) - throw new ConfigReaderException("RegEx (" + xmlElementConvention.getPattern() + ") of " + name - + " (" + xmlElementConvention.getName() + ") is incorrect"); - elementConventions.add(new ElementConvention(xmlElementConvention.getName(), elementFieldTypes, - xmlElementConvention.getDescription(), xmlElementConvention.getPattern())); - } - } - final Collection xmlModelConventions = rule.getModelConventions(); - final ArrayList modelConventions = new ArrayList(); - if (xmlModelConventions != null) { - for (final XmlModelConvention xmlModelConvention : xmlModelConventions) { - modelConventions.add(new ModelConvention(xmlModelConvention.getType())); - } - } - final Collection xmlSettings = rule.getSettings(); - final Map settings = new HashMap(); - if (xmlSettings != null) { - for (final XmlSetting xmlSetting : xmlSettings) { - if (!settings.containsKey(xmlSetting.getName())) { - settings.put(xmlSetting.getName(), - new Setting(xmlSetting.getName(), xmlSetting.getScript(), xmlSetting.getType(), - xmlSetting.getId(), xmlSetting.getRequired(), xmlSetting.getValue())); - } else { - settings.get(xmlSetting.getName()).addScriptPlace(xmlSetting.getScript()); - } - } - } - rules.put(name, new Rule(name, state, ruleDescription, settings, elementConventions, modelConventions)); - } - - return rules; - } - - private static boolean checkRegEx(String regEx) { - boolean correct = false; - - if (regEx.isEmpty()) - return correct; - - try { - Pattern.compile(regEx); - correct = true; - } catch (PatternSyntaxException e) { - } - return correct; - } -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.config.reader; + +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.*; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +/** + * Used to read the config file (ruleSet.xml) and extract the configured rules + * Requirements: Exisiting ruleSet.xml in src/test/resources + */ +public final class XmlConfigReader implements ConfigReader { + + /** + * @throws ConfigReaderException + * If file can not be found in classpath + */ + @Override + public Map read(final String file) throws ConfigReaderException { + + try { + final JAXBContext jaxbContext = JAXBContext.newInstance(XmlRuleSet.class); + final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); + + InputStream fRuleSet = RuntimeConfig.getInstance().getClassLoader().getResourceAsStream(file); + + if (fRuleSet != null) { + final XmlRuleSet ruleSet = (XmlRuleSet) jaxbUnmarshaller.unmarshal(fRuleSet); + return transformFromXmlDatastructues(ruleSet); + } else { + throw new ConfigReaderException("ConfigFile could not be found"); + } + } catch (JAXBException e) { + throw new ConfigReaderException(e); + } + } + + /** + * Retrieves all rules, by default deactivated + * + * @return rules + */ + public Map getDeactivatedRuleSet() { + final Map rules = new HashMap(); + + for (String name : RuntimeConfig.getInstance().getViadeeRules()) { + if (name.equals("CreateOutputHTML")) { + rules.put(name, new Rule(name, true, null, new HashMap(), + new ArrayList(), new ArrayList())); + } else { + rules.put(name, new Rule(name, false, null, new HashMap(), + new ArrayList(), new ArrayList())); + } + } + + return rules; + } + + /** + * Transforms XmlRuleSet to rules + * + * @param ruleSet + * @return rules + * @throws ConfigReaderException + * If file could not be read properly + */ + private static Map transformFromXmlDatastructues(final XmlRuleSet ruleSet) + throws ConfigReaderException { + final Map rules = new HashMap(); + + final Collection xmlRules = ruleSet.getRules(); + for (final XmlRule rule : xmlRules) { + final String name = rule.getName(); + if (name == null) + throw new ConfigReaderException("rule name is not set"); + final boolean state = rule.isState(); + final String ruleDescription = rule.getDescription(); + final Collection xmlElementConventions = rule.getElementConventions(); + final ArrayList elementConventions = new ArrayList(); + if (xmlElementConventions != null) { + for (final XmlElementConvention xmlElementConvention : xmlElementConventions) { + final XmlElementFieldTypes xmlElementFieldTypes = xmlElementConvention.getElementFieldTypes(); + ElementFieldTypes elementFieldTypes = null; + if (xmlElementFieldTypes != null) { + elementFieldTypes = new ElementFieldTypes(xmlElementFieldTypes.getElementFieldTypes(), + xmlElementFieldTypes.isExcluded()); + } + if (!checkRegEx(xmlElementConvention.getPattern())) + throw new ConfigReaderException("RegEx (" + xmlElementConvention.getPattern() + ") of " + name + + " (" + xmlElementConvention.getName() + ") is incorrect"); + elementConventions.add(new ElementConvention(xmlElementConvention.getName(), elementFieldTypes, + xmlElementConvention.getDescription(), xmlElementConvention.getPattern())); + } + } + final Collection xmlModelConventions = rule.getModelConventions(); + final ArrayList modelConventions = new ArrayList(); + if (xmlModelConventions != null) { + for (final XmlModelConvention xmlModelConvention : xmlModelConventions) { + modelConventions.add(new ModelConvention(xmlModelConvention.getType())); + } + } + final Collection xmlSettings = rule.getSettings(); + final Map settings = new HashMap(); + if (xmlSettings != null) { + for (final XmlSetting xmlSetting : xmlSettings) { + if (!settings.containsKey(xmlSetting.getName())) { + settings.put(xmlSetting.getName(), + new Setting(xmlSetting.getName(), xmlSetting.getScript(), xmlSetting.getType(), + xmlSetting.getId(), xmlSetting.getRequired(), xmlSetting.getValue())); + } else { + settings.get(xmlSetting.getName()).addScriptPlace(xmlSetting.getScript()); + } + } + } + rules.put(name, new Rule(name, state, ruleDescription, settings, elementConventions, modelConventions)); + } + + return rules; + } + + private static boolean checkRegEx(String regEx) { + boolean correct = false; + + if (regEx.isEmpty()) + return correct; + + try { + Pattern.compile(regEx); + correct = true; + } catch (PatternSyntaxException e) { + } + return correct; + } +} diff --git a/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlElementFieldTypes.java b/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlElementFieldTypes.java index 8171c7a3..e580beb7 100644 --- a/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlElementFieldTypes.java +++ b/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlElementFieldTypes.java @@ -31,12 +31,11 @@ */ package de.viadee.bpm.vPAV.config.reader; -import java.util.Collection; - import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Collection; @XmlRootElement(name = "elementFieldTypes") @XmlType(propOrder = { "elementFieldTypes", "excluded" }) diff --git a/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlRule.java b/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlRule.java index 124c3016..92f4db8f 100644 --- a/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlRule.java +++ b/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlRule.java @@ -31,12 +31,11 @@ */ package de.viadee.bpm.vPAV.config.reader; -import java.util.Collection; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.Collection; @XmlRootElement(name = "rule") @XmlType(propOrder = { "name", "state", "description", "settings", "elementConventions", "modelConventions" }) diff --git a/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlRuleSet.java b/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlRuleSet.java index 7e1abf0e..5afa0ed3 100644 --- a/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlRuleSet.java +++ b/src/main/java/de/viadee/bpm/vPAV/config/reader/XmlRuleSet.java @@ -31,10 +31,9 @@ */ package de.viadee.bpm.vPAV.config.reader; -import java.util.Collection; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Collection; @XmlRootElement(name = "ruleSet") public class XmlRuleSet { diff --git a/src/main/java/de/viadee/bpm/vPAV/constants/CamundaMethodServices.java b/src/main/java/de/viadee/bpm/vPAV/constants/CamundaMethodServices.java index 8c0a3138..07256022 100644 --- a/src/main/java/de/viadee/bpm/vPAV/constants/CamundaMethodServices.java +++ b/src/main/java/de/viadee/bpm/vPAV/constants/CamundaMethodServices.java @@ -42,5 +42,17 @@ public class CamundaMethodServices { public static final String SCOPE = "org.camunda.bpm.engine.delegate.VariableScope"; public static final String VARIABLE_MAP = "org.camunda.bpm.engine.variable.VariableMap"; + + public static final String START_PROCESS_INSTANCE_BY_MESSAGE = "startProcessInstanceByMessage"; + + public static final String START_PROCESS_INSTANCE_BY_ID = "startProcessInstanceById"; + + public static final String START_PROCESS_INSTANCE_BY_MESSAGE_AND_PROCESS_DEF = "startProcessInstanceByMessageAndProcessDefinitionId"; + + public static final String START_PROCESS_INSTANCE_BY_KEY = "startProcessInstanceByKey"; + + public static final String CORRELATE_MESSAGE = "createMessageCorrelation"; + + } diff --git a/src/main/java/de/viadee/bpm/vPAV/output/IssueOutputWriter.java b/src/main/java/de/viadee/bpm/vPAV/output/IssueOutputWriter.java index d5f67a5b..37825e15 100644 --- a/src/main/java/de/viadee/bpm/vPAV/output/IssueOutputWriter.java +++ b/src/main/java/de/viadee/bpm/vPAV/output/IssueOutputWriter.java @@ -31,10 +31,10 @@ */ package de.viadee.bpm.vPAV.output; -import java.util.Collection; - import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import java.util.Collection; + public interface IssueOutputWriter { void write(final Collection issues) throws OutputWriterException; diff --git a/src/main/java/de/viadee/bpm/vPAV/output/IssueWriter.java b/src/main/java/de/viadee/bpm/vPAV/output/IssueWriter.java index 36dc6638..417827ae 100644 --- a/src/main/java/de/viadee/bpm/vPAV/output/IssueWriter.java +++ b/src/main/java/de/viadee/bpm/vPAV/output/IssueWriter.java @@ -31,20 +31,18 @@ */ package de.viadee.bpm.vPAV.output; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map.Entry; - +import de.viadee.bpm.vPAV.config.model.ElementConvention; +import de.viadee.bpm.vPAV.config.model.Rule; import de.viadee.bpm.vPAV.processing.model.data.*; +import de.viadee.bpm.vPAV.processing.model.graph.Path; import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; import org.camunda.bpm.model.bpmn.instance.BaseElement; import org.w3c.dom.Element; -import de.viadee.bpm.vPAV.config.model.ElementConvention; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; -import de.viadee.bpm.vPAV.processing.model.graph.Path; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map.Entry; public class IssueWriter { diff --git a/src/main/java/de/viadee/bpm/vPAV/output/JsOutputWriter.java b/src/main/java/de/viadee/bpm/vPAV/output/JsOutputWriter.java index 176588a1..05e41a17 100644 --- a/src/main/java/de/viadee/bpm/vPAV/output/JsOutputWriter.java +++ b/src/main/java/de/viadee/bpm/vPAV/output/JsOutputWriter.java @@ -31,36 +31,23 @@ */ package de.viadee.bpm.vPAV.output; -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.Function; -import java.util.logging.Logger; - -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariable; -import de.viadee.bpm.vPAV.processing.model.data.*; - import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; - import de.viadee.bpm.vPAV.RuntimeConfig; import de.viadee.bpm.vPAV.constants.BpmnConstants; import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.model.data.*; import de.viadee.bpm.vPAV.processing.model.graph.Path; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.*; +import java.util.function.Function; +import java.util.logging.Logger; + /** * Create the JavaScript file for HTML-output; Needs: issues and bpmnFile names */ diff --git a/src/main/java/de/viadee/bpm/vPAV/output/JsonOutputWriter.java b/src/main/java/de/viadee/bpm/vPAV/output/JsonOutputWriter.java index d5232f19..c7b526e3 100644 --- a/src/main/java/de/viadee/bpm/vPAV/output/JsonOutputWriter.java +++ b/src/main/java/de/viadee/bpm/vPAV/output/JsonOutputWriter.java @@ -31,23 +31,22 @@ */ package de.viadee.bpm.vPAV.output; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.List; - import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; - import de.viadee.bpm.vPAV.constants.BpmnConstants; import de.viadee.bpm.vPAV.constants.ConfigConstants; import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.graph.Path; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.List; + public class JsonOutputWriter implements IssueOutputWriter { /** diff --git a/src/main/java/de/viadee/bpm/vPAV/output/RuleSetOutputWriter.java b/src/main/java/de/viadee/bpm/vPAV/output/RuleSetOutputWriter.java index 6604a75a..e233562d 100644 --- a/src/main/java/de/viadee/bpm/vPAV/output/RuleSetOutputWriter.java +++ b/src/main/java/de/viadee/bpm/vPAV/output/RuleSetOutputWriter.java @@ -31,35 +31,20 @@ */ package de.viadee.bpm.vPAV.output; -import java.io.BufferedWriter; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; +import de.viadee.bpm.vPAV.config.model.*; +import de.viadee.bpm.vPAV.config.reader.*; +import de.viadee.bpm.vPAV.constants.ConfigConstants; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import java.io.*; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Map; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; - -import de.viadee.bpm.vPAV.config.model.ElementConvention; -import de.viadee.bpm.vPAV.config.model.ElementFieldTypes; -import de.viadee.bpm.vPAV.config.model.ModelConvention; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.config.reader.XmlElementConvention; -import de.viadee.bpm.vPAV.config.reader.XmlElementFieldTypes; -import de.viadee.bpm.vPAV.config.reader.XmlModelConvention; -import de.viadee.bpm.vPAV.config.reader.XmlRule; -import de.viadee.bpm.vPAV.config.reader.XmlRuleSet; -import de.viadee.bpm.vPAV.config.reader.XmlSetting; -import de.viadee.bpm.vPAV.constants.ConfigConstants; - /** * Ergebnisse aus dem Checker in ein definiertes XML-Format schreiben * diff --git a/src/main/java/de/viadee/bpm/vPAV/output/XmlCheckerIssue.java b/src/main/java/de/viadee/bpm/vPAV/output/XmlCheckerIssue.java index 82f877fe..ab31fdba 100644 --- a/src/main/java/de/viadee/bpm/vPAV/output/XmlCheckerIssue.java +++ b/src/main/java/de/viadee/bpm/vPAV/output/XmlCheckerIssue.java @@ -31,12 +31,11 @@ */ package de.viadee.bpm.vPAV.output; -import java.util.List; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; +import java.util.List; @XmlRootElement(name = "issue") @XmlType(propOrder = { "id", "ruleName", "ruleDescription", "bpmnFile", "resourceFile", "classification", "elementId", diff --git a/src/main/java/de/viadee/bpm/vPAV/output/XmlCheckerIssues.java b/src/main/java/de/viadee/bpm/vPAV/output/XmlCheckerIssues.java index 9d7d3b86..b4475b37 100644 --- a/src/main/java/de/viadee/bpm/vPAV/output/XmlCheckerIssues.java +++ b/src/main/java/de/viadee/bpm/vPAV/output/XmlCheckerIssues.java @@ -31,13 +31,12 @@ */ package de.viadee.bpm.vPAV.output; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - @XmlRootElement(name = "issues") public class XmlCheckerIssues { diff --git a/src/main/java/de/viadee/bpm/vPAV/output/XmlOutputWriter.java b/src/main/java/de/viadee/bpm/vPAV/output/XmlOutputWriter.java index 5d609c23..de36a2f4 100644 --- a/src/main/java/de/viadee/bpm/vPAV/output/XmlOutputWriter.java +++ b/src/main/java/de/viadee/bpm/vPAV/output/XmlOutputWriter.java @@ -31,26 +31,20 @@ */ package de.viadee.bpm.vPAV.output; -import java.io.BufferedWriter; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; - import de.viadee.bpm.vPAV.constants.BpmnConstants; import de.viadee.bpm.vPAV.constants.ConfigConstants; import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.graph.Path; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import java.io.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + /** * Ergebnisse aus dem Checker in ein definiertes XML-Format schreiben * diff --git a/src/main/java/de/viadee/bpm/vPAV/output/XmlPath.java b/src/main/java/de/viadee/bpm/vPAV/output/XmlPath.java index 5ab54de2..62a84ca4 100644 --- a/src/main/java/de/viadee/bpm/vPAV/output/XmlPath.java +++ b/src/main/java/de/viadee/bpm/vPAV/output/XmlPath.java @@ -31,10 +31,9 @@ */ package de.viadee.bpm.vPAV.output; -import java.util.Collection; - import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Collection; @XmlRootElement(name = "path") public class XmlPath { diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/BpmnModelDispatcher.java b/src/main/java/de/viadee/bpm/vPAV/processing/BpmnModelDispatcher.java index a5b2ded8..d9a68fe1 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/BpmnModelDispatcher.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/BpmnModelDispatcher.java @@ -31,43 +31,26 @@ */ package de.viadee.bpm.vPAV.processing; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.xml.sax.SAXException; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.FileScanner; import de.viadee.bpm.vPAV.config.model.Rule; import de.viadee.bpm.vPAV.config.model.Setting; import de.viadee.bpm.vPAV.constants.BpmnConstants; import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.checker.CheckerFactory; -import de.viadee.bpm.vPAV.processing.checker.DataFlowChecker; -import de.viadee.bpm.vPAV.processing.checker.ElementChecker; -import de.viadee.bpm.vPAV.processing.checker.ModelChecker; -import de.viadee.bpm.vPAV.processing.checker.ProcessVariablesModelChecker; +import de.viadee.bpm.vPAV.processing.checker.*; import de.viadee.bpm.vPAV.processing.dataflow.DataFlowRule; -import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; -import de.viadee.bpm.vPAV.processing.model.data.ModelDispatchResult; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariable; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import de.viadee.bpm.vPAV.processing.model.data.*; import de.viadee.bpm.vPAV.processing.model.graph.IGraph; import de.viadee.bpm.vPAV.processing.model.graph.Path; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.util.*; /** * Calls model and element checkers for a concrete bpmn processdefinition @@ -102,7 +85,7 @@ public class BpmnModelDispatcher { */ public ModelDispatchResult dispatchWithVariables(final FileScanner fileScanner, final File processdefinition, final Map decisionRefToPathMap, final Map processIdToPathMap, - final OuterProcessVariablesScanner scanner, final Collection dataFlowRules, + final ProcessVariablesScanner scanner, final Collection dataFlowRules, final Collection resourcesNewestVersions, final Map conf) { final BpmnScanner bpmnScanner = createScanner(processdefinition); diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/CheckName.java b/src/main/java/de/viadee/bpm/vPAV/processing/CheckName.java index 8ed2ffbb..d29eaa71 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/CheckName.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/CheckName.java @@ -31,11 +31,10 @@ */ package de.viadee.bpm.vPAV.processing; +import de.viadee.bpm.vPAV.constants.BpmnConstants; import org.camunda.bpm.model.bpmn.instance.BaseElement; import org.w3c.dom.Element; -import de.viadee.bpm.vPAV.constants.BpmnConstants; - /** * * Utility class to check names and return names/ids diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/ElementGraphBuilder.java b/src/main/java/de/viadee/bpm/vPAV/processing/ElementGraphBuilder.java index cd556bb0..fe347a2b 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/ElementGraphBuilder.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/ElementGraphBuilder.java @@ -33,16 +33,16 @@ import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; import de.viadee.bpm.vPAV.constants.BpmnConstants; -import de.viadee.bpm.vPAV.processing.model.data.*; +import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; import de.viadee.bpm.vPAV.processing.model.graph.Edge; import de.viadee.bpm.vPAV.processing.model.graph.Graph; import de.viadee.bpm.vPAV.processing.model.graph.IGraph; import de.viadee.bpm.vPAV.processing.model.graph.Path; import org.camunda.bpm.model.bpmn.Bpmn; import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; import org.camunda.bpm.model.bpmn.instance.*; import org.camunda.bpm.model.bpmn.instance.Process; import org.camunda.bpm.model.bpmn.instance.camunda.CamundaIn; @@ -109,7 +109,7 @@ public ElementGraphBuilder(final Map decisionRefToPathMap, */ public Collection createProcessGraph(final JavaReaderContext context, final FileScanner fileScanner, final BpmnModelInstance modelInstance, final String processdefinition, - final Collection calledElementHierarchy, final OuterProcessVariablesScanner scanner) { + final Collection calledElementHierarchy, final ProcessVariablesScanner scanner) { final Collection graphCollection = new ArrayList(); @@ -141,33 +141,35 @@ public Collection createProcessGraph(final JavaReaderContext context, fi processdefinition); } + // Ordered map to hold operations in correct order + final LinkedHashMap variables = new LinkedHashMap<>(); + // initialize element final BpmnElement node = new BpmnElement(processdefinition, element); + + // retrieve initial variable operation (should be WRITE) + if (element.getElementType().getTypeName().equals(BpmnConstants.STARTEVENT)) { + // add process variables for start event, which set by call + // startProcessInstanceByKey + for (Map.Entry> entry : scanner.getEntryPoints().entrySet()) { + for (Map.Entry innerEntry : entry.getValue().entrySet()) { + variables.putAll(checkInitialVariableOperations(innerEntry.getValue(), context, scanner, node, processdefinition, variables, entry)); + } + } + + node.setProcessVariables(variables); + graph.addStartNode(node); + } + // examine process variables and save it with access operation - final LinkedHashMap variables = new ProcessVariableReader( - decisionRefToPathMap, bpmnScanner).getVariablesFromElement(context, fileScanner, node); + final ProcessVariableReader reader = new ProcessVariableReader(decisionRefToPathMap, bpmnScanner); + variables.putAll(reader.getVariablesFromElement(context, fileScanner, node, variables)); // examine process variables for element and set it node.setProcessVariables(variables); // mention element elementMap.put(element.getId(), node); - if (element.getElementType().getBaseType().getBaseType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_EVENT)) { - // add variables for message event (set by outer class) - addProcessVariablesForMessageName(element, node, context, scanner, processdefinition); - } - if (element.getElementType().getTypeName().equals(BpmnConstants.STARTEVENT)) { - // add process variables for start event, which set by call - // startProcessInstanceByKey - checkInitialVariableOperations(context, scanner, node, processdefinition); - - final String processId = node.getBaseElement().getParentElement() - .getAttributeValue(BpmnConstants.ATTR_ID); - addProcessVariablesByStartForProcessId(node, processId); - - graph.addStartNode(node); - } if (element.getElementType().getTypeName().equals(BpmnConstants.ENDEVENT)) { graph.addEndNode(node); } @@ -197,76 +199,12 @@ public Collection createProcessGraph(final JavaReaderContext context, fi * @param scanner * OuterProcessVariableScanner */ - private void checkInitialVariableOperations(final JavaReaderContext jvc, final OuterProcessVariablesScanner scanner, - final BpmnElement element, final String resourceFilePath) { - for (final String clazz : scanner.getInitialProcessVariablesLocation()) { - jvc.readClass(clazz, scanner, element, resourceFilePath); - } - } - - /** - * Add process variables on start event for a specific process id - * - * @param node - * Current BPMN Element - * @param processId - * Current Process ID - */ - private void addProcessVariablesByStartForProcessId(final BpmnElement node, final String processId) { - if (processIdToVariables != null && processId != null) { - final Collection outerVariables = processIdToVariables.get(processId); - // add variables - if (outerVariables != null) { - for (final String varName : outerVariables) { - node.setProcessVariable(varName, - new ProcessVariableOperation(varName, node, ElementChapter.OutstandingVariable, - KnownElementFieldType.Class, null, VariableOperation.WRITE, "")); - } - } - } + private LinkedHashMap checkInitialVariableOperations(final String clazz, final JavaReaderContext jvc, final ProcessVariablesScanner scanner, + final BpmnElement element, final String resourceFilePath, final LinkedHashMap variables, final Map.Entry> entry) { + variables.putAll(jvc.readClass(clazz, scanner, element, resourceFilePath, entry)); + return variables; } - /** - * Add process variables on event for a specific message name - * - * @param element - * FlowElement - * @param node - * BpmnElement - */ - private void addProcessVariablesForMessageName(final FlowElement element, final BpmnElement node, - final JavaReaderContext jvc, final OuterProcessVariablesScanner scanner, final String resourceFilePath) { - if (messageIdToVariables != null) { - if (element instanceof Event) { - final Event event = (Event) element; - final Collection messageEventDefinitions = event - .getChildElementsByType(MessageEventDefinition.class); - if (messageEventDefinitions != null) { - for (MessageEventDefinition eventDef : messageEventDefinitions) { - if (eventDef != null) { - final Message message = eventDef.getMessage(); - if (message != null) { - final String messageName = message.getName(); - final Collection outerVariables = messageIdToVariables.get(messageName); - if (outerVariables != null) { - for (final String varName : outerVariables) { - // Check which outerVariables have been written - - checkInitialVariableOperations(jvc, scanner, node, resourceFilePath); - - node.setProcessVariable(varName, - new ProcessVariableOperation(varName, node, - ElementChapter.OutstandingVariable, KnownElementFieldType.Class, - null, VariableOperation.WRITE, "")); - } - } - } - } - } - } - } - } - } public BpmnElement getElement(final String id) { return elementMap.get(id); @@ -402,8 +340,9 @@ private void addElementsSubprocess(final JavaReaderContext context, final FileSc // add elements of the sub process as nodes final BpmnElement node = new BpmnElement(processdefinitionPath, subElement); // determine process variables with operations - final LinkedHashMap variables = new ProcessVariableReader( - decisionRefToPathMap, bpmnScanner).getVariablesFromElement(context, fileScanner, node); + final LinkedHashMap variables = new LinkedHashMap<>(); + variables.putAll( + new ProcessVariableReader(decisionRefToPathMap, bpmnScanner).getVariablesFromElement(context, fileScanner, node, variables)); // set process variables for the node node.setProcessVariables(variables); // mention the element @@ -436,7 +375,7 @@ private void addElementsSubprocess(final JavaReaderContext context, final FileSc private void integrateCallActivityFlow(final JavaReaderContext context, final FileScanner fileScanner, final String processdefinition, final BpmnModelInstance modelInstance, final CallActivity callActivity, final IGraph graph, final Collection calledElementHierarchy, - final OuterProcessVariablesScanner scanner) { + final ProcessVariablesScanner scanner) { final String calledElement = callActivity.getCalledElement(); @@ -592,7 +531,7 @@ private void connectParallelGatewaysWithSubDataFlow(final IGraph graph, final Co */ private Collection createSubDataFlowsFromCallActivity(final JavaReaderContext context, FileScanner fileScanner, final Collection calledElementHierarchy, final String callActivityPath, - final OuterProcessVariablesScanner scanner) { + final ProcessVariablesScanner scanner) { // read called process final BpmnModelInstance submodel = Bpmn.readModelFromFile(new File(callActivityPath)); diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/JavaReader.java b/src/main/java/de/viadee/bpm/vPAV/processing/JavaReader.java index 4e4c7da2..39701327 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/JavaReader.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/JavaReader.java @@ -31,21 +31,22 @@ */ package de.viadee.bpm.vPAV.processing; -import java.util.*; - import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.ElementChapter; import de.viadee.bpm.vPAV.processing.model.data.KnownElementFieldType; import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import java.util.LinkedHashMap; +import java.util.Map; + public interface JavaReader { - LinkedHashMap getVariablesFromJavaDelegate(final FileScanner fileScanner, final String classFile, - final BpmnElement element, final ElementChapter chapter, final KnownElementFieldType fieldType, - final String scopeId); + LinkedHashMap getVariablesFromJavaDelegate(final FileScanner fileScanner, + final String classFile, final BpmnElement element, final ElementChapter chapter, + final KnownElementFieldType fieldType, final String scopeId); - LinkedHashMap getVariablesFromClass(final String className, final OuterProcessVariablesScanner scanner, - final BpmnElement element, final String resourceFilePath); + LinkedHashMap getVariablesFromClass(final String className, + final ProcessVariablesScanner scanner, final BpmnElement element, final String resourceFilePath, + final Map.Entry> entry); } diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderContext.java b/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderContext.java index 5330bbaa..055f9802 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderContext.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderContext.java @@ -31,14 +31,15 @@ */ package de.viadee.bpm.vPAV.processing; -import java.util.*; import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.ElementChapter; import de.viadee.bpm.vPAV.processing.model.data.KnownElementFieldType; import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import java.util.LinkedHashMap; +import java.util.Map; + public class JavaReaderContext { private JavaReader javaReaderStrategy; @@ -52,8 +53,8 @@ public LinkedHashMap readJavaDelegate(final Fi return javaReaderStrategy.getVariablesFromJavaDelegate(fileScanner, classFile, element, chapter, fieldType, scopeId); } - public LinkedHashMap readClass(final String className, final OuterProcessVariablesScanner scanner, final BpmnElement element, final String resourceFilePath){ - return javaReaderStrategy.getVariablesFromClass(className, scanner, element, resourceFilePath); + public LinkedHashMap readClass(final String className, final ProcessVariablesScanner scanner, final BpmnElement element, final String resourceFilePath, final Map.Entry> entry){ + return javaReaderStrategy.getVariablesFromClass(className, scanner, element, resourceFilePath, entry); } diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderRegex.java b/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderRegex.java index a430703a..fc8110de 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderRegex.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderRegex.java @@ -31,16 +31,16 @@ */ package de.viadee.bpm.vPAV.processing; -import java.util.LinkedHashMap; -import java.util.logging.Logger; - import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.ElementChapter; import de.viadee.bpm.vPAV.processing.model.data.KnownElementFieldType; import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.logging.Logger; + public class JavaReaderRegex implements JavaReader { public static final Logger LOGGER = Logger.getLogger(JavaReaderRegex.class.getName()); @@ -81,23 +81,12 @@ public LinkedHashMap getVariablesFromJavaDeleg } /** - * * Unused implementation - * - * @param className - * Class name to be scanned - * @param scanner - * OuterProcessVariableScanner - * @param element - * BpmnElement - * @param resourceFilePath - * Path of the BPMN model - * - * @return Process Variables */ @Override public LinkedHashMap getVariablesFromClass(final String className, - final OuterProcessVariablesScanner scanner, final BpmnElement element, final String resourceFilePath) { + final ProcessVariablesScanner scanner, final BpmnElement element, final String resourceFilePath, + final Map.Entry> entry) { // TODO Auto-generated method stub return null; } diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderStatic.java b/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderStatic.java index 41fd9290..617aef29 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderStatic.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/JavaReaderStatic.java @@ -31,37 +31,15 @@ */ package de.viadee.bpm.vPAV.processing; -import java.util.*; -import java.util.logging.Logger; - import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; -import de.viadee.bpm.vPAV.processing.model.data.Anomaly; -import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CamundaProcessVariableFunctions; -import de.viadee.bpm.vPAV.processing.model.data.ElementChapter; -import de.viadee.bpm.vPAV.processing.model.data.KnownElementFieldType; -import de.viadee.bpm.vPAV.processing.model.data.OutSetCFG; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; -import de.viadee.bpm.vPAV.processing.model.data.VariableBlock; -import de.viadee.bpm.vPAV.processing.model.data.VariableOperation; -import soot.Body; -import soot.G; -import soot.PackManager; -import soot.PatchingChain; -import soot.RefType; -import soot.Scene; -import soot.SootClass; -import soot.SootMethod; -import soot.Type; -import soot.Unit; -import soot.VoidType; +import de.viadee.bpm.vPAV.constants.CamundaMethodServices; +import de.viadee.bpm.vPAV.processing.model.data.*; +import org.camunda.bpm.engine.variable.VariableMap; +import soot.*; import soot.jimple.AssignStmt; import soot.jimple.InvokeStmt; import soot.jimple.StringConstant; import soot.jimple.internal.JInterfaceInvokeExpr; -import soot.jimple.internal.JVirtualInvokeExpr; import soot.jimple.toolkits.callgraph.CallGraph; import soot.jimple.toolkits.callgraph.Edge; import soot.options.Options; @@ -69,6 +47,9 @@ import soot.toolkits.graph.BlockGraph; import soot.toolkits.graph.ClassicCompleteBlockGraph; +import java.util.*; +import java.util.logging.Logger; + public class JavaReaderStatic implements JavaReader { public static final Logger LOGGER = Logger.getLogger(JavaReaderStatic.class.getName()); @@ -137,7 +118,8 @@ public LinkedHashMap getVariablesFromJavaDeleg * @return Map of process variable operations */ public LinkedHashMap getVariablesFromClass(String className, - final OuterProcessVariablesScanner scanner, final BpmnElement element, final String resourceFilePath) { + final ProcessVariablesScanner scanner, final BpmnElement element, final String resourceFilePath, + final Map.Entry> map) { final LinkedHashMap initialOperations = new LinkedHashMap<>(); @@ -156,12 +138,15 @@ public LinkedHashMap getVariablesFromClass(Str sootClass.setApplicationClass(); Scene.v().loadNecessaryClasses(); for (SootMethod method : sootClass.getMethods()) { - final Body body = method.retrieveActiveBody(); - initialOperations.putAll(checkWriteAccess(body, scanner, element, resourceFilePath)); + for (Map.Entry entry : map.getValue().entrySet()) { + if (method.getName().equals(entry.getKey())) { + final Body body = method.retrieveActiveBody(); + initialOperations.putAll(checkWriteAccess(body, element, resourceFilePath, map)); + } + } } } } - return initialOperations; } @@ -171,71 +156,89 @@ public LinkedHashMap getVariablesFromClass(Str * * @param body * Soot representation of a method's body - * @param scanner - * OuterProcessVariableScanner * @param element * BpmnElement * @param resourceFilePath * Path of the BPMN model * @return Map of process variable operations */ - private Map checkWriteAccess(final Body body, - final OuterProcessVariablesScanner scanner, final BpmnElement element, final String resourceFilePath) { - - final Map initialOperations = new HashMap<>(); - - for (String location : scanner.getInitialProcessVariablesLocation()) { - location = cleanString(location, true); - location = "new " + location.replace(".java", "") + "$InitialProcessVariables"; - - String assignment = ""; - String invoke = ""; - - final PatchingChain pc = body.getUnits(); - for (Unit unit : pc) { - if (unit instanceof AssignStmt) { - final String rightBox = ((AssignStmt) unit).getRightOpBox().getValue().toString(); - final String leftBox = ((AssignStmt) unit).getLeftOpBox().getValue().toString(); + private Map checkWriteAccess(final Body body, final BpmnElement element, + final String resourceFilePath, final Map.Entry> map) { - if (rightBox.equals(location)) { - assignment = leftBox; - } - - if (rightBox.equals(assignment)) { - invoke = leftBox; - } + final LinkedHashMap initialOperations = new LinkedHashMap<>(); - if (leftBox.contains(location.replace("new ", "")) && leftBox.contains(invoke)) { - if (scanner.getInitialProcessVariables() - .contains(((AssignStmt) unit).getFieldRef().getFieldRef().name())) { - final String name = ((AssignStmt) unit).getFieldRef().getFieldRef().name(); - initialOperations.put(name, - new ProcessVariableOperation(name, element, ElementChapter.Code, - KnownElementFieldType.Initial, resourceFilePath, VariableOperation.WRITE, - element.getBaseElement().getId())); + for (Map.Entry entry : map.getValue().entrySet()) { + if (body.getMethod().getName().equals(entry.getKey())) { + final PatchingChain pc = body.getUnits(); + String assignment = ""; + String invoke = ""; + + for (Unit unit : pc) { + if (unit instanceof AssignStmt) { + final String rightBox = ((AssignStmt) unit).getRightOpBox().getValue().toString(); + final String leftBox = ((AssignStmt) unit).getLeftOpBox().getValue().toString(); + + if (rightBox.contains(CamundaMethodServices.VARIABLE_MAP + " createVariables()")) { + assignment = leftBox; + } + + if (rightBox.contains(map.getKey()) && rightBox.contains(invoke)) { + return initialOperations; + } + + if (((AssignStmt) unit).getRightOpBox().getValue() instanceof JInterfaceInvokeExpr) { + final JInterfaceInvokeExpr expr = (JInterfaceInvokeExpr) ((AssignStmt) unit) + .getRightOpBox().getValue(); + if (expr != null) { + if (expr.getMethodRef().getDeclaringClass().equals(Scene.v() + .forceResolve(VariableMap.class.getName(), SootClass.SIGNATURES))) { + initialOperations.putAll(parseInitialExpression(expr, element, resourceFilePath)); + invoke = leftBox; + } + if (checkArgBoxes(map, assignment, invoke, expr)) return initialOperations; + } } - } - - if (((AssignStmt) unit).getRightOpBox().getValue() instanceof JVirtualInvokeExpr) { - - final JVirtualInvokeExpr expr = (JVirtualInvokeExpr) ((AssignStmt) unit).getRightOpBox() - .getValue(); - - if (expr != null) { - String functionName = expr.getMethodRef().name(); - if (functionName.equals("createVariableMap")) { - return initialOperations; - } + } + if (unit instanceof InvokeStmt) { + if (((InvokeStmt) unit).getInvokeExprBox().getValue() instanceof JInterfaceInvokeExpr) { + final JInterfaceInvokeExpr expr = (JInterfaceInvokeExpr) ((InvokeStmt) unit) + .getInvokeExprBox().getValue(); + if (expr != null) { + if (checkArgBoxes(map, assignment, invoke, expr)) return initialOperations; + } } } } } - } - + } return initialOperations; } - /** + /** + * + * Check whether or not the second or third argument contain a reference to the variable map + * + * @param map Current entry + * @param assignment Current assigned variable + * @param invoke Current invocation + * @param expr Current expression + * @return True/False based on whether the second or third argument refers to the variable map + */ + private boolean checkArgBoxes(Map.Entry> map, String assignment, String invoke, JInterfaceInvokeExpr expr) { + if (expr.getMethodRef().getName().equals(map.getKey())) { + if (!assignment.isEmpty()) { + if (expr.getArgBox(1).getValue().toString().equals(invoke)) { + return true; + } + if (expr.getArgBox(2).getValue().toString().equals(invoke)) { + return true; + } + } + } + return false; + } + + /** * * Starting by the main JavaDelegate, statically analyses the classes * implemented for the bpmn element. @@ -267,7 +270,7 @@ public Map classFetcher(final Set clas OutSetCFG outSet = new OutSetCFG(new ArrayList()); classFetcherRecursive(classPaths, className, methodName, classFile, element, chapter, fieldType, scopeId, - outSet, null, new ArrayList()); + outSet, null); processVariables.putAll(outSet.getAllProcessVariables()); @@ -305,75 +308,69 @@ public Map classFetcher(final Set clas * Callgraph information * @param originalBlock * VariableBlock - * @param visitedClasses - * List to hold information which class has been visited (avoid - * circular references that lead to a StackOverflow) * @return OutSetCFG which contains data flow information */ public OutSetCFG classFetcherRecursive(final Set classPaths, String className, final String methodName, final String classFile, final BpmnElement element, final ElementChapter chapter, final KnownElementFieldType fieldType, final String scopeId, OutSetCFG outSet, - final VariableBlock originalBlock, final ArrayList visitedClasses) { - - if (!visitedClasses.contains(className)) { - className = cleanString(className, true); - - Options.v().set_whole_program(true); - Options.v().set_allow_phantom_refs(true); - - SootClass sootClass = Scene.v().forceResolve(className, SootClass.SIGNATURES); - - if (sootClass != null) { - - sootClass.setApplicationClass(); - Scene.v().loadNecessaryClasses(); - - // Retrieve the method and its body based on the used interface - List parameterTypes = new ArrayList(); - RefType delegateExecutionType = RefType.v("org.camunda.bpm.engine.delegate.DelegateExecution"); - RefType delegateTaskType = RefType.v("org.camunda.bpm.engine.delegate.DelegateTask"); - RefType mapVariablesType = RefType.v("org.camunda.bpm.engine.variable.VariableMap"); - VoidType returnType = VoidType.v(); - - switch (methodName) { - case "execute": - parameterTypes.add((Type) delegateExecutionType); - outSet = retrieveMethod(classPaths, className, methodName, classFile, element, chapter, fieldType, - scopeId, outSet, originalBlock, sootClass, parameterTypes, returnType, visitedClasses); - break; - case "notify": - for (SootClass clazz : sootClass.getInterfaces()) { - if (clazz.getName().equals("org.camunda.bpm.engine.delegate.TaskListener")) { - parameterTypes.add((Type) delegateTaskType); - } else if (clazz.getName().equals("org.camunda.bpm.engine.delegate.ExecutionListener")) { - parameterTypes.add((Type) delegateExecutionType); - } + final VariableBlock originalBlock) { + + className = cleanString(className, true); + + Options.v().set_whole_program(true); + Options.v().set_allow_phantom_refs(true); + + SootClass sootClass = Scene.v().forceResolve(className, SootClass.SIGNATURES); + + if (sootClass != null) { + + sootClass.setApplicationClass(); + Scene.v().loadNecessaryClasses(); + + // Retrieve the method and its body based on the used interface + List parameterTypes = new ArrayList(); + RefType delegateExecutionType = RefType.v("org.camunda.bpm.engine.delegate.DelegateExecution"); + RefType delegateTaskType = RefType.v("org.camunda.bpm.engine.delegate.DelegateTask"); + RefType mapVariablesType = RefType.v("org.camunda.bpm.engine.variable.VariableMap"); + VoidType returnType = VoidType.v(); + + switch (methodName) { + case "execute": + parameterTypes.add((Type) delegateExecutionType); + outSet = retrieveMethod(classPaths, className, methodName, classFile, element, chapter, fieldType, + scopeId, outSet, originalBlock, sootClass, parameterTypes, returnType); + break; + case "notify": + for (SootClass clazz : sootClass.getInterfaces()) { + if (clazz.getName().equals("org.camunda.bpm.engine.delegate.TaskListener")) { + parameterTypes.add((Type) delegateTaskType); + } else if (clazz.getName().equals("org.camunda.bpm.engine.delegate.ExecutionListener")) { + parameterTypes.add((Type) delegateExecutionType); } - outSet = retrieveMethod(classPaths, className, methodName, classFile, element, chapter, fieldType, - scopeId, outSet, originalBlock, sootClass, parameterTypes, returnType, visitedClasses); - break; - case "mapInputVariables": - parameterTypes.add((Type) delegateExecutionType); - parameterTypes.add((Type) mapVariablesType); - outSet = retrieveMethod(classPaths, className, methodName, classFile, element, chapter, fieldType, - scopeId, outSet, originalBlock, sootClass, parameterTypes, returnType, visitedClasses); - break; - case "mapOutputVariables": - parameterTypes.add((Type) delegateExecutionType); - parameterTypes.add((Type) mapVariablesType); - outSet = retrieveMethod(classPaths, className, methodName, classFile, element, chapter, fieldType, - scopeId, outSet, originalBlock, sootClass, parameterTypes, returnType, visitedClasses); - break; - default: - visitedClasses.add(className); - outSet = retrieveCustomMethod(sootClass, classPaths, className, methodName, classFile, element, - chapter, fieldType, scopeId, outSet, originalBlock, visitedClasses); - break; } - - } else { - LOGGER.warning("Class " + classFile + " was not found by Soot"); + outSet = retrieveMethod(classPaths, className, methodName, classFile, element, chapter, fieldType, + scopeId, outSet, originalBlock, sootClass, parameterTypes, returnType); + break; + case "mapInputVariables": + parameterTypes.add((Type) delegateExecutionType); + parameterTypes.add((Type) mapVariablesType); + outSet = retrieveMethod(classPaths, className, methodName, classFile, element, chapter, fieldType, + scopeId, outSet, originalBlock, sootClass, parameterTypes, returnType); + break; + case "mapOutputVariables": + parameterTypes.add((Type) delegateExecutionType); + parameterTypes.add((Type) mapVariablesType); + outSet = retrieveMethod(classPaths, className, methodName, classFile, element, chapter, fieldType, + scopeId, outSet, originalBlock, sootClass, parameterTypes, returnType); + break; + default: + outSet = retrieveCustomMethod(sootClass, classPaths, className, methodName, classFile, element, chapter, + fieldType, scopeId, outSet, originalBlock); + break; } + + } else { + LOGGER.warning("Class " + classFile + " was not found by Soot"); } return outSet; @@ -411,26 +408,24 @@ public OutSetCFG classFetcherRecursive(final Set classPaths, String clas * Soot representation of parameters * @param returnType * Soot Representation of return type - * @param visitedClasses - * List of visited classes to avoid circular references * @return OutSetCFG which contains data flow information */ private OutSetCFG retrieveMethod(final Set classPaths, String className, final String methodName, final String classFile, final BpmnElement element, final ElementChapter chapter, final KnownElementFieldType fieldType, final String scopeId, OutSetCFG outSet, final VariableBlock originalBlock, final SootClass sootClass, final List parameterTypes, - final VoidType returnType, final ArrayList visitedClasses) { + final VoidType returnType) { - SootMethod method = sootClass.getMethodUnsafe(methodName, parameterTypes, (Type) returnType); + SootMethod method = sootClass.getMethodUnsafe(methodName, parameterTypes, returnType); if (method != null) { - outSet = fetchMethodBody(classPaths, className, methodName, classFile, element, chapter, fieldType, scopeId, - outSet, originalBlock, method, visitedClasses); + outSet = fetchMethodBody(classPaths, className, classFile, element, chapter, fieldType, scopeId, + outSet, originalBlock, method); } else { method = sootClass.getMethodByNameUnsafe(methodName); if (method != null) { - outSet = fetchMethodBody(classPaths, className, methodName, classFile, element, chapter, fieldType, - scopeId, outSet, originalBlock, method, visitedClasses); + outSet = fetchMethodBody(classPaths, className, classFile, element, chapter, fieldType, + scopeId, outSet, originalBlock, method); } else { LOGGER.warning("In class " + classFile + " - " + methodName + " method was not found by Soot"); } @@ -465,19 +460,17 @@ private OutSetCFG retrieveMethod(final Set classPaths, String className, * VariableBlock * @param sootClass * Soot representation of given class - * @param visitedClasses - * List of visited classes to avoid circular references * @return OutSetCFG which contains data flow information */ private OutSetCFG retrieveCustomMethod(final SootClass sootClass, final Set classPaths, String className, final String methodName, final String classFile, final BpmnElement element, final ElementChapter chapter, final KnownElementFieldType fieldType, final String scopeId, OutSetCFG outSet, - final VariableBlock originalBlock, final ArrayList visitedClasses) { + final VariableBlock originalBlock) { for (SootMethod method : sootClass.getMethods()) { if (method.getName().equals(methodName)) { - outSet = fetchMethodBody(classPaths, className, methodName, classFile, element, chapter, fieldType, - scopeId, outSet, originalBlock, method, visitedClasses); + outSet = fetchMethodBody(classPaths, className, classFile, element, chapter, fieldType, + scopeId, outSet, originalBlock, method); } } return outSet; @@ -492,8 +485,6 @@ private OutSetCFG retrieveCustomMethod(final SootClass sootClass, final Set classPaths, final String className, final String methodName, + private OutSetCFG fetchMethodBody(final Set classPaths, final String className, final String classFile, final BpmnElement element, final ElementChapter chapter, final KnownElementFieldType fieldType, final String scopeId, OutSetCFG outSet, - final VariableBlock originalBlock, final SootMethod method, final ArrayList visitedClasses) { + final VariableBlock originalBlock, final SootMethod method) { final Body body = method.retrieveActiveBody(); @@ -532,11 +521,10 @@ private OutSetCFG fetchMethodBody(final Set classPaths, final String cla CallGraph cg = Scene.v().getCallGraph(); final List graphHeads = graph.getHeads(); - final List graphTails = graph.getTails(); for (Block head : graphHeads) { - outSet = graphIterator(classPaths, cg, graph, head, graphTails, outSet, element, chapter, fieldType, - classFile, scopeId, originalBlock, className, visitedClasses); + outSet = graphIterator(classPaths, cg, graph, outSet, element, chapter, fieldType, + classFile, scopeId, originalBlock, className); } return outSet; @@ -552,10 +540,6 @@ private OutSetCFG fetchMethodBody(final Set classPaths, final String cla * Soot CallGraph * @param graph * Control Flow graph of method - * @param head - * Starting Block of the CFG - * @param blockTails - * List of End Blocks of CFG * @param outSet * OUT set of CFG * @param element @@ -572,14 +556,12 @@ private OutSetCFG fetchMethodBody(final Set classPaths, final String cla * VariableBlock * @param oldClassName * Classname - * @param visitedClasses - * List of visited classes to avoid circular references * @return OutSetCFG which contains data flow information */ - private OutSetCFG graphIterator(final Set classPaths, CallGraph cg, BlockGraph graph, Block head, - List blockTails, OutSetCFG outSet, final BpmnElement element, final ElementChapter chapter, + private OutSetCFG graphIterator(final Set classPaths, CallGraph cg, BlockGraph graph, + OutSetCFG outSet, final BpmnElement element, final ElementChapter chapter, final KnownElementFieldType fieldType, final String filePath, final String scopeId, - VariableBlock originalBlock, String oldClassName, final ArrayList visitedClasses) { + VariableBlock originalBlock, String oldClassName) { final Iterator graphIterator = graph.iterator(); @@ -589,7 +571,7 @@ private OutSetCFG graphIterator(final Set classPaths, CallGraph cg, Bloc // Collect the functions Unit by Unit via the blockIterator final VariableBlock vb = blockIterator(classPaths, cg, block, outSet, element, chapter, fieldType, filePath, - scopeId, originalBlock, oldClassName, visitedClasses); + scopeId, originalBlock, oldClassName); // depending if outset already has that Block, only add varibles, // if not, then add the whole vb @@ -630,14 +612,12 @@ private OutSetCFG graphIterator(final Set classPaths, CallGraph cg, Bloc * VariableBlock * @param oldClassName * Classname - * @param visitedClasses - * List of visited classes to avoid circular references * @return VariableBlock */ private VariableBlock blockIterator(final Set classPaths, final CallGraph cg, final Block block, OutSetCFG outSet, final BpmnElement element, final ElementChapter chapter, final KnownElementFieldType fieldType, final String filePath, final String scopeId, - VariableBlock variableBlock, String oldClassName, final ArrayList visitedClasses) { + VariableBlock variableBlock, String oldClassName) { if (variableBlock == null) { variableBlock = new VariableBlock(block, new ArrayList()); @@ -655,7 +635,7 @@ private VariableBlock blockIterator(final Set classPaths, final CallGrap Edge src; while (sources.hasNext()) { - src = (Edge) sources.next(); + src = sources.next(); String methodName = src.tgt().getName(); String className = src.tgt().getDeclaringClass().getName(); className = cleanString(className, false); @@ -668,7 +648,7 @@ private VariableBlock blockIterator(final Set classPaths, final CallGrap if (classPaths.contains(className) || className.contains("$")) { G.reset(); classFetcherRecursive(classPaths, className, methodName, className, element, chapter, fieldType, - scopeId, outSet, variableBlock, visitedClasses); + scopeId, outSet, variableBlock); } } @@ -725,7 +705,7 @@ private VariableBlock blockIterator(final Set classPaths, final CallGrap private void parseExpression(JInterfaceInvokeExpr expr, VariableBlock variableBlock, BpmnElement element, ElementChapter chapter, KnownElementFieldType fieldType, String filePath, String scopeId) { - String functionName = expr.getMethodRef().name(); + String functionName = expr.getMethodRef().getName(); int numberOfArg = expr.getArgCount(); String baseBox = expr.getBaseBox().getValue().getType().toString(); @@ -748,6 +728,45 @@ private void parseExpression(JInterfaceInvokeExpr expr, VariableBlock variableBl } } + /** + * + * Parsing of initially discovered statements to find Process Variable + * operations. + * + * @param expr + * Expression Unit from Statement + * @param element + * Current BPMN Element + * @param resourceFilePath + * Filepath of model + * @return inital operations + */ + private Map parseInitialExpression(final JInterfaceInvokeExpr expr, final BpmnElement element, + final String resourceFilePath) { + + final LinkedHashMap initialOperations = new LinkedHashMap<>(); + + final String functionName = expr.getMethodRef().getName(); + final int numberOfArg = expr.getArgCount(); + final String baseBox = expr.getBaseBox().getValue().getType().toString(); + + final CamundaProcessVariableFunctions foundMethod = CamundaProcessVariableFunctions + .findByNameAndNumberOfBoxes(functionName, baseBox, numberOfArg); + + if (foundMethod != null) { + final int location = foundMethod.getLocation() - 1; + final VariableOperation type = foundMethod.getOperationType(); + if (expr.getArgBox(location).getValue() instanceof StringConstant) { + final StringConstant variableName = (StringConstant) expr.getArgBox(location).getValue(); + final String name = variableName.value; + initialOperations.put(name, new ProcessVariableOperation(expr.getArg(0).toString(), element, + ElementChapter.Code, KnownElementFieldType.Initial, resourceFilePath, type, + element.getBaseElement().getId())); + } + } + return initialOperations; + } + /** * * Find anomalies inside a Bpmn element as well. @@ -952,30 +971,8 @@ private boolean duSourceCode(final ProcessVariableOperation prev, final ProcessV * @return cleaned String */ private String cleanString(String className, boolean dot) { - final String replaceDot = "."; - final String replaceEmpty = ""; - final String replaceSingleBackSlash = "\\"; - final String replaceSingleForwardSlash = "/"; - final String replaceDotJava = ".java"; - - if (dot) { - if (System.getProperty("os.name").startsWith("Windows")) { - className = className.replace(replaceSingleBackSlash, replaceDot).replace(replaceDotJava, replaceEmpty); - } else { - className = className.replace(replaceSingleForwardSlash, replaceDot).replace(replaceDotJava, - replaceEmpty); - } - } else { - if (System.getProperty("os.name").startsWith("Windows")) { - className = className.replace(replaceDot, replaceSingleBackSlash); - className = className.concat(replaceDotJava); - } else { - className = className.replace(replaceDot, replaceSingleForwardSlash); - className = className.concat(replaceDotJava); - } - } + className = ProcessVariablesScanner.cleanString(className, dot); return className; - } } diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/ProcessVariableReader.java b/src/main/java/de/viadee/bpm/vPAV/processing/ProcessVariableReader.java index 6d02879b..eeebec44 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/ProcessVariableReader.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/ProcessVariableReader.java @@ -31,47 +31,20 @@ */ package de.viadee.bpm.vPAV.processing; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.el.ELException; - +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.constants.BpmnConstants; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.model.data.*; import org.camunda.bpm.engine.impl.juel.Builder; import org.camunda.bpm.engine.impl.juel.IdentifierNode; import org.camunda.bpm.engine.impl.juel.Tree; import org.camunda.bpm.engine.impl.juel.TreeBuilder; import org.camunda.bpm.model.bpmn.Query; import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance; -import org.camunda.bpm.model.bpmn.instance.BusinessRuleTask; -import org.camunda.bpm.model.bpmn.instance.CallActivity; -import org.camunda.bpm.model.bpmn.instance.CompletionCondition; -import org.camunda.bpm.model.bpmn.instance.ConditionExpression; -import org.camunda.bpm.model.bpmn.instance.ExtensionElements; -import org.camunda.bpm.model.bpmn.instance.LoopCardinality; -import org.camunda.bpm.model.bpmn.instance.LoopCharacteristics; -import org.camunda.bpm.model.bpmn.instance.Script; -import org.camunda.bpm.model.bpmn.instance.ScriptTask; -import org.camunda.bpm.model.bpmn.instance.SendTask; -import org.camunda.bpm.model.bpmn.instance.SequenceFlow; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.camunda.bpm.model.bpmn.instance.UserTask; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaExecutionListener; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaFormData; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaFormField; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaIn; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaOut; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaTaskListener; +import org.camunda.bpm.model.bpmn.instance.*; +import org.camunda.bpm.model.bpmn.instance.camunda.*; import org.camunda.bpm.model.dmn.Dmn; import org.camunda.bpm.model.dmn.DmnModelInstance; import org.camunda.bpm.model.dmn.instance.Decision; @@ -80,16 +53,12 @@ import org.camunda.bpm.model.dmn.instance.Text; import org.camunda.bpm.model.xml.instance.ModelElementInstance; -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.constants.BpmnConstants; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.ElementChapter; -import de.viadee.bpm.vPAV.processing.model.data.KnownElementFieldType; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; -import de.viadee.bpm.vPAV.processing.model.data.VariableOperation; +import javax.el.ELException; +import java.io.InputStream; +import java.util.*; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * search process variables for an bpmn element @@ -117,12 +86,13 @@ public ProcessVariableReader(final Map decisionRefToPathMap, Bpm * FileScanner * @param element * BpmnElement - * @return processVariables returns processVariables + * @param processVariables + * process variable operation + * @return returns processVariables */ public LinkedHashMap getVariablesFromElement(final JavaReaderContext context, - final FileScanner fileScanner, final BpmnElement element) { - - final LinkedHashMap processVariables = new LinkedHashMap(); + final FileScanner fileScanner, final BpmnElement element, + final LinkedHashMap processVariables) { // 1) Search variables in task processVariables.putAll(getVariablesFromTask(context, fileScanner, element)); diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/ProcessVariablesScanner.java b/src/main/java/de/viadee/bpm/vPAV/processing/ProcessVariablesScanner.java new file mode 100644 index 00000000..9be90c51 --- /dev/null +++ b/src/main/java/de/viadee/bpm/vPAV/processing/ProcessVariablesScanner.java @@ -0,0 +1,184 @@ +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing; + +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.constants.CamundaMethodServices; +import soot.Body; +import soot.Scene; +import soot.SootClass; +import soot.SootMethod; +import soot.options.Options; + +import java.io.IOException; +import java.util.*; + +public class ProcessVariablesScanner { + + private Set javaResources; + + private Map> messageIdToVariableMap = new HashMap>(); + + private Map> processIdToVariableMap = new HashMap>(); + + private Map> entryPoints = new HashMap>(); + + private Set camundaProcessEntryPoints = new HashSet(); + + public ProcessVariablesScanner(final Set javaResources) { + this.javaResources = javaResources; + camundaProcessEntryPoints.add(CamundaMethodServices.START_PROCESS_INSTANCE_BY_ID); + camundaProcessEntryPoints.add(CamundaMethodServices.START_PROCESS_INSTANCE_BY_KEY); + camundaProcessEntryPoints.add(CamundaMethodServices.START_PROCESS_INSTANCE_BY_MESSAGE); + camundaProcessEntryPoints.add(CamundaMethodServices.START_PROCESS_INSTANCE_BY_MESSAGE_AND_PROCESS_DEF); + } + + /** + * scan java resources for variables and retrieve important information such as + * message ids and entrypoints + * + * @throws IOException + * possible exception if filepath can not be resolved + */ + public void scanProcessVariables() throws IOException { + for (final String filePath : javaResources) { + if (!filePath.startsWith("javax")) { + final Set messageIds = new HashSet(); + final Set processIds = new HashSet(); + retrieveMethod(filePath, messageIds, processIds); + } + } + } + + /** + * Retrieve the method name which contains the entrypoint (e.g. + * "startProcessByXYZ") + * + * @param filePath + * fully qualified path to the java class + * @return + */ + private void retrieveMethod(final String filePath, final Set messageIds, final Set processIds) { + final String sootPath = FileScanner.getSootPath(); + System.setProperty("soot.class.path", sootPath); + + Options.v().set_whole_program(true); + Options.v().set_allow_phantom_refs(true); + + SootClass sootClass = Scene.v().forceResolve(cleanString(filePath, true), SootClass.SIGNATURES); + + if (sootClass != null && !sootClass.isInterface()) { + sootClass.setApplicationClass(); + Scene.v().loadNecessaryClasses(); + for (SootMethod method : sootClass.getMethods()) { +// if (method.hasActiveBody()) { + final Body body = method.retrieveActiveBody(); + for (String entryPoint : camundaProcessEntryPoints) { + if (body.toString().contains(entryPoint)) { + final Map innerMap = new HashMap(); + innerMap.put(method.getName(), filePath); + entryPoints.put(entryPoint, innerMap); + messageIds.add(entryPoint); + } + if (body.toString().contains(CamundaMethodServices.CORRELATE_MESSAGE)) { + processIds.add(entryPoint); + } + } +// } + } + } + } + + /** + * Strips unnecessary characters and returns cleaned name + * + * @param className + * Classname to be stripped of unused chars + * @param dot + * Replace dots + * @return cleaned String + */ + static String cleanString(String className, boolean dot) { + final String replaceDot = "."; + final String replaceEmpty = ""; + final String replaceSingleBackSlash = "\\"; + final String replaceSingleForwardSlash = "/"; + final String replaceDotJava = ".java"; + + if (dot) { + if (System.getProperty("os.name").startsWith("Windows")) { + className = className.replace(replaceSingleBackSlash, replaceDot).replace(replaceDotJava, replaceEmpty); + } else { + className = className.replace(replaceSingleForwardSlash, replaceDot).replace(replaceDotJava, + replaceEmpty); + } + } else { + if (System.getProperty("os.name").startsWith("Windows")) { + className = className.replace(replaceDot, replaceSingleBackSlash); + className = className.concat(replaceDotJava); + } else { + className = className.replace(replaceDot, replaceSingleForwardSlash); + className = className.concat(replaceDotJava); + } + } + return className; + } + + /** + * get list of entrypoints (process message, method) where process variables + * have been found + * + * @return returns list of locations + */ + public Map> getEntryPoints() { + return entryPoints; + } + + /** + * get mapping for message id + * + * @return messageIdToVariableMap returns messageIdToVariableMap + */ + public Map> getMessageIdToVariableMap() { + return messageIdToVariableMap; + } + + /** + * get mapping for process id + * + * @return processIdToVariableMap returns processIdToVariableMap + */ + public Map> getProcessIdToVariableMap() { + return processIdToVariableMap; + } + +} diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/ResourceFileReader.java b/src/main/java/de/viadee/bpm/vPAV/processing/ResourceFileReader.java index 6035c6a6..88de0a6a 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/ResourceFileReader.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/ResourceFileReader.java @@ -31,6 +31,13 @@ */ package de.viadee.bpm.vPAV.processing; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.model.data.*; +import org.apache.commons.io.IOUtils; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.types.Resource; + import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; @@ -39,18 +46,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.io.IOUtils; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.types.Resource; - -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.ElementChapter; -import de.viadee.bpm.vPAV.processing.model.data.KnownElementFieldType; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; -import de.viadee.bpm.vPAV.processing.model.data.VariableOperation; - public class ResourceFileReader { public static final Logger LOGGER = Logger.getLogger(ResourceFileReader.class.getName()); diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/BoundaryErrorChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/BoundaryErrorChecker.java index cf5e4058..3a89540d 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/BoundaryErrorChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/BoundaryErrorChecker.java @@ -1,304 +1,303 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.logging.Logger; - -import org.apache.commons.io.IOUtils; -import org.apache.tools.ant.DirectoryScanner; -import org.apache.tools.ant.types.Resource; -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; - -import de.odysseus.el.tree.IdentifierNode; -import de.odysseus.el.tree.Tree; -import de.odysseus.el.tree.TreeBuilder; -import de.odysseus.el.tree.impl.Builder; -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.Messages; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.constants.BpmnConstants; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.output.IssueWriter; -import de.viadee.bpm.vPAV.processing.CheckName; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; -import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; - -public class BoundaryErrorChecker extends AbstractElementChecker { - - private static Logger logger = Logger.getLogger(BoundaryErrorChecker.class.getName()); - - public BoundaryErrorChecker(final Rule rule, BpmnScanner bpmnScanner) { - super(rule, bpmnScanner); - } - - @Override - public Collection check(BpmnElement element) { - - final Collection issues = new ArrayList(); - final BaseElement bpmnElement = element.getBaseElement(); - - String mappedTaskId = null; - String implementation = null; - String implementationRef = null; - - // Grab only boundaryEvents - if (bpmnElement.getElementType().getTypeName().equals(BpmnModelConstants.BPMN_ELEMENT_BOUNDARY_EVENT)) { - - // Map errorEventDef -> "errorRef" , "camunda:errorMessageVariable" - final Map errorEventDef = bpmnScanner.getErrorEvent(bpmnElement.getId()); - - // Check if boundaryEvent consists of an errorEventDefinition - if (errorEventDef.size() != 0) { - mappedTaskId = bpmnScanner.getErrorEventMapping(bpmnElement.getId()); - implementation = bpmnScanner.getImplementation(mappedTaskId); - implementationRef = bpmnScanner.getImplementationReference(mappedTaskId, - implementation); - - // No error has been referenced - if (errorEventDef.entrySet().iterator().next().getKey() == null - || errorEventDef.entrySet().iterator().next().getKey().isEmpty()) { - final String errorCode = bpmnScanner.getErrorCodeVar(bpmnElement.getId()); - if (errorCode == null || errorCode.isEmpty()) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("BoundaryErrorChecker.0"), //$NON-NLS-1$ - CheckName.checkName(bpmnElement)))); - } else { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("BoundaryErrorChecker.1"), //$NON-NLS-1$ - CheckName.checkName(bpmnElement)))); - } - } else { - - // Error reference could be resolved, retrieve errorDefinition - final Map errorDef = bpmnScanner - .getErrorDef(errorEventDef.entrySet().iterator().next().getKey()); - - // No errorCode has been specified - if (errorDef.entrySet().iterator().next().getValue() == null - || errorDef.entrySet().iterator().next().getValue().isEmpty()) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, - String.format(Messages.getString("BoundaryErrorChecker.2"), //$NON-NLS-1$ - CheckName.checkName(bpmnElement)))); - - } else { - if (implementation != null) { - // Check the BeanMapping to resolve delegate expression - if (implementation.equals(BpmnConstants.CAMUNDA_DEXPRESSION)) { - checkBeanMapping(element, issues, bpmnElement, - errorDef.entrySet().iterator().next().getValue(), implementationRef); - - // Check the directly referenced class - } else if (implementation.equals(BpmnConstants.CAMUNDA_CLASS)) { - if (!readResourceFile(implementationRef, - errorDef.entrySet().iterator().next().getValue())) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format( - Messages.getString("BoundaryErrorChecker.3"), //$NON-NLS-1$ - CheckName.checkName(bpmnElement), implementationRef))); - - } - } - } - } - - // No errorName has been specified - if (errorDef.entrySet().iterator().next().getKey() == null - || errorDef.entrySet().iterator().next().getKey().isEmpty()) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, - String.format(Messages.getString("BoundaryErrorChecker.4"), //$NON-NLS-1$ - CheckName.checkName(bpmnElement)))); - } - - // No ErrorMessageVariable has been specified - if (errorEventDef.entrySet().iterator().next().getValue() == null - || errorEventDef.entrySet().iterator().next().getValue().isEmpty()) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, - String.format(Messages.getString("BoundaryErrorChecker.5"), //$NON-NLS-1$ - CheckName.checkName(bpmnElement)))); - } - } - } - } - return issues; - } - - /** - * In case a bean mapping exists, we check for validity of a bean, so the event can be mapped against the respective - * task If the class or bean can be resolved, the ErrorCode gets validated - * - * @param element - * @param issues - * @param bpmnElement - * @param errorDefEntry - * @param implementationRef - */ - private void checkBeanMapping(BpmnElement element, final Collection issues, - final BaseElement bpmnElement, final String errorDefEntry, final String implementationRef) { - if (RuntimeConfig.getInstance().getBeanMapping() != null) { - final TreeBuilder treeBuilder = new Builder(); - final Tree tree = treeBuilder.build(implementationRef); - final Iterable identifierNodes = tree.getIdentifierNodes(); - // if beanMapping ${...} reference - if (identifierNodes.iterator().hasNext()) { - for (final IdentifierNode node : identifierNodes) { - final String classFile = RuntimeConfig.getInstance().getBeanMapping() - .get(node.getName()); - // correct beanmapping was found -> check if class exists - if (classFile != null && classFile.trim().length() > 0) { - if (checkClassFile(classFile)) { - if (!readResourceFile(classFile, errorDefEntry)) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format( - Messages.getString("BoundaryErrorChecker.6"), //$NON-NLS-1$ - CheckName.checkName(bpmnElement), node.getName()))); - } - } else { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - Messages.getString("BoundaryErrorChecker.7"))); //$NON-NLS-1$ - } - } else { - // incorrect beanmapping - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, String.format( - Messages.getString("BoundaryErrorChecker.8"), //$NON-NLS-1$ - implementationRef))); - } - } - } - } else { - if (!checkClassFile(implementationRef)) { - issues.addAll( - IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format( - Messages.getString("BoundaryErrorChecker.9"), //$NON-NLS-1$ - implementationRef, CheckName.checkName(bpmnElement)))); - } - } - } - - /** - * Reads a resource and retrieves content as String - * - * @param className - * @param errorCode - * @return boolean - */ - private boolean readResourceFile(final String className, final String errorCode) { - - final String fileName = className.replaceAll("\\.", "/") + ".java"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - boolean matchingErrorCode = false; - - if (fileName != null && fileName.trim().length() > 0) { - try { - final DirectoryScanner scanner = new DirectoryScanner(); - - if (RuntimeConfig.getInstance().isTest()) { - if (fileName.endsWith(".java")) //$NON-NLS-1$ - scanner.setBasedir(ConfigConstants.TEST_JAVAPATH); - else - scanner.setBasedir(ConfigConstants.TEST_BASEPATH); - } else { - if (fileName.endsWith(".java")) //$NON-NLS-1$ - scanner.setBasedir(ConfigConstants.JAVAPATH); - else - scanner.setBasedir(ConfigConstants.BASEPATH); - } - - Resource s = scanner.getResource(fileName); - - if (s.isExists()) { - InputStreamReader resource = new InputStreamReader(new FileInputStream(s.toString())); - final String methodBody = IOUtils.toString(resource); - return validateContent(methodBody, errorCode); - } else { - logger.warning("Class " + fileName + " could not be read or does not exist"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } catch (final IOException ex) { - logger.warning("Resource '" + fileName + "' could not be read: " + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - return matchingErrorCode; - } - - /** - * Check methodBody for content and return true if a "throw new BpmnError.." declaration is found - * - * @param errorCode - * @param methodBody - * @return boolean - */ - private boolean validateContent(final String methodBody, final String errorCode) { - - if (methodBody != null && !methodBody.isEmpty()) { - if (methodBody.contains("throw new BpmnError")) { //$NON-NLS-1$ - String temp = methodBody.substring(methodBody.indexOf("throw new BpmnError")); //$NON-NLS-1$ - temp = temp.substring(0, temp.indexOf(";") + 1); //$NON-NLS-1$ - - final String delErrorCode = temp.substring(temp.indexOf("\"") + 1, temp.lastIndexOf("\"")); //$NON-NLS-1$ //$NON-NLS-2$ - if (delErrorCode.equals(errorCode)) { - return true; - } - } - } - return false; - } - - /** - * Check if class reference for a given element exists - * - * @param className - * @return boolean - */ - private boolean checkClassFile(final String className) { - - @SuppressWarnings("unused") - final String classPath = className.replaceAll("\\.", "/") + ".java"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - try { - RuntimeConfig.getInstance().getClassLoader().loadClass(className); - } catch (final ClassNotFoundException e) { - return false; - } - return true; - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.odysseus.el.tree.IdentifierNode; +import de.odysseus.el.tree.Tree; +import de.odysseus.el.tree.TreeBuilder; +import de.odysseus.el.tree.impl.Builder; +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.Messages; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.constants.BpmnConstants; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.output.IssueWriter; +import de.viadee.bpm.vPAV.processing.CheckName; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.apache.commons.io.IOUtils; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.types.Resource; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.logging.Logger; + +public class BoundaryErrorChecker extends AbstractElementChecker { + + private static Logger logger = Logger.getLogger(BoundaryErrorChecker.class.getName()); + + public BoundaryErrorChecker(final Rule rule, BpmnScanner bpmnScanner) { + super(rule, bpmnScanner); + } + + @Override + public Collection check(BpmnElement element) { + + final Collection issues = new ArrayList(); + final BaseElement bpmnElement = element.getBaseElement(); + + String mappedTaskId = null; + String implementation = null; + String implementationRef = null; + + // Grab only boundaryEvents + if (bpmnElement.getElementType().getTypeName().equals(BpmnModelConstants.BPMN_ELEMENT_BOUNDARY_EVENT)) { + + // Map errorEventDef -> "errorRef" , "camunda:errorMessageVariable" + final Map errorEventDef = bpmnScanner.getErrorEvent(bpmnElement.getId()); + + // Check if boundaryEvent consists of an errorEventDefinition + if (errorEventDef.size() != 0) { + mappedTaskId = bpmnScanner.getErrorEventMapping(bpmnElement.getId()); + implementation = bpmnScanner.getImplementation(mappedTaskId); + implementationRef = bpmnScanner.getImplementationReference(mappedTaskId, + implementation); + + // No error has been referenced + if (errorEventDef.entrySet().iterator().next().getKey() == null + || errorEventDef.entrySet().iterator().next().getKey().isEmpty()) { + final String errorCode = bpmnScanner.getErrorCodeVar(bpmnElement.getId()); + if (errorCode == null || errorCode.isEmpty()) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("BoundaryErrorChecker.0"), //$NON-NLS-1$ + CheckName.checkName(bpmnElement)))); + } else { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("BoundaryErrorChecker.1"), //$NON-NLS-1$ + CheckName.checkName(bpmnElement)))); + } + } else { + + // Error reference could be resolved, retrieve errorDefinition + final Map errorDef = bpmnScanner + .getErrorDef(errorEventDef.entrySet().iterator().next().getKey()); + + // No errorCode has been specified + if (errorDef.entrySet().iterator().next().getValue() == null + || errorDef.entrySet().iterator().next().getValue().isEmpty()) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, + String.format(Messages.getString("BoundaryErrorChecker.2"), //$NON-NLS-1$ + CheckName.checkName(bpmnElement)))); + + } else { + if (implementation != null) { + // Check the BeanMapping to resolve delegate expression + if (implementation.equals(BpmnConstants.CAMUNDA_DEXPRESSION)) { + checkBeanMapping(element, issues, bpmnElement, + errorDef.entrySet().iterator().next().getValue(), implementationRef); + + // Check the directly referenced class + } else if (implementation.equals(BpmnConstants.CAMUNDA_CLASS)) { + if (!readResourceFile(implementationRef, + errorDef.entrySet().iterator().next().getValue())) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format( + Messages.getString("BoundaryErrorChecker.3"), //$NON-NLS-1$ + CheckName.checkName(bpmnElement), implementationRef))); + + } + } + } + } + + // No errorName has been specified + if (errorDef.entrySet().iterator().next().getKey() == null + || errorDef.entrySet().iterator().next().getKey().isEmpty()) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, + String.format(Messages.getString("BoundaryErrorChecker.4"), //$NON-NLS-1$ + CheckName.checkName(bpmnElement)))); + } + + // No ErrorMessageVariable has been specified + if (errorEventDef.entrySet().iterator().next().getValue() == null + || errorEventDef.entrySet().iterator().next().getValue().isEmpty()) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, + String.format(Messages.getString("BoundaryErrorChecker.5"), //$NON-NLS-1$ + CheckName.checkName(bpmnElement)))); + } + } + } + } + return issues; + } + + /** + * In case a bean mapping exists, we check for validity of a bean, so the event can be mapped against the respective + * task If the class or bean can be resolved, the ErrorCode gets validated + * + * @param element + * @param issues + * @param bpmnElement + * @param errorDefEntry + * @param implementationRef + */ + private void checkBeanMapping(BpmnElement element, final Collection issues, + final BaseElement bpmnElement, final String errorDefEntry, final String implementationRef) { + if (RuntimeConfig.getInstance().getBeanMapping() != null) { + final TreeBuilder treeBuilder = new Builder(); + final Tree tree = treeBuilder.build(implementationRef); + final Iterable identifierNodes = tree.getIdentifierNodes(); + // if beanMapping ${...} reference + if (identifierNodes.iterator().hasNext()) { + for (final IdentifierNode node : identifierNodes) { + final String classFile = RuntimeConfig.getInstance().getBeanMapping() + .get(node.getName()); + // correct beanmapping was found -> check if class exists + if (classFile != null && classFile.trim().length() > 0) { + if (checkClassFile(classFile)) { + if (!readResourceFile(classFile, errorDefEntry)) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format( + Messages.getString("BoundaryErrorChecker.6"), //$NON-NLS-1$ + CheckName.checkName(bpmnElement), node.getName()))); + } + } else { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + Messages.getString("BoundaryErrorChecker.7"))); //$NON-NLS-1$ + } + } else { + // incorrect beanmapping + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, String.format( + Messages.getString("BoundaryErrorChecker.8"), //$NON-NLS-1$ + implementationRef))); + } + } + } + } else { + if (!checkClassFile(implementationRef)) { + issues.addAll( + IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format( + Messages.getString("BoundaryErrorChecker.9"), //$NON-NLS-1$ + implementationRef, CheckName.checkName(bpmnElement)))); + } + } + } + + /** + * Reads a resource and retrieves content as String + * + * @param className + * @param errorCode + * @return boolean + */ + private boolean readResourceFile(final String className, final String errorCode) { + + final String fileName = className.replaceAll("\\.", "/") + ".java"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + boolean matchingErrorCode = false; + + if (fileName != null && fileName.trim().length() > 0) { + try { + final DirectoryScanner scanner = new DirectoryScanner(); + + if (RuntimeConfig.getInstance().isTest()) { + if (fileName.endsWith(".java")) //$NON-NLS-1$ + scanner.setBasedir(ConfigConstants.TEST_JAVAPATH); + else + scanner.setBasedir(ConfigConstants.TEST_BASEPATH); + } else { + if (fileName.endsWith(".java")) //$NON-NLS-1$ + scanner.setBasedir(ConfigConstants.JAVAPATH); + else + scanner.setBasedir(ConfigConstants.BASEPATH); + } + + Resource s = scanner.getResource(fileName); + + if (s.isExists()) { + InputStreamReader resource = new InputStreamReader(new FileInputStream(s.toString())); + final String methodBody = IOUtils.toString(resource); + return validateContent(methodBody, errorCode); + } else { + logger.warning("Class " + fileName + " could not be read or does not exist"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } catch (final IOException ex) { + logger.warning("Resource '" + fileName + "' could not be read: " + ex.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + + return matchingErrorCode; + } + + /** + * Check methodBody for content and return true if a "throw new BpmnError.." declaration is found + * + * @param errorCode + * @param methodBody + * @return boolean + */ + private boolean validateContent(final String methodBody, final String errorCode) { + + if (methodBody != null && !methodBody.isEmpty()) { + if (methodBody.contains("throw new BpmnError")) { //$NON-NLS-1$ + String temp = methodBody.substring(methodBody.indexOf("throw new BpmnError")); //$NON-NLS-1$ + temp = temp.substring(0, temp.indexOf(";") + 1); //$NON-NLS-1$ + + final String delErrorCode = temp.substring(temp.indexOf("\"") + 1, temp.lastIndexOf("\"")); //$NON-NLS-1$ //$NON-NLS-2$ + if (delErrorCode.equals(errorCode)) { + return true; + } + } + } + return false; + } + + /** + * Check if class reference for a given element exists + * + * @param className + * @return boolean + */ + private boolean checkClassFile(final String className) { + + @SuppressWarnings("unused") + final String classPath = className.replaceAll("\\.", "/") + ".java"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + try { + RuntimeConfig.getInstance().getClassLoader().loadClass(className); + } catch (final ClassNotFoundException e) { + return false; + } + return true; + } + +} diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/CheckerFactory.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/CheckerFactory.java index 8f176b31..04bd7dff 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/CheckerFactory.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/CheckerFactory.java @@ -31,15 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Logger; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.Messages; import de.viadee.bpm.vPAV.RuntimeConfig; @@ -47,6 +38,11 @@ import de.viadee.bpm.vPAV.constants.BpmnConstants; import de.viadee.bpm.vPAV.constants.ConfigConstants; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.*; +import java.util.logging.Logger; + /** * Factory decides which Checkers will be used in defined situations * diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/DataFlowChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/DataFlowChecker.java index 4eea51ce..86770848 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/DataFlowChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/DataFlowChecker.java @@ -34,8 +34,8 @@ import de.viadee.bpm.vPAV.config.model.Rule; import de.viadee.bpm.vPAV.output.IssueWriter; import de.viadee.bpm.vPAV.processing.dataflow.DataFlowRule; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariable; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import de.viadee.bpm.vPAV.processing.model.data.ProcessVariable; import org.camunda.bpm.model.bpmn.BpmnModelInstance; import java.util.ArrayList; diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/DmnTaskChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/DmnTaskChecker.java index e41fb6b3..37304d7c 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/DmnTaskChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/DmnTaskChecker.java @@ -31,14 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.BusinessRuleTask; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.Messages; import de.viadee.bpm.vPAV.RuntimeConfig; @@ -49,6 +41,13 @@ import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.BusinessRuleTask; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; /** * Checks, whether a business rule task with dmn implementation is valid diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ElementChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ElementChecker.java index c5aee336..be92d717 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ElementChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ElementChecker.java @@ -31,11 +31,11 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.Collection; - import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import java.util.Collection; + /** * Checks bpmn models for defined characteristics */ diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ElementIdConventionChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ElementIdConventionChecker.java index be72d229..cf71b7b1 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ElementIdConventionChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ElementIdConventionChecker.java @@ -1,87 +1,86 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.Messages; -import de.viadee.bpm.vPAV.config.model.ElementConvention; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.output.IssueWriter; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; -import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; - -public class ElementIdConventionChecker extends AbstractElementChecker { - - public ElementIdConventionChecker(final Rule rule, final BpmnScanner bpmnScanner) { - super(rule, bpmnScanner); - } - - /** - * Check if an element follows a configurable pattern - * - * @return issues - */ - @Override - public Collection check(final BpmnElement element) { - final Collection issues = new ArrayList(); - final BaseElement baseElement = element.getBaseElement(); - - final Collection elementConventions = rule.getElementConventions(); - - final String elementId = baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_ID); - - if (elementConventions != null && !elementConventions.isEmpty() && elementId != null) { - for (final ElementConvention convention : elementConventions) { - final Pattern pattern = Pattern.compile(convention.getPattern().trim()); - Matcher matcher = pattern.matcher(elementId); - String bpmnInstance = convention.getName(); - if (!matcher.matches() - && baseElement.getElementType().getInstanceType().getSimpleName().toLowerCase() - .equals(bpmnInstance.toLowerCase())) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, - String.format(Messages.getString("ElementIdConventionChecker.0"), elementId), //$NON-NLS-1$ - convention.getDescription())); - } - } - } - return issues; - } -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.Messages; +import de.viadee.bpm.vPAV.config.model.ElementConvention; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.output.IssueWriter; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ElementIdConventionChecker extends AbstractElementChecker { + + public ElementIdConventionChecker(final Rule rule, final BpmnScanner bpmnScanner) { + super(rule, bpmnScanner); + } + + /** + * Check if an element follows a configurable pattern + * + * @return issues + */ + @Override + public Collection check(final BpmnElement element) { + final Collection issues = new ArrayList(); + final BaseElement baseElement = element.getBaseElement(); + + final Collection elementConventions = rule.getElementConventions(); + + final String elementId = baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_ID); + + if (elementConventions != null && !elementConventions.isEmpty() && elementId != null) { + for (final ElementConvention convention : elementConventions) { + final Pattern pattern = Pattern.compile(convention.getPattern().trim()); + Matcher matcher = pattern.matcher(elementId); + String bpmnInstance = convention.getName(); + if (!matcher.matches() + && baseElement.getElementType().getInstanceType().getSimpleName().toLowerCase() + .equals(bpmnInstance.toLowerCase())) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, + String.format(Messages.getString("ElementIdConventionChecker.0"), elementId), //$NON-NLS-1$ + convention.getDescription())); + } + } + } + return issues; + } +} diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/EmbeddedGroovyScriptChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/EmbeddedGroovyScriptChecker.java index 6ccff69d..f8b9089b 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/EmbeddedGroovyScriptChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/EmbeddedGroovyScriptChecker.java @@ -31,19 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.ExtensionElements; -import org.camunda.bpm.model.bpmn.instance.Script; -import org.camunda.bpm.model.bpmn.instance.ScriptTask; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaExecutionListener; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaTaskListener; -import org.codehaus.groovy.control.CompilationFailedException; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.Messages; import de.viadee.bpm.vPAV.config.model.Rule; @@ -54,6 +41,18 @@ import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; import groovy.lang.GroovyShell; import groovy.lang.MissingPropertyException; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.ExtensionElements; +import org.camunda.bpm.model.bpmn.instance.Script; +import org.camunda.bpm.model.bpmn.instance.ScriptTask; +import org.camunda.bpm.model.bpmn.instance.camunda.CamundaExecutionListener; +import org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript; +import org.camunda.bpm.model.bpmn.instance.camunda.CamundaTaskListener; +import org.codehaus.groovy.control.CompilationFailedException; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; /** * Class EmbeddedGroovyScriptChecker diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ExtensionChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ExtensionChecker.java index 6860e2dc..967b87af 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ExtensionChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ExtensionChecker.java @@ -31,17 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.Messages; import de.viadee.bpm.vPAV.config.model.Rule; @@ -51,6 +40,16 @@ import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ExtensionChecker extends AbstractElementChecker { diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/FieldInjectionChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/FieldInjectionChecker.java index 32188f7e..ec69c8ad 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/FieldInjectionChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/FieldInjectionChecker.java @@ -31,22 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collection; -import java.util.logging.Logger; - -import org.camunda.bpm.engine.delegate.Expression; -import org.camunda.bpm.engine.impl.el.FixedValue; -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.BusinessRuleTask; -import org.camunda.bpm.model.bpmn.instance.SendTask; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.camunda.bpm.model.bpmn.instance.UserTask; - import de.odysseus.el.tree.IdentifierNode; import de.odysseus.el.tree.Tree; import de.odysseus.el.tree.TreeBuilder; @@ -60,6 +44,17 @@ import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.engine.delegate.Expression; +import org.camunda.bpm.engine.impl.el.FixedValue; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.*; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collection; +import java.util.logging.Logger; /** * Class FieldInjectionChecker diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/JavaDelegateChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/JavaDelegateChecker.java index 25663d46..de21e506 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/JavaDelegateChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/JavaDelegateChecker.java @@ -31,16 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.ArrayList; -import java.util.Collection; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.BusinessRuleTask; -import org.camunda.bpm.model.bpmn.instance.SendTask; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.camunda.bpm.model.bpmn.instance.UserTask; - import de.odysseus.el.tree.IdentifierNode; import de.odysseus.el.tree.Tree; import de.odysseus.el.tree.TreeBuilder; @@ -55,6 +45,11 @@ import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.*; + +import java.util.ArrayList; +import java.util.Collection; /** * Class JavaDelegateChecker @@ -91,10 +86,10 @@ public Collection check(final BpmnElement element) { // read attributes from task if ((bpmnElement instanceof ServiceTask || bpmnElement instanceof BusinessRuleTask || bpmnElement instanceof SendTask)) { - implementationAttr = bpmnScanner.getImplementation(bpmnElement.getId()); + implementationAttr = bpmnScanner.getImplementation(bpmnElement.getId()); } - - + + if (bpmnElement instanceof UserTask) { taskDelegate = bpmnScanner.getListener(bpmnElement.getId(), BpmnConstants.ATTR_DEL, BpmnConstants.CAMUNDA_TASKLISTENER); @@ -195,9 +190,7 @@ else if (implementationAttr.equals(BpmnConstants.CAMUNDA_EXT)) { String.format(Messages.getString("JavaDelegateChecker.8"), //$NON-NLS-1$ bpmnElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_NAME)))); } - } - - else if (implementationAttr.equals(BpmnConstants.IMPLEMENTATION)) + } else if (implementationAttr.equals(BpmnConstants.IMPLEMENTATION)) if (dmnAttr == null && classAttr == null && delegateExprAttr == null && exprAttr == null && typeAttr == null) { // No technical attributes have been added @@ -273,7 +266,7 @@ else if (implementationAttr.equals(BpmnConstants.IMPLEMENTATION)) * @return issues */ private Collection checkListener(final BpmnElement element, ArrayList aClass, - ArrayList aDelegate, ArrayList aExpression, boolean taskListener) { + ArrayList aDelegate, ArrayList aExpression, boolean taskListener) { final Collection issues = new ArrayList(); String location = ""; //$NON-NLS-1$ if (taskListener) @@ -346,7 +339,7 @@ private Collection checkListener(final BpmnElement element, ArrayL * @return issues */ private Collection checkClassFile(final BpmnElement element, final String className, - final boolean listener, final boolean taskListener) { + final boolean listener, final boolean taskListener) { final Collection issues = new ArrayList(); final BaseElement bpmnElement = element.getBaseElement(); @@ -386,7 +379,7 @@ private Collection checkClassFile(final BpmnElement element, final interfaceImplemented = true; if (_interface.getName().contains(BpmnConstants.INTERFACE_ACTIVITY_BEHAVIOUR) && !_interface.getName() - .contains(BpmnConstants.INTERFACE_SIGNALLABLE_ACTIVITY_BEHAVIOR)) { + .contains(BpmnConstants.INTERFACE_SIGNALLABLE_ACTIVITY_BEHAVIOR)) { // ActivityBehavior is not a very good practice and should be avoided as much as possible issues.add( IssueWriter.createIssueWithClassPath(rule, CriticalityEnum.INFO, classPath, element, diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/MessageEventChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/MessageEventChecker.java index 99f4a369..f96edab4 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/MessageEventChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/MessageEventChecker.java @@ -1,186 +1,185 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.util.ArrayList; -import java.util.Collection; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.Event; -import org.camunda.bpm.model.bpmn.instance.Message; -import org.camunda.bpm.model.bpmn.instance.MessageEventDefinition; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.Messages; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.output.IssueWriter; -import de.viadee.bpm.vPAV.processing.CheckName; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; -import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; - -public class MessageEventChecker extends AbstractElementChecker { - - public MessageEventChecker(final Rule rule, final BpmnScanner bpmnScanner) { - super(rule, bpmnScanner); - } - - /** - * Check MessageEvents for implementation and messages - * - * @return issues - */ - @Override - public Collection check(BpmnElement element) { - - final Collection issues = new ArrayList(); - final BaseElement baseElement = element.getBaseElement(); - - if (baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_END_EVENT) - || baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_INTERMEDIATE_CATCH_EVENT) - || baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_INTERMEDIATE_THROW_EVENT) - || baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_BOUNDARY_EVENT)) { - - checkEventsInSubProcess(element, issues, baseElement); - } else if (baseElement.getElementType().getTypeName().equals(BpmnModelConstants.BPMN_ELEMENT_RECEIVE_TASK)) { - - if (baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_MESSAGE_REF) == null - || baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_MESSAGE_REF).isEmpty()) { - - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("MessageEventChecker.0"), CheckName.checkName(baseElement)))); //$NON-NLS-1$ - - } else { - if (bpmnScanner.getMessageName( - baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_MESSAGE_REF)) == null - || bpmnScanner - .getMessageName( - baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_MESSAGE_REF)) - .isEmpty()) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("MessageEventChecker.1"), //$NON-NLS-1$ - CheckName.checkName(baseElement)))); - } - } - } else if (baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_START_EVENT)) { - - // Depending on whether the startEvent is part of a subprocess, expressions may be allowed to exist - if (bpmnScanner.checkStartEvent(baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_ID))) { - checkEventsInSubProcess(element, issues, baseElement); - } else { - checkEventsInProcess(element, issues, baseElement); - } - } - return issues; - } - - /** - * Checks for existence of messages in startEvents. Expressions will create an issue due to write/read anomaly - * - * @param element - * BpmnElement - * @param issues - * Collection of CheckerIssues - * @param baseElement - * BaseElement - */ - private void checkEventsInProcess(BpmnElement element, final Collection issues, - final BaseElement baseElement) { - final Event event = (Event) baseElement; - final Collection messageEventDefinitions = event - .getChildElementsByType(MessageEventDefinition.class); - if (messageEventDefinitions != null) { - for (MessageEventDefinition eventDef : messageEventDefinitions) { - if (eventDef != null) { - final Message message = eventDef.getMessage(); - if (message == null) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("MessageEventChecker.2"), //$NON-NLS-1$ - CheckName.checkName(baseElement)))); - } else { - if (message.getName() == null || message.getName().isEmpty()) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("MessageEventChecker.3"), //$NON-NLS-1$ - CheckName.checkName(baseElement)))); - } else if (message.getName().contains("{") || message.getName().contains("}")) { //$NON-NLS-1$ //$NON-NLS-2$ - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("MessageEventChecker.6"), //$NON-NLS-1$ - CheckName.checkName(baseElement)))); - } - } - } - } - } - } - - /** - * Checks for existence of messages and expression in startEvents - * - * @param element - * BpmnElement - * @param issues - * Collection of CheckerIssues - * @param baseElement - * BaseElement - */ - private void checkEventsInSubProcess(BpmnElement element, final Collection issues, - final BaseElement baseElement) { - final Event event = (Event) baseElement; - final Collection messageEventDefinitions = event - .getChildElementsByType(MessageEventDefinition.class); - if (messageEventDefinitions != null) { - for (MessageEventDefinition eventDef : messageEventDefinitions) { - if (eventDef != null) { - final Message message = eventDef.getMessage(); - if (message == null) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("MessageEventChecker.7"), //$NON-NLS-1$ - CheckName.checkName(baseElement)))); - } else { - if (message.getName() == null || message.getName().isEmpty()) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("MessageEventChecker.8"), //$NON-NLS-1$ - CheckName.checkName(baseElement)))); - } - } - } - } - } - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.Messages; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.output.IssueWriter; +import de.viadee.bpm.vPAV.processing.CheckName; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.Event; +import org.camunda.bpm.model.bpmn.instance.Message; +import org.camunda.bpm.model.bpmn.instance.MessageEventDefinition; + +import java.util.ArrayList; +import java.util.Collection; + +public class MessageEventChecker extends AbstractElementChecker { + + public MessageEventChecker(final Rule rule, final BpmnScanner bpmnScanner) { + super(rule, bpmnScanner); + } + + /** + * Check MessageEvents for implementation and messages + * + * @return issues + */ + @Override + public Collection check(BpmnElement element) { + + final Collection issues = new ArrayList(); + final BaseElement baseElement = element.getBaseElement(); + + if (baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_END_EVENT) + || baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_INTERMEDIATE_CATCH_EVENT) + || baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_INTERMEDIATE_THROW_EVENT) + || baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_BOUNDARY_EVENT)) { + + checkEventsInSubProcess(element, issues, baseElement); + } else if (baseElement.getElementType().getTypeName().equals(BpmnModelConstants.BPMN_ELEMENT_RECEIVE_TASK)) { + + if (baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_MESSAGE_REF) == null + || baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_MESSAGE_REF).isEmpty()) { + + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("MessageEventChecker.0"), CheckName.checkName(baseElement)))); //$NON-NLS-1$ + + } else { + if (bpmnScanner.getMessageName( + baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_MESSAGE_REF)) == null + || bpmnScanner + .getMessageName( + baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_MESSAGE_REF)) + .isEmpty()) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("MessageEventChecker.1"), //$NON-NLS-1$ + CheckName.checkName(baseElement)))); + } + } + } else if (baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_START_EVENT)) { + + // Depending on whether the startEvent is part of a subprocess, expressions may be allowed to exist + if (bpmnScanner.checkStartEvent(baseElement.getAttributeValue(BpmnModelConstants.BPMN_ATTRIBUTE_ID))) { + checkEventsInSubProcess(element, issues, baseElement); + } else { + checkEventsInProcess(element, issues, baseElement); + } + } + return issues; + } + + /** + * Checks for existence of messages in startEvents. Expressions will create an issue due to write/read anomaly + * + * @param element + * BpmnElement + * @param issues + * Collection of CheckerIssues + * @param baseElement + * BaseElement + */ + private void checkEventsInProcess(BpmnElement element, final Collection issues, + final BaseElement baseElement) { + final Event event = (Event) baseElement; + final Collection messageEventDefinitions = event + .getChildElementsByType(MessageEventDefinition.class); + if (messageEventDefinitions != null) { + for (MessageEventDefinition eventDef : messageEventDefinitions) { + if (eventDef != null) { + final Message message = eventDef.getMessage(); + if (message == null) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("MessageEventChecker.2"), //$NON-NLS-1$ + CheckName.checkName(baseElement)))); + } else { + if (message.getName() == null || message.getName().isEmpty()) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("MessageEventChecker.3"), //$NON-NLS-1$ + CheckName.checkName(baseElement)))); + } else if (message.getName().contains("{") || message.getName().contains("}")) { //$NON-NLS-1$ //$NON-NLS-2$ + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("MessageEventChecker.6"), //$NON-NLS-1$ + CheckName.checkName(baseElement)))); + } + } + } + } + } + } + + /** + * Checks for existence of messages and expression in startEvents + * + * @param element + * BpmnElement + * @param issues + * Collection of CheckerIssues + * @param baseElement + * BaseElement + */ + private void checkEventsInSubProcess(BpmnElement element, final Collection issues, + final BaseElement baseElement) { + final Event event = (Event) baseElement; + final Collection messageEventDefinitions = event + .getChildElementsByType(MessageEventDefinition.class); + if (messageEventDefinitions != null) { + for (MessageEventDefinition eventDef : messageEventDefinitions) { + if (eventDef != null) { + final Message message = eventDef.getMessage(); + if (message == null) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("MessageEventChecker.7"), //$NON-NLS-1$ + CheckName.checkName(baseElement)))); + } else { + if (message.getName() == null || message.getName().isEmpty()) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("MessageEventChecker.8"), //$NON-NLS-1$ + CheckName.checkName(baseElement)))); + } + } + } + } + } + } + +} diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ModelChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ModelChecker.java index ef990c4b..2638eb34 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ModelChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ModelChecker.java @@ -31,11 +31,10 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.Collection; - +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import java.util.Collection; /** * Checks, which concern the whole model diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/NoExpressionChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/NoExpressionChecker.java index 84d298f8..3a76046a 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/NoExpressionChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/NoExpressionChecker.java @@ -1,189 +1,177 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; - -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.BusinessRuleTask; -import org.camunda.bpm.model.bpmn.instance.EndEvent; -import org.camunda.bpm.model.bpmn.instance.ExclusiveGateway; -import org.camunda.bpm.model.bpmn.instance.IntermediateThrowEvent; -import org.camunda.bpm.model.bpmn.instance.ManualTask; -import org.camunda.bpm.model.bpmn.instance.ScriptTask; -import org.camunda.bpm.model.bpmn.instance.SendTask; -import org.camunda.bpm.model.bpmn.instance.SequenceFlow; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.camunda.bpm.model.bpmn.instance.StartEvent; -import org.camunda.bpm.model.bpmn.instance.UserTask; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.constants.BpmnConstants; -import de.viadee.bpm.vPAV.output.IssueWriter; -import de.viadee.bpm.vPAV.processing.CheckName; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; -import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; - -public class NoExpressionChecker extends AbstractElementChecker { - - public NoExpressionChecker(final Rule rule, final BpmnScanner bpmnScanner) { - super(rule, bpmnScanner); - } - - /** - * Check if ServiceTasks, BusinessRuleTasks, SendTasks and ScriptTasks use expressions against best practices - * - * @return issues - */ - @Override - public Collection check(BpmnElement element) { - - final Collection issues = new ArrayList(); - final BaseElement baseElement = element.getBaseElement(); - - - final Map settings = rule.getSettings(); - - if (baseElement instanceof ServiceTask || baseElement instanceof BusinessRuleTask - || baseElement instanceof SendTask || baseElement instanceof ScriptTask) { - - // read attributes from task - final String implementationAttr = bpmnScanner.getImplementation(baseElement.getId()); - - if (implementationAttr != null && implementationAttr.equals(BpmnConstants.CAMUNDA_EXPRESSION) - && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, - String.format("Usage of expressions in '%s' is against best practices.", - CheckName.checkName(baseElement)))); - } - - // get the execution listener - final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, - BpmnConstants.CAMUNDA_EXECUTIONLISTENER); - - if (!listener.isEmpty() && listener.size() > 0 - && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { - addIssue(element, issues, baseElement); - } - - } else if (baseElement instanceof IntermediateThrowEvent - || baseElement instanceof EndEvent || baseElement instanceof StartEvent) { - - // read attributes from event - final String implementationAttrEvent = bpmnScanner.getEventImplementation(baseElement.getId()); - - if (implementationAttrEvent != null && implementationAttrEvent.contains(BpmnConstants.CAMUNDA_EXPRESSION) - && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, - String.format("Usage of expression in event '%s' is against best practices.", - CheckName.checkName(baseElement)))); - } - - // get the execution listener - final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, - BpmnConstants.CAMUNDA_EXECUTIONLISTENER); - - if (!listener.isEmpty() && listener.size() > 0 - && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { - addIssue(element, issues, baseElement); - } - - } else if (baseElement instanceof SequenceFlow) { - - // get the execution listener - final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, - BpmnConstants.CAMUNDA_EXECUTIONLISTENER); - if (!listener.isEmpty() - && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { - addIssue(element, issues, baseElement); - } - - } else if (baseElement instanceof ExclusiveGateway) { - // get the execution listener - final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, - BpmnConstants.CAMUNDA_EXECUTIONLISTENER); - if (!listener.isEmpty() - && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { - addIssue(element, issues, baseElement); - } - } else if (baseElement instanceof UserTask) { - // get the execution listener - final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, - BpmnConstants.CAMUNDA_EXECUTIONLISTENER); - if (!listener.isEmpty() - && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { - addIssue(element, issues, baseElement); - } - - // get the task listener - final ArrayList taskListener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, - BpmnConstants.CAMUNDA_EXECUTIONLISTENER); - if (!taskListener.isEmpty() - && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { - addIssue(element, issues, baseElement); - } - - } else if (baseElement instanceof ManualTask) { - // get the execution listener - final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, - BpmnConstants.CAMUNDA_EXECUTIONLISTENER); - if (!listener.isEmpty() - && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { - addIssue(element, issues, baseElement); - } - } - - return issues; - } - - /** - * Adds an issue to the collection - * - * @param element - * BpmnElement to be added - * @param issues - * Collection of issues - * @param baseElement - * BaseElement - */ - private void addIssue(BpmnElement element, final Collection issues, final BaseElement baseElement) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, - String.format("Usage of expression in listeners for '%s' is against best practices.", - CheckName.checkName(baseElement)))); - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.constants.BpmnConstants; +import de.viadee.bpm.vPAV.output.IssueWriter; +import de.viadee.bpm.vPAV.processing.CheckName; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.instance.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; + +public class NoExpressionChecker extends AbstractElementChecker { + + public NoExpressionChecker(final Rule rule, final BpmnScanner bpmnScanner) { + super(rule, bpmnScanner); + } + + /** + * Check if ServiceTasks, BusinessRuleTasks, SendTasks and ScriptTasks use expressions against best practices + * + * @return issues + */ + @Override + public Collection check(BpmnElement element) { + + final Collection issues = new ArrayList(); + final BaseElement baseElement = element.getBaseElement(); + + + final Map settings = rule.getSettings(); + + if (baseElement instanceof ServiceTask || baseElement instanceof BusinessRuleTask + || baseElement instanceof SendTask || baseElement instanceof ScriptTask) { + + // read attributes from task + final String implementationAttr = bpmnScanner.getImplementation(baseElement.getId()); + + if (implementationAttr != null && implementationAttr.equals(BpmnConstants.CAMUNDA_EXPRESSION) + && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, + String.format("Usage of expressions in '%s' is against best practices.", + CheckName.checkName(baseElement)))); + } + + // get the execution listener + final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, + BpmnConstants.CAMUNDA_EXECUTIONLISTENER); + + if (!listener.isEmpty() && listener.size() > 0 + && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { + addIssue(element, issues, baseElement); + } + + } else if (baseElement instanceof IntermediateThrowEvent + || baseElement instanceof EndEvent || baseElement instanceof StartEvent) { + + // read attributes from event + final String implementationAttrEvent = bpmnScanner.getEventImplementation(baseElement.getId()); + + if (implementationAttrEvent != null && implementationAttrEvent.contains(BpmnConstants.CAMUNDA_EXPRESSION) + && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, + String.format("Usage of expression in event '%s' is against best practices.", + CheckName.checkName(baseElement)))); + } + + // get the execution listener + final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, + BpmnConstants.CAMUNDA_EXECUTIONLISTENER); + + if (!listener.isEmpty() && listener.size() > 0 + && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { + addIssue(element, issues, baseElement); + } + + } else if (baseElement instanceof SequenceFlow) { + + // get the execution listener + final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, + BpmnConstants.CAMUNDA_EXECUTIONLISTENER); + if (!listener.isEmpty() + && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { + addIssue(element, issues, baseElement); + } + + } else if (baseElement instanceof ExclusiveGateway) { + // get the execution listener + final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, + BpmnConstants.CAMUNDA_EXECUTIONLISTENER); + if (!listener.isEmpty() + && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { + addIssue(element, issues, baseElement); + } + } else if (baseElement instanceof UserTask) { + // get the execution listener + final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, + BpmnConstants.CAMUNDA_EXECUTIONLISTENER); + if (!listener.isEmpty() + && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { + addIssue(element, issues, baseElement); + } + + // get the task listener + final ArrayList taskListener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, + BpmnConstants.CAMUNDA_EXECUTIONLISTENER); + if (!taskListener.isEmpty() + && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { + addIssue(element, issues, baseElement); + } + + } else if (baseElement instanceof ManualTask) { + // get the execution listener + final ArrayList listener = bpmnScanner.getListener(baseElement.getId(), BpmnConstants.ATTR_EX, + BpmnConstants.CAMUNDA_EXECUTIONLISTENER); + if (!listener.isEmpty() + && !settings.containsKey(baseElement.getElementType().getInstanceType().getSimpleName())) { + addIssue(element, issues, baseElement); + } + } + + return issues; + } + + /** + * Adds an issue to the collection + * + * @param element + * BpmnElement to be added + * @param issues + * Collection of issues + * @param baseElement + * BaseElement + */ + private void addIssue(BpmnElement element, final Collection issues, final BaseElement baseElement) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.WARNING, element, + String.format("Usage of expression in listeners for '%s' is against best practices.", + CheckName.checkName(baseElement)))); + } + +} diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/NoScriptChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/NoScriptChecker.java index 5c69b59b..4ab57cfe 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/NoScriptChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/NoScriptChecker.java @@ -31,16 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.ScriptTask; -import org.camunda.bpm.model.bpmn.instance.SequenceFlow; -import org.camunda.bpm.model.bpmn.instance.SubProcess; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.Messages; import de.viadee.bpm.vPAV.config.model.Rule; @@ -51,6 +41,15 @@ import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.ScriptTask; +import org.camunda.bpm.model.bpmn.instance.SequenceFlow; +import org.camunda.bpm.model.bpmn.instance.SubProcess; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; public class NoScriptChecker extends AbstractElementChecker { diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/OverlapChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/OverlapChecker.java index 05158c46..86ff8759 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/OverlapChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/OverlapChecker.java @@ -1,110 +1,109 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.SequenceFlow; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.Messages; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.output.IssueWriter; -import de.viadee.bpm.vPAV.processing.CheckName; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; -import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; - -public class OverlapChecker extends AbstractElementChecker { - - public OverlapChecker(final Rule rule, final BpmnScanner bpmnScanner) { - super(rule, bpmnScanner); - } - - private Map> sequenceFlowList = new HashMap<>(); - - /** - * Check for redundant edges between common elements (double or more flows instead of one) - * - * @return issues - */ - - @Override - public Collection check(BpmnElement element) { - final Collection issues = new ArrayList(); - final BaseElement bpmnElement = element.getBaseElement(); - - if (bpmnElement instanceof SequenceFlow) { - - final ArrayList sequenceFlowDef = bpmnScanner.getSequenceFlowDef(bpmnElement.getId()); - - if (getSequenceFlowList().isEmpty()) { - addToSequenceFlowList(bpmnElement.getId(), sequenceFlowDef); - } - - for (Map.Entry> entry : getSequenceFlowList().entrySet()) { - // Check whether targetRef & sourceRef of current item exist in global list - if (sequenceFlowDef.equals(entry.getValue()) && !bpmnElement.getId().equals(entry.getKey())) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format( - Messages.getString("OverlapChecker.0"), //$NON-NLS-1$ - CheckName.checkName(bpmnElement)))); - return issues; - } - } - - if (!getSequenceFlowList().containsKey(bpmnElement.getId())) { - addToSequenceFlowList(bpmnElement.getId(), sequenceFlowDef); - } - - } - - return issues; - } - - public Map> getSequenceFlowList() { - return sequenceFlowList; - } - - public void addToSequenceFlowList(String id, ArrayList sequenceFlowList) { - this.sequenceFlowList.put(id, sequenceFlowList); - } - - public void resetSequenceFlowList() { - this.sequenceFlowList.clear(); - } - +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.Messages; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.output.IssueWriter; +import de.viadee.bpm.vPAV.processing.CheckName; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.SequenceFlow; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class OverlapChecker extends AbstractElementChecker { + + public OverlapChecker(final Rule rule, final BpmnScanner bpmnScanner) { + super(rule, bpmnScanner); + } + + private Map> sequenceFlowList = new HashMap<>(); + + /** + * Check for redundant edges between common elements (double or more flows instead of one) + * + * @return issues + */ + + @Override + public Collection check(BpmnElement element) { + final Collection issues = new ArrayList(); + final BaseElement bpmnElement = element.getBaseElement(); + + if (bpmnElement instanceof SequenceFlow) { + + final ArrayList sequenceFlowDef = bpmnScanner.getSequenceFlowDef(bpmnElement.getId()); + + if (getSequenceFlowList().isEmpty()) { + addToSequenceFlowList(bpmnElement.getId(), sequenceFlowDef); + } + + for (Map.Entry> entry : getSequenceFlowList().entrySet()) { + // Check whether targetRef & sourceRef of current item exist in global list + if (sequenceFlowDef.equals(entry.getValue()) && !bpmnElement.getId().equals(entry.getKey())) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format( + Messages.getString("OverlapChecker.0"), //$NON-NLS-1$ + CheckName.checkName(bpmnElement)))); + return issues; + } + } + + if (!getSequenceFlowList().containsKey(bpmnElement.getId())) { + addToSequenceFlowList(bpmnElement.getId(), sequenceFlowDef); + } + + } + + return issues; + } + + public Map> getSequenceFlowList() { + return sequenceFlowList; + } + + public void addToSequenceFlowList(String id, ArrayList sequenceFlowList) { + this.sequenceFlowList.put(id, sequenceFlowList); + } + + public void resetSequenceFlowList() { + this.sequenceFlowList.clear(); + } + } \ No newline at end of file diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelChecker.java index 8863b6c7..5783122a 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelChecker.java @@ -31,20 +31,18 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import de.viadee.bpm.vPAV.processing.model.data.*; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; - import de.viadee.bpm.vPAV.Messages; import de.viadee.bpm.vPAV.config.model.Rule; import de.viadee.bpm.vPAV.output.IssueWriter; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import de.viadee.bpm.vPAV.processing.model.data.*; import de.viadee.bpm.vPAV.processing.model.graph.Path; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; public class ProcessVariablesModelChecker implements ModelChecker { diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesNameConventionChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesNameConventionChecker.java index 267e6fe9..985035d4 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesNameConventionChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesNameConventionChecker.java @@ -31,11 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.ArrayList; -import java.util.Collection; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.Messages; import de.viadee.bpm.vPAV.config.model.ElementConvention; @@ -43,7 +38,11 @@ import de.viadee.bpm.vPAV.config.model.Rule; import de.viadee.bpm.vPAV.output.IssueWriter; import de.viadee.bpm.vPAV.processing.model.data.*; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class ProcessVariablesNameConventionChecker extends AbstractElementChecker { diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/SignalEventChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/SignalEventChecker.java index 90cab49f..5afcc2c7 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/SignalEventChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/SignalEventChecker.java @@ -1,146 +1,145 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.Event; -import org.camunda.bpm.model.bpmn.instance.Signal; -import org.camunda.bpm.model.bpmn.instance.SignalEventDefinition; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.Messages; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.output.IssueWriter; -import de.viadee.bpm.vPAV.processing.CheckName; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; -import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; - -public class SignalEventChecker extends AbstractElementChecker { - - private Map signalNames = new HashMap<>(); - - public SignalEventChecker(Rule rule, BpmnScanner bpmnScanner) { - super(rule, bpmnScanner); - } - - @Override - public Collection check(BpmnElement element) { - final Collection issues = new ArrayList(); - final BaseElement baseElement = element.getBaseElement(); - - if (baseElement.getElementType().getTypeName().equals(BpmnModelConstants.BPMN_ELEMENT_START_EVENT) - || baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_END_EVENT) - || baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_INTERMEDIATE_CATCH_EVENT) - || baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_INTERMEDIATE_THROW_EVENT) - || baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_BOUNDARY_EVENT)) { - - final Event event = (Event) baseElement; - final Collection signalEventDefinitions = event - .getChildElementsByType(SignalEventDefinition.class); - if (signalEventDefinitions != null) { - for (SignalEventDefinition eventDef : signalEventDefinitions) { - if (eventDef != null) { - final Signal signal = eventDef.getSignal(); - if (signal == null) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("SignalEventChecker.0"), //$NON-NLS-1$ - CheckName.checkName(baseElement)))); - } else { - if (signal.getName() == null || signal.getName().isEmpty()) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("SignalEventChecker.1"), //$NON-NLS-1$ - CheckName.checkName(baseElement)))); - } else if (baseElement.getElementType().getTypeName() - .equals(BpmnModelConstants.BPMN_ELEMENT_START_EVENT)) { - issues.addAll(checkDoubleUsage(element, baseElement, signal)); - } - } - } - } - } - - } - - return issues; - } - - /** - * Check for multiple usage of the same signal name - * - * @param element - * @param baseElement - * @param signal - * @return - */ - private Collection checkDoubleUsage(final BpmnElement element, final BaseElement baseElement, - final Signal signal) { - - final Collection issues = new ArrayList(); - - if (!addSignal(baseElement, signal.getName())) { - issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, - String.format(Messages.getString("SignalEventChecker.2"), //$NON-NLS-1$ - CheckName.checkName(baseElement), - CheckName.checkName(getSignal(signal.getName()))))); - } - return issues; - } - - public boolean addSignal(final BaseElement baseElement, final String name) { - if (!signalNames.containsKey(name)) { - signalNames.put(name, baseElement); - return true; - } else { - return false; - } - } - - public BaseElement getSignal(final String name) { - return signalNames.get(name); - } - - public void removeElement(final String name) { - signalNames.remove(name); - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.Messages; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.output.IssueWriter; +import de.viadee.bpm.vPAV.processing.CheckName; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.Event; +import org.camunda.bpm.model.bpmn.instance.Signal; +import org.camunda.bpm.model.bpmn.instance.SignalEventDefinition; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class SignalEventChecker extends AbstractElementChecker { + + private Map signalNames = new HashMap<>(); + + public SignalEventChecker(Rule rule, BpmnScanner bpmnScanner) { + super(rule, bpmnScanner); + } + + @Override + public Collection check(BpmnElement element) { + final Collection issues = new ArrayList(); + final BaseElement baseElement = element.getBaseElement(); + + if (baseElement.getElementType().getTypeName().equals(BpmnModelConstants.BPMN_ELEMENT_START_EVENT) + || baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_END_EVENT) + || baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_INTERMEDIATE_CATCH_EVENT) + || baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_INTERMEDIATE_THROW_EVENT) + || baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_BOUNDARY_EVENT)) { + + final Event event = (Event) baseElement; + final Collection signalEventDefinitions = event + .getChildElementsByType(SignalEventDefinition.class); + if (signalEventDefinitions != null) { + for (SignalEventDefinition eventDef : signalEventDefinitions) { + if (eventDef != null) { + final Signal signal = eventDef.getSignal(); + if (signal == null) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("SignalEventChecker.0"), //$NON-NLS-1$ + CheckName.checkName(baseElement)))); + } else { + if (signal.getName() == null || signal.getName().isEmpty()) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("SignalEventChecker.1"), //$NON-NLS-1$ + CheckName.checkName(baseElement)))); + } else if (baseElement.getElementType().getTypeName() + .equals(BpmnModelConstants.BPMN_ELEMENT_START_EVENT)) { + issues.addAll(checkDoubleUsage(element, baseElement, signal)); + } + } + } + } + } + + } + + return issues; + } + + /** + * Check for multiple usage of the same signal name + * + * @param element + * @param baseElement + * @param signal + * @return + */ + private Collection checkDoubleUsage(final BpmnElement element, final BaseElement baseElement, + final Signal signal) { + + final Collection issues = new ArrayList(); + + if (!addSignal(baseElement, signal.getName())) { + issues.addAll(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, + String.format(Messages.getString("SignalEventChecker.2"), //$NON-NLS-1$ + CheckName.checkName(baseElement), + CheckName.checkName(getSignal(signal.getName()))))); + } + return issues; + } + + public boolean addSignal(final BaseElement baseElement, final String name) { + if (!signalNames.containsKey(name)) { + signalNames.put(name, baseElement); + return true; + } else { + return false; + } + } + + public BaseElement getSignal(final String name) { + return signalNames.get(name); + } + + public void removeElement(final String name) { + signalNames.remove(name); + } + +} diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/TaskNamingConventionChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/TaskNamingConventionChecker.java index 806ea949..cc58b938 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/TaskNamingConventionChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/TaskNamingConventionChecker.java @@ -31,15 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.ArrayList; -import java.util.Collection; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.Task; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.Messages; import de.viadee.bpm.vPAV.config.model.ElementConvention; @@ -49,6 +40,14 @@ import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.Task; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class TaskNamingConventionChecker extends AbstractElementChecker { diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/TimerExpressionChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/TimerExpressionChecker.java index a7aa4df3..c9406cad 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/TimerExpressionChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/TimerExpressionChecker.java @@ -1,213 +1,210 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.bind.DatatypeConverter; -import javax.xml.datatype.DatatypeFactory; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.BoundaryEvent; -import org.camunda.bpm.model.bpmn.instance.IntermediateCatchEvent; -import org.camunda.bpm.model.bpmn.instance.StartEvent; -import org.w3c.dom.Element; - -import com.cronutils.model.Cron; -import com.cronutils.model.CronType; -import com.cronutils.model.definition.CronDefinition; -import com.cronutils.model.definition.CronDefinitionBuilder; -import com.cronutils.parser.CronParser; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.Messages; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.output.IssueWriter; -import de.viadee.bpm.vPAV.processing.CheckName; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; -import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; -import net.time4j.range.IsoRecurrence; -import net.time4j.range.MomentInterval; - -public class TimerExpressionChecker extends AbstractElementChecker { - - public TimerExpressionChecker(final Rule rule, final BpmnScanner bpmnScanner) { - super(rule, bpmnScanner); - } - - /** - * Check TimerEvents for correct usage of ISO 8601 and CRON definitions - * - * @return issues - */ - @Override - public Collection check(final BpmnElement element) { - - final BaseElement baseElement = element.getBaseElement(); - final Collection issues = new ArrayList(); - - // Map with string (contains the timer definiton) and the element itself (contains name and id) - Map list = new HashMap<>(); - - // check if the element is an event and retrieve id - if (baseElement.getId() != null && (baseElement instanceof IntermediateCatchEvent - || baseElement instanceof StartEvent || baseElement instanceof BoundaryEvent)) { - - list = bpmnScanner.getTimerImplementation(baseElement.getId()); - String timerDefinition; - - for (Map.Entry entry : list.entrySet()) { - - if (entry.getValue() != null) { - timerDefinition = entry.getValue().getParentNode().getTextContent().trim(); - } else { - timerDefinition = ""; //$NON-NLS-1$ - } - - if (timerDefinition != null && !timerDefinition.trim().isEmpty()) { - - // BpmnModelConstants.BPMN_ELEMENT_TIME_DATE - if (entry.getValue() != null && (entry.getValue().getNodeName() != null - && entry.getValue().getNodeName().contains(BpmnModelConstants.BPMN_ELEMENT_TIME_DATE))) { - try { - DatatypeConverter.parseDateTime(timerDefinition); - } catch (Exception e) { - issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, - String.format(Messages.getString("TimerExpressionChecker.1"), //$NON-NLS-1$ - CheckName.checkTimer(entry.getKey())))); - } - } - // BpmnModelConstants.BPMN_ELEMENT_TIME_DURATION - if (entry.getValue() != null && (entry.getValue().getNodeName() != null - && entry.getValue().getNodeName() - .contains(BpmnModelConstants.BPMN_ELEMENT_TIME_DURATION))) { - try { - DatatypeFactory.newInstance().newDuration(timerDefinition); - } catch (Exception e) { - issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, - String.format( - Messages.getString("TimerExpressionChecker.2"), //$NON-NLS-1$ - CheckName.checkTimer(entry.getKey())))); - } - } - // BpmnModelConstants.BPMN_ELEMENT_TIME_CYCLE - if (entry.getValue() != null && (entry.getValue().getNodeName() != null - && entry.getValue().getNodeName().contains(BpmnModelConstants.BPMN_ELEMENT_TIME_CYCLE))) { - - boolean isCron = false; - boolean isDur = false; - boolean hasRepeatingIntervals = false; - - if (!timerDefinition.contains("P") && !timerDefinition.contains("Z") //$NON-NLS-1$ //$NON-NLS-2$ - && timerDefinition.contains(" ")) { //$NON-NLS-1$ - isCron = true; - } - - if (timerDefinition.startsWith("R")) { //$NON-NLS-1$ - hasRepeatingIntervals = true; - } - - if (timerDefinition.startsWith("P") //$NON-NLS-1$ - && !(timerDefinition.contains("/") || timerDefinition.contains("--"))) { //$NON-NLS-1$ //$NON-NLS-2$ - isDur = true; - } - - if (isCron) { - try { - CronDefinition cronDef = CronDefinitionBuilder - .instanceDefinitionFor(CronType.QUARTZ); - CronParser cronParser = new CronParser(cronDef); - Cron cronJob = cronParser.parse(timerDefinition); - cronJob.validate(); - } catch (IllegalArgumentException e) { - issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, - String.format(Messages.getString("TimerExpressionChecker.10"), //$NON-NLS-1$ - CheckName.checkTimer(entry.getKey())))); - } - } - - if (!isCron && !hasRepeatingIntervals && !isDur) { - try { - MomentInterval.parseISO(timerDefinition); - } catch (ParseException e) { - issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, - String.format( - Messages.getString("TimerExpressionChecker.11"), //$NON-NLS-1$ - CheckName.checkTimer(entry.getKey())))); - } - } - - if (!isCron && hasRepeatingIntervals && !isDur) { - try { - IsoRecurrence.parseMomentIntervals(timerDefinition); - } catch (ParseException ex) { - issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, - String.format( - Messages.getString("TimerExpressionChecker.12"), //$NON-NLS-1$ - CheckName.checkTimer(entry.getKey())))); - } - } - - if (isDur && !isCron && !hasRepeatingIntervals) { - try { - DatatypeFactory.newInstance().newDuration(timerDefinition); - } catch (Exception ex) { - issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, - String.format( - Messages.getString("TimerExpressionChecker.13"), //$NON-NLS-1$ - CheckName.checkTimer(entry.getKey())))); - } - } - } - - } else if (entry.getValue() == null || entry.getValue().getLocalName() == null - || entry.getValue().getLocalName().isEmpty()) { - issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, - String.format(Messages.getString("TimerExpressionChecker.14"), //$NON-NLS-1$ - CheckName.checkTimer(entry.getKey())))); - } else if (timerDefinition == null || timerDefinition.trim().isEmpty()) { - issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, - String.format(Messages.getString("TimerExpressionChecker.15"), //$NON-NLS-1$ - CheckName.checkTimer(entry.getKey())))); - } - } - } - - return issues; - } -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import com.cronutils.model.Cron; +import com.cronutils.model.CronType; +import com.cronutils.model.definition.CronDefinition; +import com.cronutils.model.definition.CronDefinitionBuilder; +import com.cronutils.parser.CronParser; +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.Messages; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.output.IssueWriter; +import de.viadee.bpm.vPAV.processing.CheckName; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import net.time4j.range.IsoRecurrence; +import net.time4j.range.MomentInterval; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.BoundaryEvent; +import org.camunda.bpm.model.bpmn.instance.IntermediateCatchEvent; +import org.camunda.bpm.model.bpmn.instance.StartEvent; +import org.w3c.dom.Element; + +import javax.xml.bind.DatatypeConverter; +import javax.xml.datatype.DatatypeFactory; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class TimerExpressionChecker extends AbstractElementChecker { + + public TimerExpressionChecker(final Rule rule, final BpmnScanner bpmnScanner) { + super(rule, bpmnScanner); + } + + /** + * Check TimerEvents for correct usage of ISO 8601 and CRON definitions + * + * @return issues + */ + @Override + public Collection check(final BpmnElement element) { + + final BaseElement baseElement = element.getBaseElement(); + final Collection issues = new ArrayList(); + + // Map with string (contains the timer definiton) and the element itself (contains name and id) + Map list = new HashMap<>(); + + // check if the element is an event and retrieve id + if (baseElement.getId() != null && (baseElement instanceof IntermediateCatchEvent + || baseElement instanceof StartEvent || baseElement instanceof BoundaryEvent)) { + + list = bpmnScanner.getTimerImplementation(baseElement.getId()); + String timerDefinition; + + for (Map.Entry entry : list.entrySet()) { + + if (entry.getValue() != null) { + timerDefinition = entry.getValue().getParentNode().getTextContent().trim(); + } else { + timerDefinition = ""; //$NON-NLS-1$ + } + + if (timerDefinition != null && !timerDefinition.trim().isEmpty()) { + + // BpmnModelConstants.BPMN_ELEMENT_TIME_DATE + if (entry.getValue() != null && (entry.getValue().getNodeName() != null + && entry.getValue().getNodeName().contains(BpmnModelConstants.BPMN_ELEMENT_TIME_DATE))) { + try { + DatatypeConverter.parseDateTime(timerDefinition); + } catch (Exception e) { + issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, + String.format(Messages.getString("TimerExpressionChecker.1"), //$NON-NLS-1$ + CheckName.checkTimer(entry.getKey())))); + } + } + // BpmnModelConstants.BPMN_ELEMENT_TIME_DURATION + if (entry.getValue() != null && (entry.getValue().getNodeName() != null + && entry.getValue().getNodeName() + .contains(BpmnModelConstants.BPMN_ELEMENT_TIME_DURATION))) { + try { + DatatypeFactory.newInstance().newDuration(timerDefinition); + } catch (Exception e) { + issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, + String.format( + Messages.getString("TimerExpressionChecker.2"), //$NON-NLS-1$ + CheckName.checkTimer(entry.getKey())))); + } + } + // BpmnModelConstants.BPMN_ELEMENT_TIME_CYCLE + if (entry.getValue() != null && (entry.getValue().getNodeName() != null + && entry.getValue().getNodeName().contains(BpmnModelConstants.BPMN_ELEMENT_TIME_CYCLE))) { + + boolean isCron = false; + boolean isDur = false; + boolean hasRepeatingIntervals = false; + + if (!timerDefinition.contains("P") && !timerDefinition.contains("Z") //$NON-NLS-1$ //$NON-NLS-2$ + && timerDefinition.contains(" ")) { //$NON-NLS-1$ + isCron = true; + } + + if (timerDefinition.startsWith("R")) { //$NON-NLS-1$ + hasRepeatingIntervals = true; + } + + if (timerDefinition.startsWith("P") //$NON-NLS-1$ + && !(timerDefinition.contains("/") || timerDefinition.contains("--"))) { //$NON-NLS-1$ //$NON-NLS-2$ + isDur = true; + } + + if (isCron) { + try { + CronDefinition cronDef = CronDefinitionBuilder + .instanceDefinitionFor(CronType.QUARTZ); + CronParser cronParser = new CronParser(cronDef); + Cron cronJob = cronParser.parse(timerDefinition); + cronJob.validate(); + } catch (IllegalArgumentException e) { + issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, + String.format(Messages.getString("TimerExpressionChecker.10"), //$NON-NLS-1$ + CheckName.checkTimer(entry.getKey())))); + } + } + + if (!isCron && !hasRepeatingIntervals && !isDur) { + try { + MomentInterval.parseISO(timerDefinition); + } catch (ParseException e) { + issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, + String.format( + Messages.getString("TimerExpressionChecker.11"), //$NON-NLS-1$ + CheckName.checkTimer(entry.getKey())))); + } + } + + if (!isCron && hasRepeatingIntervals && !isDur) { + try { + IsoRecurrence.parseMomentIntervals(timerDefinition); + } catch (ParseException ex) { + issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, + String.format( + Messages.getString("TimerExpressionChecker.12"), //$NON-NLS-1$ + CheckName.checkTimer(entry.getKey())))); + } + } + + if (isDur && !isCron && !hasRepeatingIntervals) { + try { + DatatypeFactory.newInstance().newDuration(timerDefinition); + } catch (Exception ex) { + issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, + String.format( + Messages.getString("TimerExpressionChecker.13"), //$NON-NLS-1$ + CheckName.checkTimer(entry.getKey())))); + } + } + } + + } else if (entry.getValue() == null || entry.getValue().getLocalName() == null + || entry.getValue().getLocalName().isEmpty()) { + issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, + String.format(Messages.getString("TimerExpressionChecker.14"), //$NON-NLS-1$ + CheckName.checkTimer(entry.getKey())))); + } else if (timerDefinition == null || timerDefinition.trim().isEmpty()) { + issues.add(IssueWriter.createIssue(rule, CriticalityEnum.ERROR, element, entry, + String.format(Messages.getString("TimerExpressionChecker.15"), //$NON-NLS-1$ + CheckName.checkTimer(entry.getKey())))); + } + } + } + + return issues; + } +} diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/VersioningChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/VersioningChecker.java index eeae85ac..60f46d1d 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/VersioningChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/VersioningChecker.java @@ -31,26 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.el.ELException; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.BusinessRuleTask; -import org.camunda.bpm.model.bpmn.instance.ExtensionElements; -import org.camunda.bpm.model.bpmn.instance.MessageEventDefinition; -import org.camunda.bpm.model.bpmn.instance.ScriptTask; -import org.camunda.bpm.model.bpmn.instance.SendTask; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaExecutionListener; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript; -import org.camunda.bpm.model.bpmn.instance.camunda.CamundaTaskListener; - import de.odysseus.el.tree.IdentifierNode; import de.odysseus.el.tree.Tree; import de.odysseus.el.tree.TreeBuilder; @@ -67,6 +47,14 @@ import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.*; +import org.camunda.bpm.model.bpmn.instance.camunda.CamundaExecutionListener; +import org.camunda.bpm.model.bpmn.instance.camunda.CamundaScript; +import org.camunda.bpm.model.bpmn.instance.camunda.CamundaTaskListener; + +import javax.el.ELException; +import java.util.*; /** * check versioning of the referenced classes, scripts and beans diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/checker/XorConventionChecker.java b/src/main/java/de/viadee/bpm/vPAV/processing/checker/XorConventionChecker.java index e8f71aeb..b8a72d2c 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/checker/XorConventionChecker.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/checker/XorConventionChecker.java @@ -31,18 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.ExclusiveGateway; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.Messages; import de.viadee.bpm.vPAV.config.model.ElementConvention; @@ -55,6 +43,17 @@ import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.CriticalityEnum; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.ExclusiveGateway; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class XorConventionChecker extends AbstractElementChecker { diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/dataflow/ElementBasedPredicateBuilderImpl.java b/src/main/java/de/viadee/bpm/vPAV/processing/dataflow/ElementBasedPredicateBuilderImpl.java index 83bfe008..a7b6c5cf 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/dataflow/ElementBasedPredicateBuilderImpl.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/dataflow/ElementBasedPredicateBuilderImpl.java @@ -38,7 +38,6 @@ import org.camunda.bpm.model.bpmn.instance.ExtensionElements; import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperties; import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperty; -import org.camunda.bpm.model.xml.instance.ModelElementInstance; import java.util.Collection; import java.util.List; diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/dataflow/ProcessVariablePredicateBuilderImpl.java b/src/main/java/de/viadee/bpm/vPAV/processing/dataflow/ProcessVariablePredicateBuilderImpl.java index a1dc21ad..a202f7ba 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/dataflow/ProcessVariablePredicateBuilderImpl.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/dataflow/ProcessVariablePredicateBuilderImpl.java @@ -31,10 +31,10 @@ */ package de.viadee.bpm.vPAV.processing.dataflow; -import java.util.function.Function; - import de.viadee.bpm.vPAV.processing.model.data.ProcessVariable; +import java.util.function.Function; + class ProcessVariablePredicateBuilderImpl implements ProcessVariablePredicateBuilder { private final Function, T> constraintSetter; diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/BpmnElement.java b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/BpmnElement.java index d2ad9017..2364a1a8 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/BpmnElement.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/BpmnElement.java @@ -31,17 +31,10 @@ */ package de.viadee.bpm.vPAV.processing.model.data; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.camunda.bpm.model.bpmn.instance.BaseElement; +import java.util.*; + /** * Represents an BPMN element * diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/CheckerIssue.java b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/CheckerIssue.java index 3ebdd56c..1a5faed3 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/CheckerIssue.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/CheckerIssue.java @@ -31,13 +31,13 @@ */ package de.viadee.bpm.vPAV.processing.model.data; +import de.viadee.bpm.vPAV.processing.model.graph.Path; + import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.List; -import de.viadee.bpm.vPAV.processing.model.graph.Path; - /** * Class for holding issues (errors, warnings, infos) from the checkers. Used to * create an issue which can be represented graphically in the HTML output diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/OutSetCFG.java b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/OutSetCFG.java index e6cc8e7b..4d4d9313 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/OutSetCFG.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/OutSetCFG.java @@ -31,12 +31,12 @@ */ package de.viadee.bpm.vPAV.processing.model.data; +import soot.toolkits.graph.Block; + import java.util.HashMap; import java.util.List; import java.util.Map; -import soot.toolkits.graph.Block; - /** * * helper class storing information for Data-flow analysis algorithm diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/ProcessVariable.java b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/ProcessVariable.java index 19f6fb2e..619331a9 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/ProcessVariable.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/ProcessVariable.java @@ -31,8 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.model.data; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; - import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/VariableBlock.java b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/VariableBlock.java index 16480930..829d79bc 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/model/data/VariableBlock.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/model/data/VariableBlock.java @@ -31,12 +31,12 @@ */ package de.viadee.bpm.vPAV.processing.model.data; +import soot.toolkits.graph.Block; + import java.util.HashMap; import java.util.List; import java.util.Map; -import soot.toolkits.graph.Block; - /** * * helper class storing information for data-flow analysis assigns ProcessVariables to basic blocks of the control-flow diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/Graph.java b/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/Graph.java index dc5be46e..e057d6b5 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/Graph.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/Graph.java @@ -36,23 +36,15 @@ * * A class for a directed graph. Implemented by an adjacency list representation of a graph. */ -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; import de.viadee.bpm.vPAV.constants.BpmnConstants; import de.viadee.bpm.vPAV.processing.model.data.Anomaly; import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.InOutState; +import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; + +import java.util.*; public class Graph implements IGraph { diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/IGraph.java b/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/IGraph.java index f5c774cf..1cb5bed2 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/IGraph.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/IGraph.java @@ -31,17 +31,17 @@ */ package de.viadee.bpm.vPAV.processing.model.graph; +import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; + import java.util.Collection; -/** - * University of Washington, Computer Science & Engineering, Course 373, Winter 2011, Jessica Miller - * - * A basic graph interface. - */ import java.util.List; import java.util.Map; -import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +/* + * University of Washington, Computer Science & Engineering, Course 373, Winter 2011, Jessica Miller + * A basic graph interface. + */ public interface IGraph { diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/Path.java b/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/Path.java index 718fdf3b..5a5bdc38 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/Path.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/Path.java @@ -31,10 +31,10 @@ */ package de.viadee.bpm.vPAV.processing.model.graph; -import java.util.List; - import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import java.util.List; + public class Path { private List elements; diff --git a/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/VertexInfo.java b/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/VertexInfo.java index 5f48f855..5e900961 100644 --- a/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/VertexInfo.java +++ b/src/main/java/de/viadee/bpm/vPAV/processing/model/graph/VertexInfo.java @@ -31,11 +31,11 @@ */ package de.viadee.bpm.vPAV.processing.model.graph; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; + import java.util.HashMap; import java.util.Map; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; - /** * University of Washington, Computer Science and Engineering, Course 373, Winter 2011, Jessica Miller A utility class * that attaches "bookkeeping" information to a vertex. used when searching the graph for a path between two vertices diff --git a/src/test/java/de/viadee/bpm/vPAV/BpmnScannerTest.java b/src/test/java/de/viadee/bpm/vPAV/BpmnScannerTest.java index 157032db..40b56cec 100644 --- a/src/test/java/de/viadee/bpm/vPAV/BpmnScannerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/BpmnScannerTest.java @@ -1,218 +1,216 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.Gateway; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; - -public class BpmnScannerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - /** - * Case: BPMN-Model in Version 1 - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testModelVersionV1() throws SAXException, IOException, ParserConfigurationException { - final String PATH = BASE_PATH + "BPMN_Model_Version_V1.bpmn"; - final String impClass = "camunda:delegateExpression"; - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - BpmnScanner scanner = new BpmnScanner(PATH); - String imp = scanner.getImplementation(element.getBaseElement().getId()); - - assertTrue("Get unexpected implementation", imp.equals(impClass)); - } - - /** - * Case: BPMN-Model in Version 2 - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testModelVersionV2() throws SAXException, IOException, ParserConfigurationException { - final String PATH = BASE_PATH + "BPMN_Model_Version_V2.bpmn"; - final String impEx = "camunda:class"; - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - BpmnScanner scanner = new BpmnScanner(PATH); - String imp = scanner.getImplementation(element.getBaseElement().getId()); - - assertTrue("Get unexpected implementation", imp.equals(impEx)); - } - - /** - * Case: BPMN-Model in Version 3 - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testModelVersionV3() throws SAXException, IOException, ParserConfigurationException { - final String PATH = BASE_PATH + "BPMN_Model_Version_V3.bpmn"; - final String impDel = "camunda:expression"; - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - BpmnScanner scanner = new BpmnScanner(PATH); - String imp = scanner.getImplementation(element.getBaseElement().getId()); - - assertTrue("Get unexpected implementation", imp.equals(impDel)); - } - - /** - * Case: Test getScriptType - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testGetScriptType() throws SAXException, IOException, ParserConfigurationException { - final String PATH = BASE_PATH + "BPMN_Model_Version_V1.bpmn"; - final String scriptType = "inputParameter"; - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - BpmnScanner scanner = new BpmnScanner(PATH); - ArrayList scripts = scanner.getScriptTypes(element.getBaseElement().getId()); - - assertTrue("Get unexpected implementation", scripts.contains(scriptType)); - } - - /** - * Case: Test getXorGateWays - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testGetXorGateWays() throws SAXException, IOException, ParserConfigurationException { - final String PATH = BASE_PATH + "BPMNScannerXorGateway.bpmn"; - final String gatewayId = "ExclusiveGateway_Id"; - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(Gateway.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - BpmnScanner scanner = new BpmnScanner(PATH); - String gwId = scanner.getXorGateWays(element.getBaseElement().getId()); - - assertTrue("Get unexpected Element", gwId.equals(gatewayId)); - } - - /** - * Case: Test getOutgoing - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testGetOutgoing() throws SAXException, IOException, ParserConfigurationException { - final String PATH = BASE_PATH + "BPMNScannerXorGateway.bpmn"; - final int anzOut = 2; - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(Gateway.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - BpmnScanner scanner = new BpmnScanner(PATH); - int out = scanner.getOutgoing(element.getBaseElement().getId()); - - assertTrue("More or less outgoing sequentflows as expected", out == anzOut); - } -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV; + +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.Gateway; +import org.camunda.bpm.model.bpmn.instance.ServiceTask; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; + +import static org.junit.Assert.assertTrue; + +public class BpmnScannerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + /** + * Case: BPMN-Model in Version 1 + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testModelVersionV1() throws SAXException, IOException, ParserConfigurationException { + final String PATH = BASE_PATH + "BPMN_Model_Version_V1.bpmn"; + final String impClass = "camunda:delegateExpression"; + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + BpmnScanner scanner = new BpmnScanner(PATH); + String imp = scanner.getImplementation(element.getBaseElement().getId()); + + assertTrue("Get unexpected implementation", imp.equals(impClass)); + } + + /** + * Case: BPMN-Model in Version 2 + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testModelVersionV2() throws SAXException, IOException, ParserConfigurationException { + final String PATH = BASE_PATH + "BPMN_Model_Version_V2.bpmn"; + final String impEx = "camunda:class"; + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + BpmnScanner scanner = new BpmnScanner(PATH); + String imp = scanner.getImplementation(element.getBaseElement().getId()); + + assertTrue("Get unexpected implementation", imp.equals(impEx)); + } + + /** + * Case: BPMN-Model in Version 3 + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testModelVersionV3() throws SAXException, IOException, ParserConfigurationException { + final String PATH = BASE_PATH + "BPMN_Model_Version_V3.bpmn"; + final String impDel = "camunda:expression"; + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + BpmnScanner scanner = new BpmnScanner(PATH); + String imp = scanner.getImplementation(element.getBaseElement().getId()); + + assertTrue("Get unexpected implementation", imp.equals(impDel)); + } + + /** + * Case: Test getScriptType + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testGetScriptType() throws SAXException, IOException, ParserConfigurationException { + final String PATH = BASE_PATH + "BPMN_Model_Version_V1.bpmn"; + final String scriptType = "inputParameter"; + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + BpmnScanner scanner = new BpmnScanner(PATH); + ArrayList scripts = scanner.getScriptTypes(element.getBaseElement().getId()); + + assertTrue("Get unexpected implementation", scripts.contains(scriptType)); + } + + /** + * Case: Test getXorGateWays + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testGetXorGateWays() throws SAXException, IOException, ParserConfigurationException { + final String PATH = BASE_PATH + "BPMNScannerXorGateway.bpmn"; + final String gatewayId = "ExclusiveGateway_Id"; + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(Gateway.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + BpmnScanner scanner = new BpmnScanner(PATH); + String gwId = scanner.getXorGateWays(element.getBaseElement().getId()); + + assertTrue("Get unexpected Element", gwId.equals(gatewayId)); + } + + /** + * Case: Test getOutgoing + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testGetOutgoing() throws SAXException, IOException, ParserConfigurationException { + final String PATH = BASE_PATH + "BPMNScannerXorGateway.bpmn"; + final int anzOut = 2; + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(Gateway.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + BpmnScanner scanner = new BpmnScanner(PATH); + int out = scanner.getOutgoing(element.getBaseElement().getId()); + + assertTrue("More or less outgoing sequentflows as expected", out == anzOut); + } +} diff --git a/src/test/java/de/viadee/bpm/vPAV/FileScannerTest.java b/src/test/java/de/viadee/bpm/vPAV/FileScannerTest.java index ee981211..d1accf10 100644 --- a/src/test/java/de/viadee/bpm/vPAV/FileScannerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/FileScannerTest.java @@ -31,13 +31,16 @@ */ package de.viadee.bpm.vPAV; +import de.viadee.bpm.vPAV.config.model.Rule; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; - -import org.junit.BeforeClass; -import org.junit.Test; +import java.util.HashMap; public class FileScannerTest { @@ -56,11 +59,17 @@ public static void setup() throws MalformedURLException { @Test public void testSootPathLoading() { - ProcessApplicationValidator.findModelErrors(); + new FileScanner(new HashMap(), "src/test/java"); + String testTarget = "target/test-classes"; String sootPath = FileScanner.getSootPath(); + boolean contains = false; + + if (sootPath.contains(testTarget)) { + contains = true; + } - System.out.println(sootPath); + Assert.assertTrue("SootPath should contain 'target/test-classes'.", contains); } } diff --git a/src/test/java/de/viadee/bpm/vPAV/OuterProcessVariablesTestOperation.java b/src/test/java/de/viadee/bpm/vPAV/OuterProcessVariablesTestOperation.java index a5eda952..52151f4c 100644 --- a/src/test/java/de/viadee/bpm/vPAV/OuterProcessVariablesTestOperation.java +++ b/src/test/java/de/viadee/bpm/vPAV/OuterProcessVariablesTestOperation.java @@ -31,33 +31,12 @@ */ package de.viadee.bpm.vPAV; -import static org.junit.Assert.fail; +import org.junit.BeforeClass; import java.io.File; -import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.ElementGraphBuilder; -import de.viadee.bpm.vPAV.processing.JavaReaderContext; -import de.viadee.bpm.vPAV.processing.JavaReaderRegex; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; /** * unit test checks, whether outer variables on data flow graph will be set @@ -81,98 +60,7 @@ public static void setup() throws MalformedURLException { cl = new URLClassLoader(classUrls); RuntimeConfig.getInstance().setClassLoader(cl); } + + // create new tests after refactoring - /** - * checks outer variables set on process start by key - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - */ - @Test - public void testStartProcessByKey() throws ParserConfigurationException, SAXException, IOException { - //// Given... - final OuterProcessVariablesScanner scanner = new OuterProcessVariablesScanner(null); - final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); - final String PATH = BASE_PATH + "OuterProcessVariablesTest_StartProcessByKey.bpmn"; - final File processdefinition = new File(PATH); - final JavaReaderContext jvc = new JavaReaderContext(); - jvc.setJavaReadingStrategy(new JavaReaderRegex()); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(processdefinition); - final Map> processIdToVariables = new HashMap>(); - processIdToVariables.put("OuterProcessVariablesTest", Arrays.asList(new String[] { "a" })); - - //// When... - final ElementGraphBuilder graphBuilder = new ElementGraphBuilder(null, null, null, - processIdToVariables, new BpmnScanner(PATH)); - // create data flow graphs - graphBuilder.createProcessGraph(jvc, fileScanner, modelInstance, processdefinition.getPath(), new ArrayList(), scanner); - - //// Then... - // select start event from process and check variable - final BpmnElement element = graphBuilder.getElement("StartEvent_0m79sut"); - final Map variables = element.getProcessVariables(); - if (variables == null) { - fail("there are no outer variables set on data flow graph"); - } - if (!variables.containsKey("a")) { - fail("variable a is not set on data flow graph"); - } - } - - /** - * checks outer process variables set on process start by message and message correlation - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - */ - @Test - public void testMessageCorrelation() throws ParserConfigurationException, SAXException, IOException { - /// Given - final OuterProcessVariablesScanner scanner = new OuterProcessVariablesScanner(null); - final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); - final String PATH = BASE_PATH + "OuterProcessVariablesTest_MessageCorrelation.bpmn"; - final File processdefinition = new File(PATH); - final JavaReaderContext jvc = new JavaReaderContext(); - jvc.setJavaReadingStrategy(new JavaReaderRegex()); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(processdefinition); - - final Map> messageIdToVariables = new HashMap>(); - messageIdToVariables.put("startMessage", Arrays.asList(new String[] { "a" })); - messageIdToVariables.put("intermediateMessage", Arrays.asList(new String[] { "b" })); - - /// When - final ElementGraphBuilder graphBuilder = new ElementGraphBuilder(null, null, - messageIdToVariables, null, new BpmnScanner(PATH)); - // create data flow graphs - graphBuilder.createProcessGraph(jvc, fileScanner, modelInstance, processdefinition.getPath(), new ArrayList(), scanner); - - /// Then - // select start event from process and check variable - final BpmnElement startEvent = graphBuilder.getElement("StartEvent_05bq8nu"); - final Map startVariables = startEvent.getProcessVariables(); - if (startVariables == null) { - fail("there are no outer variables set on data flow graph (message start event)"); - } - - if (!startVariables.containsKey("a")) { - fail("variable a is not set on data flow graph (message start event)"); - } - - // select intermediate event from process and check variable - final BpmnElement intermediateEvent = graphBuilder.getElement("IntermediateCatchEvent_103fbi3"); - final Map intermediateVariables = intermediateEvent - .getProcessVariables(); - if (intermediateVariables == null) { - fail("there are no outer variables set on data flow graph (message intermediate event)"); - } - if (!intermediateVariables.containsKey("b")) { - fail("variable b is not set on data flow graph (message intermediate event)"); - } - } } diff --git a/src/test/java/de/viadee/bpm/vPAV/RuntimeConfigTest.java b/src/test/java/de/viadee/bpm/vPAV/RuntimeConfigTest.java index edb9b1fa..86bb80e3 100644 --- a/src/test/java/de/viadee/bpm/vPAV/RuntimeConfigTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/RuntimeConfigTest.java @@ -31,13 +31,11 @@ */ package de.viadee.bpm.vPAV; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import org.junit.Test; import java.util.HashMap; -import org.junit.Test; +import static org.junit.Assert.*; public class RuntimeConfigTest { diff --git a/src/test/java/de/viadee/bpm/vPAV/config/reader/XmlConfigReaderTest.java b/src/test/java/de/viadee/bpm/vPAV/config/reader/XmlConfigReaderTest.java index 106130b5..5a7165e5 100644 --- a/src/test/java/de/viadee/bpm/vPAV/config/reader/XmlConfigReaderTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/config/reader/XmlConfigReaderTest.java @@ -1,168 +1,167 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.config.reader; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Map; - -import org.junit.BeforeClass; -import org.junit.Test; - -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.constants.BpmnConstants; -import de.viadee.bpm.vPAV.constants.ConfigConstants; - -public class XmlConfigReaderTest { - - private static ClassLoader cl; - - @BeforeClass - public static void setup() throws MalformedURLException { - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - } - - /** - * Test loading a correct config file - * - * @throws ConfigReaderException - */ - @Test() - public void testLoadingCorrectXMLConfigFile() throws ConfigReaderException { - // Given - XmlConfigReader reader = new XmlConfigReader(); - - // When - Map result = reader.read(ConfigConstants.RULESET); - - // Then - assertFalse("No rules could be read", result.isEmpty()); - } - - /** - * Test loading a non-existing config file and check for defaults - * - * @throws ConfigReaderException - */ - @Test() - public void testLoadingNonExistingXMLConfigFile() throws ConfigReaderException { - // Given - XmlConfigReader reader = new XmlConfigReader(); - Map result = null; - - // When - try { - result = reader.read("non-existing.xml"); - assertTrue("Exception expected, but no one was thrown.", result != null); - } catch (ConfigReaderException e) { - // load DefaultRuleSet - result = reader.read("ruleSetDefault.xml"); - - // Default rules correct - assertTrue("False Default ruleSet ", result.get("JavaDelegateChecker").isActive()); - assertTrue("False Default ruleSet ", result.get("EmbeddedGroovyScriptChecker").isActive()); - assertFalse("False Default ruleSet ", result.get("VersioningChecker").isActive()); - assertFalse("False Default ruleSet ", result.get("DmnTaskChecker").isActive()); -// assertFalse("False Default ruleSet ", result.get("ProcessVariablesModelChecker").isActive()); - assertFalse("False Default ruleSet ", result.get("ProcessVariablesNameConventionChecker").isActive()); - assertFalse("False Default ruleSet ", result.get("TaskNamingConventionChecker").isActive()); - } - } - - /** - * Test loading an incorrect config file (rulename empty) - * - * - */ - @Test(expected = ConfigReaderException.class) - public void testLoadingIncorrectXMLNameConfigFile() throws ConfigReaderException { - // Given - XmlConfigReader reader = new XmlConfigReader(); - - // When Then - reader.read("ruleSetIncorrectName.xml"); - - } - - /** - * Test loading an incorrect config file (no xml) - * - * - */ - @Test(expected = ConfigReaderException.class) - public void testLoadingIncorrectXMLConfigFile() throws ConfigReaderException { - // Given - XmlConfigReader reader = new XmlConfigReader(); - - // When Then - reader.read("ruleSetIncorrect.xml"); - - } - - @Test() - public void testBooleanForTypeOfProcessVariableModelReader() throws ConfigReaderException { - - // Given - XmlConfigReader reader = new XmlConfigReader(); - - // When - Map result = reader.read(ConfigConstants.RULESETDEFAULT); - - // Then - boolean isStatic = false; - Rule rule = result.get(BpmnConstants.PROCESS_VARIABLE_MODEL_CHECKER); - if (rule != null) { - Setting setting = rule.getSettings().get(ConfigConstants.USE_STATIC_ANALYSIS_BOOLEAN); - if (setting != null) { - String value = setting.getValue(); - if (setting.getValue().equals("true")) { - isStatic = true; - } - } - } - assertTrue(isStatic); - - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.config.reader; + +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.constants.BpmnConstants; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Map; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class XmlConfigReaderTest { + + private static ClassLoader cl; + + @BeforeClass + public static void setup() throws MalformedURLException { + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + } + + /** + * Test loading a correct config file + * + * @throws ConfigReaderException + */ + @Test() + public void testLoadingCorrectXMLConfigFile() throws ConfigReaderException { + // Given + XmlConfigReader reader = new XmlConfigReader(); + + // When + Map result = reader.read(ConfigConstants.RULESET); + + // Then + assertFalse("No rules could be read", result.isEmpty()); + } + + /** + * Test loading a non-existing config file and check for defaults + * + * @throws ConfigReaderException + */ + @Test() + public void testLoadingNonExistingXMLConfigFile() throws ConfigReaderException { + // Given + XmlConfigReader reader = new XmlConfigReader(); + Map result = null; + + // When + try { + result = reader.read("non-existing.xml"); + assertTrue("Exception expected, but no one was thrown.", result != null); + } catch (ConfigReaderException e) { + // load DefaultRuleSet + result = reader.read("ruleSetDefault.xml"); + + // Default rules correct + assertTrue("False Default ruleSet ", result.get("JavaDelegateChecker").isActive()); + assertTrue("False Default ruleSet ", result.get("EmbeddedGroovyScriptChecker").isActive()); + assertFalse("False Default ruleSet ", result.get("VersioningChecker").isActive()); + assertFalse("False Default ruleSet ", result.get("DmnTaskChecker").isActive()); +// assertFalse("False Default ruleSet ", result.get("ProcessVariablesModelChecker").isActive()); + assertFalse("False Default ruleSet ", result.get("ProcessVariablesNameConventionChecker").isActive()); + assertFalse("False Default ruleSet ", result.get("TaskNamingConventionChecker").isActive()); + } + } + + /** + * Test loading an incorrect config file (rulename empty) + * + * + */ + @Test(expected = ConfigReaderException.class) + public void testLoadingIncorrectXMLNameConfigFile() throws ConfigReaderException { + // Given + XmlConfigReader reader = new XmlConfigReader(); + + // When Then + reader.read("ruleSetIncorrectName.xml"); + + } + + /** + * Test loading an incorrect config file (no xml) + * + * + */ + @Test(expected = ConfigReaderException.class) + public void testLoadingIncorrectXMLConfigFile() throws ConfigReaderException { + // Given + XmlConfigReader reader = new XmlConfigReader(); + + // When Then + reader.read("ruleSetIncorrect.xml"); + + } + + @Test() + public void testBooleanForTypeOfProcessVariableModelReader() throws ConfigReaderException { + + // Given + XmlConfigReader reader = new XmlConfigReader(); + + // When + Map result = reader.read(ConfigConstants.RULESETDEFAULT); + + // Then + boolean isStatic = false; + Rule rule = result.get(BpmnConstants.PROCESS_VARIABLE_MODEL_CHECKER); + if (rule != null) { + Setting setting = rule.getSettings().get(ConfigConstants.USE_STATIC_ANALYSIS_BOOLEAN); + if (setting != null) { + String value = setting.getValue(); + if (setting.getValue().equals("true")) { + isStatic = true; + } + } + } + assertTrue(isStatic); + + } + +} diff --git a/src/test/java/de/viadee/bpm/vPAV/delegates/TestDelegateStatic.java b/src/test/java/de/viadee/bpm/vPAV/delegates/TestDelegateStatic.java index 85d42798..d62a9f6c 100644 --- a/src/test/java/de/viadee/bpm/vPAV/delegates/TestDelegateStatic.java +++ b/src/test/java/de/viadee/bpm/vPAV/delegates/TestDelegateStatic.java @@ -43,7 +43,7 @@ public void execute(DelegateExecution execution) throws Exception { // TODO Auto-generated method stub /* execution.setVariable("dshfhdsfhfds", true); */ - String bla = (String) execution.getVariable("ProcessVariable2"); + execution.getVariable("ProcessVariable2"); int a = 1; final String variableName2 = "ProcessVariable3"; diff --git a/src/main/java/de/viadee/bpm/vPAV/beans/InitialProcessVariablesBase.java b/src/test/java/de/viadee/bpm/vPAV/delegates/TestDelegateStaticInitialProcessVariables.java similarity index 61% rename from src/main/java/de/viadee/bpm/vPAV/beans/InitialProcessVariablesBase.java rename to src/test/java/de/viadee/bpm/vPAV/delegates/TestDelegateStaticInitialProcessVariables.java index 47ceef22..712af897 100644 --- a/src/main/java/de/viadee/bpm/vPAV/beans/InitialProcessVariablesBase.java +++ b/src/test/java/de/viadee/bpm/vPAV/delegates/TestDelegateStaticInitialProcessVariables.java @@ -29,34 +29,39 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package de.viadee.bpm.vPAV.beans; +package de.viadee.bpm.vPAV.delegates; + +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.variable.Variables; +import org.springframework.beans.factory.annotation.Autowired; -import java.lang.reflect.Field; -import java.util.HashMap; import java.util.Map; -public abstract class InitialProcessVariablesBase { - - /** - * Creates a map which contains fields and their respective value - * - * @return Map of variables - * @throws IllegalArgumentException - * If the object is not an instance of the class or interface - * @throws IllegalAccessException - * If the field is inaccessible - */ - public Map createVariableMap() throws IllegalArgumentException, IllegalAccessException { - final Map map = new HashMap(); - final Field[] fields = this.getClass().getDeclaredFields(); - for (final Field field : fields) { - if (!field.getName().startsWith("this")) { - final Object fieldValue = field.get(this); - if (fieldValue != null) { - map.put(field.getName(), fieldValue); - } - } - } - return map; - } + +public class TestDelegateStaticInitialProcessVariables { + + @Autowired + private RuntimeService runtimeService; + + private String ext_kunde; + + private String ext_vsnr; + + private String ext_kfz; + + + public void startProcess() { + + ext_kunde = "kunde_12345"; + ext_vsnr = "vsnr_12345"; + ext_kfz = "kfz_12345"; + + final Map processVariables = Variables.createVariables() + .putValue("kunde", ext_kunde) + .putValue("vsnr", ext_vsnr) + .putValue("kfz", ext_kfz); + + runtimeService.startProcessInstanceByMessage("schadensmeldungKfzGlasbruch", processVariables); + } + } diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableOperationReaderTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableOperationReaderTest.java index 63dbecc8..e4673acf 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableOperationReaderTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableOperationReaderTest.java @@ -31,18 +31,13 @@ */ package de.viadee.bpm.vPAV.processing; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import de.viadee.bpm.vPAV.processing.model.data.VariableOperation; import org.camunda.bpm.model.bpmn.Bpmn; import org.camunda.bpm.model.bpmn.BpmnModelInstance; import org.camunda.bpm.model.bpmn.instance.CallActivity; @@ -53,12 +48,15 @@ import org.junit.Test; import org.xml.sax.SAXException; -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.VariableOperation; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; public class ProcessVariableOperationReaderTest { @@ -99,7 +97,8 @@ public void testRecogniseVariablesInClass() throws ParserConfigurationException, final ProcessVariableReader variableReader = new ProcessVariableReader(null, new BpmnScanner(PATH)); final BpmnElement element = new BpmnElement(PATH, allServiceTasks.iterator().next()); - final Map variables = variableReader.getVariablesFromElement(jvc, fileScanner, element); + final LinkedHashMap variables = new LinkedHashMap(); + variables.putAll(variableReader.getVariablesFromElement(jvc, fileScanner, element, variables)); Assert.assertEquals(2, variables.size()); } @@ -120,7 +119,9 @@ public void testRecogniseInputOutputAssociations() throws ParserConfigurationExc final ProcessVariableReader variableReader = new ProcessVariableReader(null, new BpmnScanner(PATH)); final BpmnElement element = new BpmnElement(PATH, allServiceTasks.iterator().next()); - final Map variables = variableReader.getVariablesFromElement(jvc, fileScanner, element); + + final LinkedHashMap variables = new LinkedHashMap(); + variables.putAll(variableReader.getVariablesFromElement(jvc, fileScanner, element, variables)); final ProcessVariableOperation nameOfVariableInMainProcess = variables .get("nameOfVariableInMainProcess"); diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStaticAnonymousInnerClassesTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStaticAnonymousInnerClassesTest.java index 73f246de..ecfc0749 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStaticAnonymousInnerClassesTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStaticAnonymousInnerClassesTest.java @@ -31,17 +31,12 @@ */ package de.viadee.bpm.vPAV.processing; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; import org.camunda.bpm.model.bpmn.Bpmn; import org.camunda.bpm.model.bpmn.BpmnModelInstance; import org.camunda.bpm.model.bpmn.instance.ServiceTask; @@ -51,12 +46,15 @@ import org.junit.Test; import org.xml.sax.SAXException; -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; public class ProcessVariableReaderStaticAnonymousInnerClassesTest { @@ -98,7 +96,9 @@ public void testRecogniseVariablesInInnerAnonymousClass() throws ParserConfigura final ProcessVariableReader variableReader = new ProcessVariableReader(null, new BpmnScanner(PATH)); final BpmnElement element = new BpmnElement(PATH, allServiceTasks.iterator().next()); - final Map variables = variableReader.getVariablesFromElement(jvc, fileScanner, element); + + final LinkedHashMap variables = new LinkedHashMap(); + variables.putAll(variableReader.getVariablesFromElement(jvc, fileScanner, element, variables)); Assert.assertEquals(3, variables.size()); } diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStaticTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStaticTest.java index 6f47cb27..43b8929c 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStaticTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStaticTest.java @@ -31,31 +31,34 @@ */ package de.viadee.bpm.vPAV.processing; -import static org.junit.Assert.assertEquals; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.ProcessApplicationValidator; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.StartEvent; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; +import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; +import java.util.*; -import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.ProcessApplicationValidator; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import static org.junit.Assert.assertEquals; public class ProcessVariableReaderStaticTest { private static ClassLoader cl; + + private static final String BASE_PATH = "src/test/resources/"; @BeforeClass public static void setup() throws MalformedURLException { @@ -68,14 +71,44 @@ public static void setup() throws MalformedURLException { } @Test - public void testSootReachingMethod() throws ParserConfigurationException, SAXException, IOException { + public void testSootReachingMethod() { final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); - ProcessApplicationValidator.findModelErrorsFromClassloader(cl); - final Map variables = new JavaReaderStatic().getVariablesFromJavaDelegate(fileScanner, "de.viadee.bpm.vPAV.delegates.TestDelegateStatic", null, null, null, null); assertEquals(3, variables.size()); + } + + @Test + public void findInitialProcessVariables() { + final String PATH = BASE_PATH + "ProcessVariablesModelCheckerTest_InitialProcessVariables.bpmn"; + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection startElement = modelInstance + .getModelElementsByType(StartEvent.class); + + final BpmnElement element = new BpmnElement(PATH, startElement.iterator().next()); + + + final Map> outerMap = new HashMap>(); + final Map innerMap = new HashMap(); + innerMap.put("startProcess", "de.viadee.bpm.vPAV.delegates.TestDelegateStaticInitialProcessVariables.java"); + outerMap.put("startProcessInstanceByMessage", innerMap); + + final Map variables = new HashMap<>(); + final Set resources = new HashSet(); + resources.add(""); + + ProcessVariablesScanner scanner = new ProcessVariablesScanner(resources); + + for (Map.Entry> entry : outerMap.entrySet()) { + variables.putAll(new JavaReaderStatic().getVariablesFromClass( + "de.viadee.bpm.vPAV.delegates.TestDelegateStaticInitialProcessVariables", scanner, element, null, entry)); + } + + assertEquals(3, variables.size()); } diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStrategyPatternTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStrategyPatternTest.java index 963c0c39..0e63f9cb 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStrategyPatternTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderStrategyPatternTest.java @@ -31,8 +31,17 @@ */ package de.viadee.bpm.vPAV.processing; -import static org.junit.Assert.assertEquals; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.ProcessApplicationValidator; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; +import javax.xml.parsers.ParserConfigurationException; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; @@ -41,18 +50,7 @@ import java.util.HashMap; import java.util.Map; -import javax.xml.parsers.ParserConfigurationException; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.ProcessApplicationValidator; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import static org.junit.Assert.assertEquals; public class ProcessVariableReaderStrategyPatternTest { @@ -76,14 +74,11 @@ public static void tearDown() { } @Test() - public void testStrategyPatternProcessVariableReaderStatic() - throws ParserConfigurationException, SAXException, IOException { + public void testStrategyPatternProcessVariableReaderStatic() { final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); boolean isStatic = true; - ProcessApplicationValidator.findModelErrors(); - final JavaReaderContext pvc = new JavaReaderContext(); if (isStatic) { pvc.setJavaReadingStrategy(new JavaReaderStatic()); @@ -100,8 +95,7 @@ public void testStrategyPatternProcessVariableReaderStatic() } @Test() - public void testStrategyPatternProcessVariableReaderRegex() - throws ParserConfigurationException, SAXException, IOException { + public void testStrategyPatternProcessVariableReaderRegex() { final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); boolean isStatic = false; diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderTest.java index d6dbcabe..5c8d3901 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/ProcessVariableReaderTest.java @@ -31,17 +31,13 @@ */ package de.viadee.bpm.vPAV.processing; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import de.viadee.bpm.vPAV.processing.model.data.VariableOperation; import org.camunda.bpm.model.bpmn.Bpmn; import org.camunda.bpm.model.bpmn.BpmnModelInstance; import org.camunda.bpm.model.bpmn.instance.CallActivity; @@ -52,13 +48,15 @@ import org.junit.Test; import org.xml.sax.SAXException; -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; -import de.viadee.bpm.vPAV.processing.model.data.VariableOperation; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedHashMap; public class ProcessVariableReaderTest { @@ -99,7 +97,8 @@ public void testRecogniseVariablesInClass() throws ParserConfigurationException, final ProcessVariableReader variableReader = new ProcessVariableReader(null, new BpmnScanner(PATH)); final BpmnElement element = new BpmnElement(PATH, allServiceTasks.iterator().next()); - final Map variables = variableReader.getVariablesFromElement(jvc, fileScanner, element); + final LinkedHashMap variables = new LinkedHashMap(); + variables.putAll(variableReader.getVariablesFromElement(jvc, fileScanner, element, variables)); Assert.assertEquals(2, variables.size()); } @@ -120,7 +119,8 @@ public void testRecogniseInputOutputAssociations() throws ParserConfigurationExc final ProcessVariableReader variableReader = new ProcessVariableReader(null, new BpmnScanner(PATH)); final BpmnElement element = new BpmnElement(PATH, allServiceTasks.iterator().next()); - final Map variables = variableReader.getVariablesFromElement(jvc, fileScanner, element); + final LinkedHashMap variables = new LinkedHashMap(); + variables.putAll(variableReader.getVariablesFromElement(jvc, fileScanner, element, variables)); final ProcessVariableOperation nameOfVariableInMainProcess = variables .get("nameOfVariableInMainProcess"); diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/ReachingDefinitionTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/ReachingDefinitionTest.java index dfcea5cd..326460da 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/ReachingDefinitionTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/ReachingDefinitionTest.java @@ -48,7 +48,6 @@ import org.xml.sax.SAXException; import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.ProcessApplicationValidator; import de.viadee.bpm.vPAV.RuntimeConfig; import de.viadee.bpm.vPAV.constants.ConfigConstants; import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; @@ -69,16 +68,10 @@ public static void setup() throws MalformedURLException { } @Test - public void testSootReachingMethod() throws ParserConfigurationException, SAXException, IOException { - + public void testSootReachingMethod() { final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); - ProcessApplicationValidator.findModelErrorsFromClassloader(cl); - final Map variables = new JavaReaderStatic().getVariablesFromJavaDelegate(fileScanner, "de.viadee.bpm.vPAV.delegates.TestDelegateReachingDef", null, null, null, null); - assertEquals(3, variables.size()); - } - } diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/StaticInterProceduralTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/StaticInterProceduralTest.java index fceca774..dedc0cf1 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/StaticInterProceduralTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/StaticInterProceduralTest.java @@ -31,51 +31,34 @@ */ package de.viadee.bpm.vPAV.processing; -import static org.junit.Assert.*; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; +import javax.xml.parsers.ParserConfigurationException; import java.io.IOException; import java.net.MalformedURLException; import java.util.HashMap; import java.util.Map; -import javax.xml.parsers.ParserConfigurationException; - -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.Runner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import static org.junit.Assert.assertEquals; public class StaticInterProceduralTest { - private static Runner runner; - - private static ClassLoader oldClassLoader; - @BeforeClass public static void setup() throws MalformedURLException { - // Prepare for post-test cleanup - oldClassLoader = RuntimeConfig.getInstance().getClassLoader(); RuntimeConfig.getInstance().setClassLoader(StaticInterProceduralTest.class.getClassLoader()); RuntimeConfig.getInstance().setTest(true); - runner = new Runner(); - } - - @AfterClass - public static void tearDown() { - RuntimeConfig.getInstance().setClassLoader(oldClassLoader); } @Test public void testInterProceduralAnalysis() throws ParserConfigurationException, SAXException, IOException { // Given final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); - runner.viadeeProcessApplicationValidator(ConfigConstants.TEST_JAVAPATH); // When final Map variables = new JavaReaderStatic().getVariablesFromJavaDelegate(fileScanner, @@ -83,7 +66,6 @@ public void testInterProceduralAnalysis() throws ParserConfigurationException, S // Then assertEquals("Static reader should also find variable from TestInterProcAnother class and TestInterPocOther", 5, variables.size()); - } } diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/BoundaryErrorCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/BoundaryErrorCheckerTest.java index 7c17c84e..3e241f5a 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/BoundaryErrorCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/BoundaryErrorCheckerTest.java @@ -1,220 +1,218 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - -public class BoundaryErrorCheckerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static BoundaryErrorChecker checker; - - private static ClassLoader cl; - - private final Rule rule = new Rule("BoundaryErrorChecker", true, null, null, null, null); - - @BeforeClass - public static void setup() throws MalformedURLException { - - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().setTest(true); - RuntimeConfig.getInstance().getResource("en_US"); - - // Bean-Mapping - final Map beanMapping = new HashMap(); - beanMapping.put("correctBoundaryErrorEvent", "de.viadee.bpm.vPAV.delegates.BoundaryErrorEventDelegateCorrect"); - beanMapping.put("wrongBoundaryErrorEvent", "de.viadee.bpm.vPAV.delegates.BoundaryErrorEventDelegateWrong"); - RuntimeConfig.getInstance().setBeanMapping(beanMapping); - } - - /** - * Case: Correct BoundaryErrorEvent with corresponding ErrorCodes - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testBoundaryErrorEventClass_Correct() throws ParserConfigurationException, SAXException, IOException { - - final String PATH = BASE_PATH + "BoundaryErrorEventClass_Correct.bpmn"; - checker = new BoundaryErrorChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() > 0) { - Assert.fail("correct model generates an issue"); - } - - } - - /** - * Case: Correct BoundaryErrorEvent with not corresponding ErrorCodes - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testBoundaryErrorEventClass_Wrong() throws ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "BoundaryErrorEventClass_Wrong.bpmn"; - checker = new BoundaryErrorChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("Incorrect model should generate an issue"); - } - } - - /** - * Case: Correct BoundaryErrorEvent with corresponding ErrorCodes, usage of bean - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testBoundaryErrorEventBean_Correct() throws ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "BoundaryErrorEventBean_Correct.bpmn"; - checker = new BoundaryErrorChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() > 0) { - Assert.fail("correct model generates an issue"); - } - } - - /** - * Case: Correct BoundaryErrorEvent with not corresponding ErrorCodes, usage of bean - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testBoundaryErrorEventBean_Wrong() throws ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "BoundaryErrorEventBean_Wrong.bpmn"; - checker = new BoundaryErrorChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("Incorrect model should generate an issue"); - } - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class BoundaryErrorCheckerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static BoundaryErrorChecker checker; + + private static ClassLoader cl; + + private final Rule rule = new Rule("BoundaryErrorChecker", true, null, null, null, null); + + @BeforeClass + public static void setup() throws MalformedURLException { + + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().setTest(true); + RuntimeConfig.getInstance().getResource("en_US"); + + // Bean-Mapping + final Map beanMapping = new HashMap(); + beanMapping.put("correctBoundaryErrorEvent", "de.viadee.bpm.vPAV.delegates.BoundaryErrorEventDelegateCorrect"); + beanMapping.put("wrongBoundaryErrorEvent", "de.viadee.bpm.vPAV.delegates.BoundaryErrorEventDelegateWrong"); + RuntimeConfig.getInstance().setBeanMapping(beanMapping); + } + + /** + * Case: Correct BoundaryErrorEvent with corresponding ErrorCodes + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testBoundaryErrorEventClass_Correct() throws ParserConfigurationException, SAXException, IOException { + + final String PATH = BASE_PATH + "BoundaryErrorEventClass_Correct.bpmn"; + checker = new BoundaryErrorChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() > 0) { + Assert.fail("correct model generates an issue"); + } + + } + + /** + * Case: Correct BoundaryErrorEvent with not corresponding ErrorCodes + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testBoundaryErrorEventClass_Wrong() throws ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "BoundaryErrorEventClass_Wrong.bpmn"; + checker = new BoundaryErrorChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("Incorrect model should generate an issue"); + } + } + + /** + * Case: Correct BoundaryErrorEvent with corresponding ErrorCodes, usage of bean + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testBoundaryErrorEventBean_Correct() throws ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "BoundaryErrorEventBean_Correct.bpmn"; + checker = new BoundaryErrorChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() > 0) { + Assert.fail("correct model generates an issue"); + } + } + + /** + * Case: Correct BoundaryErrorEvent with not corresponding ErrorCodes, usage of bean + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testBoundaryErrorEventBean_Wrong() throws ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "BoundaryErrorEventBean_Wrong.bpmn"; + checker = new BoundaryErrorChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("Incorrect model should generate an issue"); + } + } + +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/CheckerFactoryTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/CheckerFactoryTest.java index 564465e4..b464c4d5 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/CheckerFactoryTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/CheckerFactoryTest.java @@ -1,157 +1,155 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.processing.ConfigItemNotFoundException; - -/** - * unit tests for class CheckerFactoryTest - * - */ -public class CheckerFactoryTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static ClassLoader cl; - - private final static Setting setting = new Setting("WrongChecker", null, null, null, false, - "de.viadee.vPAV_checker_plugin"); - - private static Map settings = new HashMap(); - - private static Map rules = new HashMap(); - - private final String PATH = BASE_PATH + "CheckerFactoryTest.bpmn"; - - @BeforeClass - public static void setup() throws MalformedURLException { - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().getResource("en_US"); - } - - /** - * Test correct viadee checker 'JavaDelegateChecker' - * - * @throws ConfigItemNotFoundException - * @throws ParserConfigurationException - * @throws SAXException - * @throws IOException - */ - @Test - public void testCorrectInternalChecker() - throws ConfigItemNotFoundException, ParserConfigurationException, SAXException, IOException { - Rule rule = new Rule("JavaDelegateChecker", true, null, null, null, null); - rules.put("JavaDelegateChecker", rule); - CheckerFactory checkerFactory = new CheckerFactory(); - - Collection cElChecker = checkerFactory.createCheckerInstances(rules, null, - new BpmnScanner(PATH)); - - assertTrue("Collection of Checker should not be empty", !cElChecker.isEmpty()); - } - - /** - * Test wrong internal checker - * - * @throws ConfigItemNotFoundException - * @throws ParserConfigurationException - * @throws SAXException - * @throws IOException - */ - @Test - public void testIncorrectInternalChecker() - throws ConfigItemNotFoundException, ParserConfigurationException, SAXException, IOException { - Rule rule = new Rule("WrongChecker", true, null, null, null, null); - rules.put("WrongChecker", rule); - CheckerFactory checkerFactory = new CheckerFactory(); - - Collection cElChecker = checkerFactory.createCheckerInstances(rules, null, - new BpmnScanner(PATH)); - - assertTrue("Collection of Checker should be empty", cElChecker.isEmpty()); - } - - /** - * Test wrong external Checker - * - * @throws ConfigItemNotFoundException - * @throws ParserConfigurationException - * @throws SAXException - * @throws IOException - */ - @Test - public void testIncorrectExternalChecker() - throws ConfigItemNotFoundException, ParserConfigurationException, SAXException, IOException { - settings.put("external_Location", setting); - Rule rule = new Rule("WrongChecker", true, null, settings, null, null); - rules.put("WrongChecker", rule); - CheckerFactory checkerFactory = new CheckerFactory(); - - Collection cElChecker = checkerFactory.createCheckerInstances(rules, null, - new BpmnScanner(PATH)); - - assertTrue("Collection of Checker should be empty", cElChecker.isEmpty()); - } - - @After - public void clearLists() { - rules.clear(); - settings.clear(); - } -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.processing.ConfigItemNotFoundException; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertTrue; + +/** + * unit tests for class CheckerFactoryTest + * + */ +public class CheckerFactoryTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static ClassLoader cl; + + private final static Setting setting = new Setting("WrongChecker", null, null, null, false, + "de.viadee.vPAV_checker_plugin"); + + private static Map settings = new HashMap(); + + private static Map rules = new HashMap(); + + private final String PATH = BASE_PATH + "CheckerFactoryTest.bpmn"; + + @BeforeClass + public static void setup() throws MalformedURLException { + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().getResource("en_US"); + } + + /** + * Test correct viadee checker 'JavaDelegateChecker' + * + * @throws ConfigItemNotFoundException + * @throws ParserConfigurationException + * @throws SAXException + * @throws IOException + */ + @Test + public void testCorrectInternalChecker() + throws ConfigItemNotFoundException, ParserConfigurationException, SAXException, IOException { + Rule rule = new Rule("JavaDelegateChecker", true, null, null, null, null); + rules.put("JavaDelegateChecker", rule); + CheckerFactory checkerFactory = new CheckerFactory(); + + Collection cElChecker = checkerFactory.createCheckerInstances(rules, null, + new BpmnScanner(PATH)); + + assertTrue("Collection of Checker should not be empty", !cElChecker.isEmpty()); + } + + /** + * Test wrong internal checker + * + * @throws ConfigItemNotFoundException + * @throws ParserConfigurationException + * @throws SAXException + * @throws IOException + */ + @Test + public void testIncorrectInternalChecker() + throws ConfigItemNotFoundException, ParserConfigurationException, SAXException, IOException { + Rule rule = new Rule("WrongChecker", true, null, null, null, null); + rules.put("WrongChecker", rule); + CheckerFactory checkerFactory = new CheckerFactory(); + + Collection cElChecker = checkerFactory.createCheckerInstances(rules, null, + new BpmnScanner(PATH)); + + assertTrue("Collection of Checker should be empty", cElChecker.isEmpty()); + } + + /** + * Test wrong external Checker + * + * @throws ConfigItemNotFoundException + * @throws ParserConfigurationException + * @throws SAXException + * @throws IOException + */ + @Test + public void testIncorrectExternalChecker() + throws ConfigItemNotFoundException, ParserConfigurationException, SAXException, IOException { + settings.put("external_Location", setting); + Rule rule = new Rule("WrongChecker", true, null, settings, null, null); + rules.put("WrongChecker", rule); + CheckerFactory checkerFactory = new CheckerFactory(); + + Collection cElChecker = checkerFactory.createCheckerInstances(rules, null, + new BpmnScanner(PATH)); + + assertTrue("Collection of Checker should be empty", cElChecker.isEmpty()); + } + + @After + public void clearLists() { + rules.clear(); + settings.clear(); + } +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/DmnTaskCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/DmnTaskCheckerTest.java index 68dd8376..e6b65616 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/DmnTaskCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/DmnTaskCheckerTest.java @@ -31,16 +31,12 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.CheckName; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import org.camunda.bpm.model.bpmn.Bpmn; import org.camunda.bpm.model.bpmn.BpmnModelInstance; import org.camunda.bpm.model.bpmn.instance.BaseElement; @@ -50,12 +46,14 @@ import org.junit.Test; import org.xml.sax.SAXException; -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.CheckName; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; /** * Unit Tests for DmnTaskChecker diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ElementIdConventionCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ElementIdConventionCheckerTest.java index 98173b68..39a7f609 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ElementIdConventionCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ElementIdConventionCheckerTest.java @@ -31,8 +31,16 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.ElementConvention; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.BeforeClass; +import org.junit.Test; import java.io.File; import java.net.MalformedURLException; @@ -41,17 +49,8 @@ import java.util.ArrayList; import java.util.Collection; -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.BeforeClass; -import org.junit.Test; - -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.ElementConvention; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; public class ElementIdConventionCheckerTest { diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/EmbeddedGroovyScriptCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/EmbeddedGroovyScriptCheckerTest.java index b6eee4ec..c369613a 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/EmbeddedGroovyScriptCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/EmbeddedGroovyScriptCheckerTest.java @@ -31,12 +31,10 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; - +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import org.camunda.bpm.model.bpmn.Bpmn; import org.camunda.bpm.model.bpmn.BpmnModelInstance; import org.camunda.bpm.model.bpmn.instance.ScriptTask; @@ -46,10 +44,11 @@ import org.junit.BeforeClass; import org.junit.Test; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; public class EmbeddedGroovyScriptCheckerTest { diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ExtensionCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ExtensionCheckerTest.java index 2ab39f2d..7c89a9e6 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ExtensionCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ExtensionCheckerTest.java @@ -1,365 +1,363 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.ModelConvention; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - -/** - * unit tests for class ExtensionChecker - * - */ -public class ExtensionCheckerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static ExtensionChecker checker; - - private static ClassLoader cl; - - @BeforeClass - public static void setup() throws MalformedURLException { - - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().getResource("en_US"); - } - - /** - * Case: Extension Key-pair in task is correct - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - - @Test - public void testExtensionChecker_Correct() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "ExtensionCheckerTest_Correct.bpmn"; - checker = new ExtensionChecker(createRule(), new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() > 0) { - Assert.fail("Correct value pair should not generate an issue"); - } - } - - /** - * Case: Extension Key-pair in task is wrong - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - - @Test - public void testExtensionChecker_Wrong() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "ExtensionCheckerTest_Wrong.bpmn"; - checker = new ExtensionChecker(createRule(), new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("Wrong value pair should generate an issue"); - } - } - - /** - * Case: Extension Key-pair in task is missing a value - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - - @Test - public void testExtensionChecker_NoValue() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "ExtensionCheckerTest_NoValue.bpmn"; - checker = new ExtensionChecker(createRule(), new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("Wrong value pair should generate an issue"); - } - } - - /** - * Case: Extension Key-pair in task is missing the key - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - - @Test - public void testExtensionChecker_NoKey() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "ExtensionCheckerTest_NoKey.bpmn"; - checker = new ExtensionChecker(createRule(), new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 2) { - Assert.fail("Wrong value pair should generate an issue"); - } - } - - /** - * Case: Check extension Key-pair for specified task - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - - @Test - public void testExtensionChecker_WithId() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "ExtensionCheckerTest_WithId.bpmn"; - checker = new ExtensionChecker(createRule2(), new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("Wrong value pair should generate an issue"); - } - } - - /** - * Case: Check extension Key-pair for specified task - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - - @Test - public void testExtensionChecker_NoRequiredAttribute() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "ExtensionCheckerTest_NoRequiredAttribute.bpmn"; - checker = new ExtensionChecker(createRule3(), new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 3) { - Assert.fail("Wrong value pair should generate an issue"); - } - } - - /** - * Creates rule configuration - * - * @return rule - */ - private static Rule createRule() { - - final ArrayList modelConventions = createModelConventions(); - - final Map settings = new HashMap(); - final Setting setting = new Setting("SETTING1", null, "ServiceTask", null, true, "\\d+"); - final Setting setting1 = new Setting("SETTING2", null, "ServiceTask", null, true, "\\d+"); - - settings.put("SETTING1", setting); - settings.put("SETTING2", setting1); - - final Rule rule = new Rule("ExtensionChecker", true, null, settings, null, modelConventions); - - return rule; - } - - /** - * Creates second rule configuration - * - * @return rule - */ - private static Rule createRule2() { - - final ArrayList modelConventions = createModelConventions(); - - final Map settings = new HashMap(); - final Setting setting = new Setting("SETTING1", null, null, "Task_26x8g8d", false, "\\d+"); - final Setting setting1 = new Setting("SETTING2", null, null, null, false, "\\d+"); - - settings.put("SETTING1", setting); - settings.put("SETTING2", setting1); - - final Rule rule = new Rule("ExtensionChecker", true, null, settings, null, modelConventions); - - return rule; - } - - /** - * Creates third rule configuration - * - * @return rule - */ - private static Rule createRule3() { - - final ArrayList modelConventions = createModelConventions(); - - final Map settings = new HashMap(); - final Setting setting = new Setting("SETTING1", null, "ServiceTask", null, false, "\\d+"); - final Setting setting1 = new Setting("SETTING2", null, "ServiceTask", null, true, "\\d+"); - - settings.put("SETTING1", setting); - settings.put("SETTING2", setting1); - - final Rule rule = new Rule("ExtensionChecker", true, null, settings, null, modelConventions); - - return rule; - } - - /** - * Creates model conventions - * - * @return modelConventions - */ - private static ArrayList createModelConventions() { - final ArrayList modelConventions = new ArrayList(); - final ModelConvention modelConvention1 = new ModelConvention("ServiceTask"); - final ModelConvention modelConvention2 = new ModelConvention("BusinessRuleTask"); - final ModelConvention modelConvention3 = new ModelConvention("SkriptTask"); - - modelConventions.add(modelConvention1); - modelConventions.add(modelConvention2); - modelConventions.add(modelConvention3); - return modelConventions; - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.ModelConvention; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * unit tests for class ExtensionChecker + * + */ +public class ExtensionCheckerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static ExtensionChecker checker; + + private static ClassLoader cl; + + @BeforeClass + public static void setup() throws MalformedURLException { + + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().getResource("en_US"); + } + + /** + * Case: Extension Key-pair in task is correct + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + + @Test + public void testExtensionChecker_Correct() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "ExtensionCheckerTest_Correct.bpmn"; + checker = new ExtensionChecker(createRule(), new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() > 0) { + Assert.fail("Correct value pair should not generate an issue"); + } + } + + /** + * Case: Extension Key-pair in task is wrong + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + + @Test + public void testExtensionChecker_Wrong() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "ExtensionCheckerTest_Wrong.bpmn"; + checker = new ExtensionChecker(createRule(), new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("Wrong value pair should generate an issue"); + } + } + + /** + * Case: Extension Key-pair in task is missing a value + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + + @Test + public void testExtensionChecker_NoValue() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "ExtensionCheckerTest_NoValue.bpmn"; + checker = new ExtensionChecker(createRule(), new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("Wrong value pair should generate an issue"); + } + } + + /** + * Case: Extension Key-pair in task is missing the key + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + + @Test + public void testExtensionChecker_NoKey() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "ExtensionCheckerTest_NoKey.bpmn"; + checker = new ExtensionChecker(createRule(), new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 2) { + Assert.fail("Wrong value pair should generate an issue"); + } + } + + /** + * Case: Check extension Key-pair for specified task + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + + @Test + public void testExtensionChecker_WithId() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "ExtensionCheckerTest_WithId.bpmn"; + checker = new ExtensionChecker(createRule2(), new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("Wrong value pair should generate an issue"); + } + } + + /** + * Case: Check extension Key-pair for specified task + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + + @Test + public void testExtensionChecker_NoRequiredAttribute() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "ExtensionCheckerTest_NoRequiredAttribute.bpmn"; + checker = new ExtensionChecker(createRule3(), new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 3) { + Assert.fail("Wrong value pair should generate an issue"); + } + } + + /** + * Creates rule configuration + * + * @return rule + */ + private static Rule createRule() { + + final ArrayList modelConventions = createModelConventions(); + + final Map settings = new HashMap(); + final Setting setting = new Setting("SETTING1", null, "ServiceTask", null, true, "\\d+"); + final Setting setting1 = new Setting("SETTING2", null, "ServiceTask", null, true, "\\d+"); + + settings.put("SETTING1", setting); + settings.put("SETTING2", setting1); + + final Rule rule = new Rule("ExtensionChecker", true, null, settings, null, modelConventions); + + return rule; + } + + /** + * Creates second rule configuration + * + * @return rule + */ + private static Rule createRule2() { + + final ArrayList modelConventions = createModelConventions(); + + final Map settings = new HashMap(); + final Setting setting = new Setting("SETTING1", null, null, "Task_26x8g8d", false, "\\d+"); + final Setting setting1 = new Setting("SETTING2", null, null, null, false, "\\d+"); + + settings.put("SETTING1", setting); + settings.put("SETTING2", setting1); + + final Rule rule = new Rule("ExtensionChecker", true, null, settings, null, modelConventions); + + return rule; + } + + /** + * Creates third rule configuration + * + * @return rule + */ + private static Rule createRule3() { + + final ArrayList modelConventions = createModelConventions(); + + final Map settings = new HashMap(); + final Setting setting = new Setting("SETTING1", null, "ServiceTask", null, false, "\\d+"); + final Setting setting1 = new Setting("SETTING2", null, "ServiceTask", null, true, "\\d+"); + + settings.put("SETTING1", setting); + settings.put("SETTING2", setting1); + + final Rule rule = new Rule("ExtensionChecker", true, null, settings, null, modelConventions); + + return rule; + } + + /** + * Creates model conventions + * + * @return modelConventions + */ + private static ArrayList createModelConventions() { + final ArrayList modelConventions = new ArrayList(); + final ModelConvention modelConvention1 = new ModelConvention("ServiceTask"); + final ModelConvention modelConvention2 = new ModelConvention("BusinessRuleTask"); + final ModelConvention modelConvention3 = new ModelConvention("SkriptTask"); + + modelConventions.add(modelConvention1); + modelConventions.add(modelConvention2); + modelConventions.add(modelConvention3); + return modelConventions; + } + +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/FieldInjectionCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/FieldInjectionCheckerTest.java index 5c757ad1..b688bcf0 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/FieldInjectionCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/FieldInjectionCheckerTest.java @@ -1,177 +1,175 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - -/** - * unit tests for class FieldInjectionChecker - * - */ -public class FieldInjectionCheckerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static FieldInjectionChecker checker; - - private static ClassLoader cl; - - private final Rule rule = new Rule("FieldInjectionChecker", true, null, null, null, null); - - @BeforeClass - public static void setup() throws MalformedURLException { - - // Bean-Mapping - final Map beanMapping = new HashMap(); - beanMapping.put("testDelegate", "de.viadee.bpm.vPAV.delegates.DelegateWithWrongType"); - RuntimeConfig.getInstance().setBeanMapping(beanMapping); - - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().getResource("en_US"); - } - - /** - * Case: JavaDelegate with correct implemented fieldInjection variable - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testCorrectFieldInjection() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "FieldInjectionCheckerTest_CorrectFieldInjection.bpmn"; - checker = new FieldInjectionChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() > 0) { - Assert.fail("correct java delegate generates an issue"); - } - } - - /** - * Case: Type of fieldInjection variable is incorrect - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testWrongTypeOfFieldInjection() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "FieldInjectionCheckerTest_WrongType.bpmn"; - checker = new FieldInjectionChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("wrong type doesn't generate an issue"); - } - } - - /** - * Case: No setter method for variable - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testNoSetterMethod() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "FieldInjectionCheckerTest_NoSetter.bpmn"; - checker = new FieldInjectionChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("no setter method doesn't generate an issue"); - } - } -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.ServiceTask; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * unit tests for class FieldInjectionChecker + * + */ +public class FieldInjectionCheckerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static FieldInjectionChecker checker; + + private static ClassLoader cl; + + private final Rule rule = new Rule("FieldInjectionChecker", true, null, null, null, null); + + @BeforeClass + public static void setup() throws MalformedURLException { + + // Bean-Mapping + final Map beanMapping = new HashMap(); + beanMapping.put("testDelegate", "de.viadee.bpm.vPAV.delegates.DelegateWithWrongType"); + RuntimeConfig.getInstance().setBeanMapping(beanMapping); + + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().getResource("en_US"); + } + + /** + * Case: JavaDelegate with correct implemented fieldInjection variable + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testCorrectFieldInjection() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "FieldInjectionCheckerTest_CorrectFieldInjection.bpmn"; + checker = new FieldInjectionChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() > 0) { + Assert.fail("correct java delegate generates an issue"); + } + } + + /** + * Case: Type of fieldInjection variable is incorrect + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testWrongTypeOfFieldInjection() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "FieldInjectionCheckerTest_WrongType.bpmn"; + checker = new FieldInjectionChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("wrong type doesn't generate an issue"); + } + } + + /** + * Case: No setter method for variable + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testNoSetterMethod() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "FieldInjectionCheckerTest_NoSetter.bpmn"; + checker = new FieldInjectionChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("no setter method doesn't generate an issue"); + } + } +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/JavaDelegateCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/JavaDelegateCheckerTest.java index 5149f442..3d50ded9 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/JavaDelegateCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/JavaDelegateCheckerTest.java @@ -1,436 +1,434 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - -/** - * unit tests for class JavaDelegateChecker - * - */ -public class JavaDelegateCheckerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static JavaDelegateChecker checker; - - private static ClassLoader cl; - - private final Rule rule = new Rule("JavaDelegateChecker", true, null, null, null, null); - - @BeforeClass - public static void setup() throws MalformedURLException { - - // Bean-Mapping - final Map beanMapping = new HashMap(); - beanMapping.put("FalschesDelegate_bla", "de.test.Test"); - beanMapping.put("testDelegate", "de.viadee.bpm.vPAV.delegates.TestDelegate"); - RuntimeConfig.getInstance().setBeanMapping(beanMapping); - - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().getResource("en_US"); - } - - /** - * Case: JavaDelegate has been correct set with interface javaDelegate - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testCorrectJavaDelegateReference() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_CorrectJavaDelegateReference.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() > 0) { - Assert.fail("correct java delegate generates an issue"); - } - } - - /** - * Case: JavaDelegate has been correct set with interface SignallableActivityBehavior - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testCorrectJavaDelegateReferenceSignal() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_CorrectJavaDelegateReferenceSignal.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() > 0) { - Assert.fail("correct java delegate generates an issue"); - } - } - - /** - * Case: JavaDelegate has been correct set with superclass AbstractBpmnActivityBehavior - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testCorrectJavaDelegateReferenceAbstract() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_CorrectJavaDelegateReferenceAbstract.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() > 0) { - Assert.fail("correct java delegate generates an issue"); - } - } - - /** - * Case: There are no technical attributes - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testNoTechnicalAttributes() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_NoTechnicalAttributes.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } else { - Assert.assertEquals("Task 'Service Task 1' with no java class name. (compare model: Details, Java Class)", - issues.iterator().next().getMessage()); - } - } - - /** - * Case: java delegate has not been set - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testNoJavaDelegateEntered() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_NoJavaDelegateEntered.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } else { - Assert.assertEquals("Task 'Service Task 1' with no java class name. (compare model: Details, Java Class)", - issues.iterator().next().getMessage()); - } - } - - /** - * Case: The path of the java delegate isn't correct - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testWrongJavaDelegatePath() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongJavaDelegatePath.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } else { - Assert.assertEquals("Class 'TestDelegate2' in 'camunda:class' not found", - issues.iterator().next().getMessage()); - } - } - - /** - * Case: The java delegates implements no or a wrong interface - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testWrongJavaDelegateInterface() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongJavaDelegateInterface.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } else { - Assert.assertEquals( - "Class 'DelegateWithWrongInterface' in 'camunda:class' does not implement/extend the correct interface/class", - issues.iterator().next().getMessage()); - } - } - - /** - * Case: beanMapping exits, but first map is wrong - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testWrongJavaDelegateEntered() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongJavaDelegateEntered.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } else { - Assert.assertEquals("Couldn't find correct beanmapping for delegate expression '${IncorrectBean}'", - issues.iterator().next().getMessage()); - } - } - - /** - * Case: incorrect JavaDelegateExpression reference - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testWrongJavaDelegateExpression() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongJavaDelegateExpression.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } else { - Assert.assertEquals("Class 'TestDelegate2' in 'camunda:delegateExpression' not found", - issues.iterator().next().getMessage()); - } - } - - /** - * Case: incorrect JavaDelegateExpression reference - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testWrongClassReference() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongClassReference.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } else { - Assert.assertEquals("Class '${testDelegate}' in 'camunda:class' not found", - issues.iterator().next().getMessage()); - } - } - - /** - * Case: implements the interface ActivityBehavior - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testInterfaceActivityBehavior() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "JavaDelegateCheckerTest_InterfaceActivityBehavior.bpmn"; - checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(ServiceTask.class); - - final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); - - final Collection issues = checker.check(element); - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } else { - Assert.assertEquals( - "Class 'DelegateWithInterfaceActivityBehavior' in 'camunda:class' implements the interface ActivityBehavior, which is not a very good practice and should be avoided as much as possible", - issues.iterator().next().getMessage()); - } - } -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.ServiceTask; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * unit tests for class JavaDelegateChecker + * + */ +public class JavaDelegateCheckerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static JavaDelegateChecker checker; + + private static ClassLoader cl; + + private final Rule rule = new Rule("JavaDelegateChecker", true, null, null, null, null); + + @BeforeClass + public static void setup() throws MalformedURLException { + + // Bean-Mapping + final Map beanMapping = new HashMap(); + beanMapping.put("FalschesDelegate_bla", "de.test.Test"); + beanMapping.put("testDelegate", "de.viadee.bpm.vPAV.delegates.TestDelegate"); + RuntimeConfig.getInstance().setBeanMapping(beanMapping); + + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().getResource("en_US"); + } + + /** + * Case: JavaDelegate has been correct set with interface javaDelegate + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testCorrectJavaDelegateReference() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_CorrectJavaDelegateReference.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() > 0) { + Assert.fail("correct java delegate generates an issue"); + } + } + + /** + * Case: JavaDelegate has been correct set with interface SignallableActivityBehavior + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testCorrectJavaDelegateReferenceSignal() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_CorrectJavaDelegateReferenceSignal.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() > 0) { + Assert.fail("correct java delegate generates an issue"); + } + } + + /** + * Case: JavaDelegate has been correct set with superclass AbstractBpmnActivityBehavior + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testCorrectJavaDelegateReferenceAbstract() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_CorrectJavaDelegateReferenceAbstract.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() > 0) { + Assert.fail("correct java delegate generates an issue"); + } + } + + /** + * Case: There are no technical attributes + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testNoTechnicalAttributes() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_NoTechnicalAttributes.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } else { + Assert.assertEquals("Task 'Service Task 1' with no java class name. (compare model: Details, Java Class)", + issues.iterator().next().getMessage()); + } + } + + /** + * Case: java delegate has not been set + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testNoJavaDelegateEntered() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_NoJavaDelegateEntered.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } else { + Assert.assertEquals("Task 'Service Task 1' with no java class name. (compare model: Details, Java Class)", + issues.iterator().next().getMessage()); + } + } + + /** + * Case: The path of the java delegate isn't correct + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testWrongJavaDelegatePath() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongJavaDelegatePath.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } else { + Assert.assertEquals("Class 'TestDelegate2' in 'camunda:class' not found", + issues.iterator().next().getMessage()); + } + } + + /** + * Case: The java delegates implements no or a wrong interface + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testWrongJavaDelegateInterface() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongJavaDelegateInterface.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } else { + Assert.assertEquals( + "Class 'DelegateWithWrongInterface' in 'camunda:class' does not implement/extend the correct interface/class", + issues.iterator().next().getMessage()); + } + } + + /** + * Case: beanMapping exits, but first map is wrong + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testWrongJavaDelegateEntered() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongJavaDelegateEntered.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } else { + Assert.assertEquals("Couldn't find correct beanmapping for delegate expression '${IncorrectBean}'", + issues.iterator().next().getMessage()); + } + } + + /** + * Case: incorrect JavaDelegateExpression reference + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testWrongJavaDelegateExpression() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongJavaDelegateExpression.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } else { + Assert.assertEquals("Class 'TestDelegate2' in 'camunda:delegateExpression' not found", + issues.iterator().next().getMessage()); + } + } + + /** + * Case: incorrect JavaDelegateExpression reference + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testWrongClassReference() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_WrongClassReference.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } else { + Assert.assertEquals("Class '${testDelegate}' in 'camunda:class' not found", + issues.iterator().next().getMessage()); + } + } + + /** + * Case: implements the interface ActivityBehavior + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testInterfaceActivityBehavior() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "JavaDelegateCheckerTest_InterfaceActivityBehavior.bpmn"; + checker = new JavaDelegateChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(ServiceTask.class); + + final BpmnElement element = new BpmnElement(PATH, baseElements.iterator().next()); + + final Collection issues = checker.check(element); + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } else { + Assert.assertEquals( + "Class 'DelegateWithInterfaceActivityBehavior' in 'camunda:class' implements the interface ActivityBehavior, which is not a very good practice and should be avoided as much as possible", + issues.iterator().next().getMessage()); + } + } +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/MessageEventCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/MessageEventCheckerTest.java index 0af5ddd3..c16497d7 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/MessageEventCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/MessageEventCheckerTest.java @@ -1,208 +1,206 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - -public class MessageEventCheckerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static MessageEventChecker checker; - - private static ClassLoader cl; - - private final Rule rule = new Rule("MessageEventChecker", true, null, null, null, null); - - @BeforeClass - public static void setup() throws MalformedURLException { - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().getResource("en_US"); - } - - /** - * Case: StartEvent has been set with correct message - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testStartEvent() throws ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "MessageEventChecker_testStartEvent.bpmn"; - checker = new MessageEventChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() > 0) { - Assert.fail("correct model generates an issue"); - } - } - - /** - * Case: StartEvent has been set with message and expression - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testStartEventWithExpression() throws ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "MessageEventChecker_testStartEventWithExpression.bpmn"; - checker = new MessageEventChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("model should generate an issue"); - } - } - - /** - * Case: EndEvent has been set with wrong message - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testEndEvent() throws ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "MessageEventChecker_testEndEvent.bpmn"; - checker = new MessageEventChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } - } - - /** - * Case: Mixed events with several faults - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testMixedEvents() throws ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "MessageEventChecker_testMixedEvents.bpmn"; - checker = new MessageEventChecker(rule, new BpmnScanner(PATH)); - - // parse bpmn model - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("collection with the issues is bigger or smaller as expected"); - } - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collection; + +public class MessageEventCheckerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static MessageEventChecker checker; + + private static ClassLoader cl; + + private final Rule rule = new Rule("MessageEventChecker", true, null, null, null, null); + + @BeforeClass + public static void setup() throws MalformedURLException { + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().getResource("en_US"); + } + + /** + * Case: StartEvent has been set with correct message + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testStartEvent() throws ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "MessageEventChecker_testStartEvent.bpmn"; + checker = new MessageEventChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() > 0) { + Assert.fail("correct model generates an issue"); + } + } + + /** + * Case: StartEvent has been set with message and expression + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testStartEventWithExpression() throws ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "MessageEventChecker_testStartEventWithExpression.bpmn"; + checker = new MessageEventChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("model should generate an issue"); + } + } + + /** + * Case: EndEvent has been set with wrong message + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testEndEvent() throws ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "MessageEventChecker_testEndEvent.bpmn"; + checker = new MessageEventChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } + } + + /** + * Case: Mixed events with several faults + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testMixedEvents() throws ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "MessageEventChecker_testMixedEvents.bpmn"; + checker = new MessageEventChecker(rule, new BpmnScanner(PATH)); + + // parse bpmn model + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("collection with the issues is bigger or smaller as expected"); + } + } + +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/NoExpressionCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/NoExpressionCheckerTest.java index 7ecd7402..0422002f 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/NoExpressionCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/NoExpressionCheckerTest.java @@ -1,216 +1,214 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - -/** - * unit tests for class NoExpressionChecke - * - */ -public class NoExpressionCheckerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static NoExpressionChecker checker; - - private static ClassLoader cl; - - private static Map setting = new HashMap(); - - private final Rule rule = new Rule("NoExpressionChecker", true, null, setting, null, null); - - @BeforeClass - public static void setup() throws MalformedURLException { - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().getResource("en_US"); - } - - /** - * Case: Tasks without Expressions - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testTaskWithoutExpression() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "NoExpressionChecker_WithoutExpressions.bpmn"; - checker = new NoExpressionChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() > 0) { - Assert.fail("correct model generates an issue"); - } - } - - /** - * Case: Tasks with Expressions - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testTaskWithExpression() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "NoExpressionChecker_WithExpressions.bpmn"; - checker = new NoExpressionChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 2) { - Assert.fail("correct model generates an issue"); - } - } - - /** - * Case: Events with Expressions - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testEventsWithExpression() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "NoExpressionChecker_EventsWithExpressions.bpmn"; - checker = new NoExpressionChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 3) { - Assert.fail("model should generate 3 issues"); - } - } - - /** - * Case: Sequenceflow with Expressions - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testSequenceFlowWithExpression() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "NoExpressionChecker_SequenceFlowWithExpression.bpmn"; - checker = new NoExpressionChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("model should generate 3 issues"); - } - } -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * unit tests for class NoExpressionChecke + * + */ +public class NoExpressionCheckerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static NoExpressionChecker checker; + + private static ClassLoader cl; + + private static Map setting = new HashMap(); + + private final Rule rule = new Rule("NoExpressionChecker", true, null, setting, null, null); + + @BeforeClass + public static void setup() throws MalformedURLException { + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().getResource("en_US"); + } + + /** + * Case: Tasks without Expressions + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testTaskWithoutExpression() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "NoExpressionChecker_WithoutExpressions.bpmn"; + checker = new NoExpressionChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() > 0) { + Assert.fail("correct model generates an issue"); + } + } + + /** + * Case: Tasks with Expressions + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testTaskWithExpression() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "NoExpressionChecker_WithExpressions.bpmn"; + checker = new NoExpressionChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 2) { + Assert.fail("correct model generates an issue"); + } + } + + /** + * Case: Events with Expressions + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testEventsWithExpression() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "NoExpressionChecker_EventsWithExpressions.bpmn"; + checker = new NoExpressionChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 3) { + Assert.fail("model should generate 3 issues"); + } + } + + /** + * Case: Sequenceflow with Expressions + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testSequenceFlowWithExpression() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "NoExpressionChecker_SequenceFlowWithExpression.bpmn"; + checker = new NoExpressionChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("model should generate 3 issues"); + } + } +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/NoScriptCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/NoScriptCheckerTest.java index ad50c2a3..9ff65c49 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/NoScriptCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/NoScriptCheckerTest.java @@ -31,6 +31,23 @@ */ package de.viadee.bpm.vPAV.processing.checker; +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.processing.CheckName; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.*; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; @@ -40,29 +57,6 @@ import java.util.HashMap; import java.util.Map; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.Gateway; -import org.camunda.bpm.model.bpmn.instance.ScriptTask; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.camunda.bpm.model.bpmn.instance.UserTask; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.processing.CheckName; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - /** * unit tests for class NoScriptTasks * diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/OverlapCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/OverlapCheckerTest.java index 10822df2..ba7d54ff 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/OverlapCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/OverlapCheckerTest.java @@ -1,144 +1,142 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - -public class OverlapCheckerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static OverlapChecker checker; - - private static ClassLoader cl; - - private final Rule rule = new Rule("OverlapChecker", true, null, null, null, null); - - @BeforeClass - public static void setup() throws MalformedURLException { - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().getResource("en_US"); - } - - /** - * Case: Correct model - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testModelWithNoOverlap() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "OverlapChecker_Correct.bpmn"; - checker = new OverlapChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - - if (issues.size() > 0) { - Assert.fail("correct model generates an issue"); - } - } - - /** - * Case: Incorrect model with overlapping sequence flows - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testModelWithOverlap() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "OverlapChecker_Wrong.bpmn"; - checker = new OverlapChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("Incorrect model should generate an issue"); - } - } -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collection; + +public class OverlapCheckerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static OverlapChecker checker; + + private static ClassLoader cl; + + private final Rule rule = new Rule("OverlapChecker", true, null, null, null, null); + + @BeforeClass + public static void setup() throws MalformedURLException { + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().getResource("en_US"); + } + + /** + * Case: Correct model + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testModelWithNoOverlap() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "OverlapChecker_Correct.bpmn"; + checker = new OverlapChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + + if (issues.size() > 0) { + Assert.fail("correct model generates an issue"); + } + } + + /** + * Case: Incorrect model with overlapping sequence flows + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testModelWithOverlap() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "OverlapChecker_Wrong.bpmn"; + checker = new OverlapChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("Incorrect model should generate an issue"); + } + } +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelCheckerStatic.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelCheckerStatic.java index 5623a454..51feae47 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelCheckerStatic.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelCheckerStatic.java @@ -31,38 +31,35 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import de.viadee.bpm.vPAV.*; -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.ProcessApplicationValidator; +import de.viadee.bpm.vPAV.RuntimeConfig; import de.viadee.bpm.vPAV.config.model.Rule; import de.viadee.bpm.vPAV.config.model.Setting; import de.viadee.bpm.vPAV.constants.ConfigConstants; import de.viadee.bpm.vPAV.processing.ElementGraphBuilder; import de.viadee.bpm.vPAV.processing.JavaReaderContext; import de.viadee.bpm.vPAV.processing.JavaReaderStatic; +import de.viadee.bpm.vPAV.processing.ProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.graph.IGraph; import de.viadee.bpm.vPAV.processing.model.graph.Path; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; public class ProcessVariablesModelCheckerStatic { @@ -85,7 +82,7 @@ public static void setup() throws ParserConfigurationException, SAXException, IO RuntimeConfig.getInstance().setClassLoader(cl); RuntimeConfig.getInstance().getResource("en_US"); - final OuterProcessVariablesScanner scanner = new OuterProcessVariablesScanner(null); + final ProcessVariablesScanner scanner = new ProcessVariablesScanner(null); final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); final String PATH = BASE_PATH + "ProcessVariablesModelCheckerTestStatic_GraphCreation.bpmn"; final File processdefinition = new File(PATH); diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelCheckerTest.java index b7ca23a5..598ce498 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesModelCheckerTest.java @@ -31,28 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.FileScanner; import de.viadee.bpm.vPAV.RuntimeConfig; @@ -61,10 +39,25 @@ import de.viadee.bpm.vPAV.processing.ElementGraphBuilder; import de.viadee.bpm.vPAV.processing.JavaReaderContext; import de.viadee.bpm.vPAV.processing.JavaReaderRegex; +import de.viadee.bpm.vPAV.processing.ProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.graph.IGraph; import de.viadee.bpm.vPAV.processing.model.graph.Path; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; public class ProcessVariablesModelCheckerTest { @@ -87,7 +80,7 @@ public static void setup() throws ParserConfigurationException, SAXException, IO RuntimeConfig.getInstance().setClassLoader(cl); RuntimeConfig.getInstance().getResource("en_US"); - final OuterProcessVariablesScanner scanner = new OuterProcessVariablesScanner(null); + final ProcessVariablesScanner scanner = new ProcessVariablesScanner(null); final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); final String PATH = BASE_PATH + "ProcessVariablesModelCheckerTest_GraphCreation.bpmn"; final File processdefinition = new File(PATH); diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesNameConventionCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesNameConventionCheckerTest.java index af5a994a..3f1331d8 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesNameConventionCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/ProcessVariablesNameConventionCheckerTest.java @@ -31,29 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.FileScanner; import de.viadee.bpm.vPAV.RuntimeConfig; @@ -67,6 +44,23 @@ import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; + +import static org.junit.Assert.assertEquals; /** * unit tests for ProcessVariablesNameConventionChecker @@ -126,8 +120,11 @@ public void testCorrectProcessVariableNames() throws ParserConfigurationExceptio final Collection issues = new ArrayList(); for (final BaseElement baseElement : baseElements) { final BpmnElement element = new BpmnElement(PATH, baseElement); - LinkedHashMap variables = new ProcessVariableReader(null, new BpmnScanner(PATH)) - .getVariablesFromElement(jvc, fileScanner, element); + ProcessVariableReader variableReader = new ProcessVariableReader(null, new BpmnScanner(PATH)); + + final LinkedHashMap variables = new LinkedHashMap(); + variables.putAll(variableReader.getVariablesFromElement(jvc, fileScanner, element, variables)); + element.setProcessVariables(variables); issues.addAll(checker.check(element)); @@ -160,8 +157,11 @@ public void testWrongProcessVariableNames() throws ParserConfigurationException, final Collection issues = new ArrayList(); for (final BaseElement baseElement : baseElements) { final BpmnElement element = new BpmnElement(PATH, baseElement); - LinkedHashMap variables = new ProcessVariableReader(null, new BpmnScanner(PATH)) - .getVariablesFromElement(jvc, fileScanner, element); + ProcessVariableReader variableReader = new ProcessVariableReader(null, new BpmnScanner(PATH)); + + final LinkedHashMap variables = new LinkedHashMap(); + variables.putAll(variableReader.getVariablesFromElement(jvc, fileScanner, element, variables)); + element.setProcessVariables(variables); issues.addAll(checker.check(element)); diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/SignalEventCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/SignalEventCheckerTest.java index 43e9eb23..b1abd3d2 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/SignalEventCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/SignalEventCheckerTest.java @@ -1,148 +1,146 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - -/** - * unit tests for class SignalEventChecker - * - */ -public class SignalEventCheckerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static SignalEventChecker checker; - - private static ClassLoader cl; - - private final Rule rule = new Rule("SignalEventChecker", true, null, null, null, null); - - @BeforeClass - public static void setup() throws MalformedURLException { - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().getResource("en_US"); - } - - /** - * Case: Tasks without Expressions - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testCorrectModel() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "SignalEventChecker_Correct.bpmn"; - checker = new SignalEventChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() > 0) { - Assert.fail("correct model generates an issue"); - } - } - - /** - * Case: Multiple SignalStartEvents with the same signal name - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testWrongModel() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "SignalEventChecker_Wrong.bpmn"; - checker = new SignalEventChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement baseElement : baseElements) { - final BpmnElement element = new BpmnElement(PATH, baseElement); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("incorrect model should generate an issue"); - } - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collection; + +/** + * unit tests for class SignalEventChecker + * + */ +public class SignalEventCheckerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static SignalEventChecker checker; + + private static ClassLoader cl; + + private final Rule rule = new Rule("SignalEventChecker", true, null, null, null, null); + + @BeforeClass + public static void setup() throws MalformedURLException { + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().getResource("en_US"); + } + + /** + * Case: Tasks without Expressions + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testCorrectModel() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "SignalEventChecker_Correct.bpmn"; + checker = new SignalEventChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() > 0) { + Assert.fail("correct model generates an issue"); + } + } + + /** + * Case: Multiple SignalStartEvents with the same signal name + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testWrongModel() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "SignalEventChecker_Wrong.bpmn"; + checker = new SignalEventChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement baseElement : baseElements) { + final BpmnElement element = new BpmnElement(PATH, baseElement); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("incorrect model should generate an issue"); + } + } + +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/TaskNamingConventionCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/TaskNamingConventionCheckerTest.java index 6db4990a..ef4be419 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/TaskNamingConventionCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/TaskNamingConventionCheckerTest.java @@ -31,8 +31,16 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.ElementConvention; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.BeforeClass; +import org.junit.Test; import java.io.File; import java.net.MalformedURLException; @@ -41,17 +49,8 @@ import java.util.ArrayList; import java.util.Collection; -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.BeforeClass; -import org.junit.Test; - -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.ElementConvention; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; public class TaskNamingConventionCheckerTest { diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/TimerExpressionCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/TimerExpressionCheckerTest.java index db7a09a7..13bf5902 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/TimerExpressionCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/TimerExpressionCheckerTest.java @@ -1,183 +1,181 @@ -/** - * BSD 3-Clause License - * - * Copyright © 2018, viadee Unternehmensberatung AG - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of the copyright holder nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package de.viadee.bpm.vPAV.processing.checker; - -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - -/** - * unit tests for class TimerExpressionChecker - * - */ -public class TimerExpressionCheckerTest { - - private static final String BASE_PATH = "src/test/resources/"; - - private static TimerExpressionChecker checker; - - private static ClassLoader cl; - - private final Rule rule = new Rule("TimerExpressionChecker", true, null, null, null, null); - - @BeforeClass - public static void setup() throws MalformedURLException { - - final File file = new File("."); - final String currentPath = file.toURI().toURL().toString(); - final URL classUrl = new URL(currentPath + "src/test/java"); - final URL[] classUrls = { classUrl }; - cl = new URLClassLoader(classUrls); - RuntimeConfig.getInstance().setClassLoader(cl); - RuntimeConfig.getInstance().getResource("en_US"); - } - - /** - * Case: TimerExpression in start event is correct - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - - @Test - public void testTimerExpression_Correct() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "TimerExpressionCheckerTest_Correct.bpmn"; - checker = new TimerExpressionChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() > 0) { - Assert.fail("correct timer expression generates an issue"); - } - } - - /** - * Case: TimerExpression in start event is wrong - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testTimerExpression_Wrong() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "TimerExpressionCheckerTest_Wrong.bpmn"; - checker = new TimerExpressionChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 1) { - Assert.fail("wrong timer expression should generate an issue"); - } - } - - /** - * Case: Several timer expressions - * - * @throws IOException - * @throws SAXException - * @throws ParserConfigurationException - * @throws XPathExpressionException - */ - @Test - public void testTimerExpressions() - throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { - final String PATH = BASE_PATH + "TimerExpressionCheckerTest.bpmn"; - checker = new TimerExpressionChecker(rule, new BpmnScanner(PATH)); - - final Collection issues = new ArrayList(); - - // parse bpmn model - final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); - - final Collection baseElements = modelInstance - .getModelElementsByType(BaseElement.class); - - for (BaseElement event : baseElements) { - final BpmnElement element = new BpmnElement(PATH, event); - issues.addAll(checker.check(element)); - } - - if (issues.size() != 2) { - Assert.fail("model should consist of two issues"); - } - - } - -} +/** + * BSD 3-Clause License + * + * Copyright © 2018, viadee Unternehmensberatung AG + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.viadee.bpm.vPAV.processing.checker; + +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collection; + +/** + * unit tests for class TimerExpressionChecker + * + */ +public class TimerExpressionCheckerTest { + + private static final String BASE_PATH = "src/test/resources/"; + + private static TimerExpressionChecker checker; + + private static ClassLoader cl; + + private final Rule rule = new Rule("TimerExpressionChecker", true, null, null, null, null); + + @BeforeClass + public static void setup() throws MalformedURLException { + + final File file = new File("."); + final String currentPath = file.toURI().toURL().toString(); + final URL classUrl = new URL(currentPath + "src/test/java"); + final URL[] classUrls = { classUrl }; + cl = new URLClassLoader(classUrls); + RuntimeConfig.getInstance().setClassLoader(cl); + RuntimeConfig.getInstance().getResource("en_US"); + } + + /** + * Case: TimerExpression in start event is correct + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + + @Test + public void testTimerExpression_Correct() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "TimerExpressionCheckerTest_Correct.bpmn"; + checker = new TimerExpressionChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() > 0) { + Assert.fail("correct timer expression generates an issue"); + } + } + + /** + * Case: TimerExpression in start event is wrong + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testTimerExpression_Wrong() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "TimerExpressionCheckerTest_Wrong.bpmn"; + checker = new TimerExpressionChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 1) { + Assert.fail("wrong timer expression should generate an issue"); + } + } + + /** + * Case: Several timer expressions + * + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + * @throws XPathExpressionException + */ + @Test + public void testTimerExpressions() + throws XPathExpressionException, ParserConfigurationException, SAXException, IOException { + final String PATH = BASE_PATH + "TimerExpressionCheckerTest.bpmn"; + checker = new TimerExpressionChecker(rule, new BpmnScanner(PATH)); + + final Collection issues = new ArrayList(); + + // parse bpmn model + final BpmnModelInstance modelInstance = Bpmn.readModelFromFile(new File(PATH)); + + final Collection baseElements = modelInstance + .getModelElementsByType(BaseElement.class); + + for (BaseElement event : baseElements) { + final BpmnElement element = new BpmnElement(PATH, event); + issues.addAll(checker.check(element)); + } + + if (issues.size() != 2) { + Assert.fail("model should consist of two issues"); + } + + } + +} diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/VersioningCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/VersioningCheckerTest.java index 41641cd8..68d92bb6 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/VersioningCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/VersioningCheckerTest.java @@ -31,7 +31,19 @@ */ package de.viadee.bpm.vPAV.processing.checker; -import static org.junit.Assert.assertEquals; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.BaseElement; +import org.camunda.bpm.model.bpmn.instance.ServiceTask; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; import java.io.File; import java.net.MalformedURLException; @@ -42,20 +54,7 @@ import java.util.HashMap; import java.util.Map; -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BaseElement; -import org.camunda.bpm.model.bpmn.instance.ServiceTask; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import static org.junit.Assert.assertEquals; public class VersioningCheckerTest { diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/checker/XorConventionCheckerTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/checker/XorConventionCheckerTest.java index 361a5635..63e7b57f 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/checker/XorConventionCheckerTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/checker/XorConventionCheckerTest.java @@ -31,6 +31,23 @@ */ package de.viadee.bpm.vPAV.processing.checker; +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.config.model.ElementConvention; +import de.viadee.bpm.vPAV.config.model.Rule; +import de.viadee.bpm.vPAV.config.model.Setting; +import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; +import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.camunda.bpm.model.bpmn.instance.ExclusiveGateway; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPathExpressionException; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; @@ -41,25 +58,6 @@ import java.util.HashMap; import java.util.Map; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathExpressionException; - -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.ExclusiveGateway; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.config.model.ElementConvention; -import de.viadee.bpm.vPAV.config.model.Rule; -import de.viadee.bpm.vPAV.config.model.Setting; -import de.viadee.bpm.vPAV.processing.model.data.BpmnElement; -import de.viadee.bpm.vPAV.processing.model.data.CheckerIssue; - /** * Unit Tests for DmnTaskChecker * diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/DataFlowRuleBuilderTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/DataFlowRuleBuilderTest.java index 558287e5..48b86a21 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/DataFlowRuleBuilderTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/DataFlowRuleBuilderTest.java @@ -45,7 +45,7 @@ import java.util.function.Predicate; import static de.viadee.bpm.vPAV.processing.dataflow.DataFlowRuleBuilder.processVariables; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.*; diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/DescribedPredicateEvaluatorTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/DescribedPredicateEvaluatorTest.java index fa6ba4cf..d9c5476f 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/DescribedPredicateEvaluatorTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/DescribedPredicateEvaluatorTest.java @@ -33,8 +33,8 @@ import org.junit.Test; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import static org.hamcrest.CoreMatchers.*; public class DescribedPredicateEvaluatorTest { diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/ElementBasedPredicateBuilderImplTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/ElementBasedPredicateBuilderImplTest.java index d643b6f6..d6fc11c2 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/ElementBasedPredicateBuilderImplTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/dataflow/ElementBasedPredicateBuilderImplTest.java @@ -35,15 +35,12 @@ import de.viadee.bpm.vPAV.processing.model.data.ProcessVariable; import org.camunda.bpm.model.bpmn.Query; import org.camunda.bpm.model.bpmn.impl.BpmnModelConstants; -import org.camunda.bpm.model.bpmn.impl.instance.camunda.CamundaPropertyImpl; import org.camunda.bpm.model.bpmn.instance.BaseElement; import org.camunda.bpm.model.bpmn.instance.ExtensionElements; import org.camunda.bpm.model.bpmn.instance.ServiceTask; import org.camunda.bpm.model.bpmn.instance.UserTask; import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperties; import org.camunda.bpm.model.bpmn.instance.camunda.CamundaProperty; -import org.camunda.bpm.model.dmn.impl.instance.ExtensionElementsImpl; -import org.camunda.bpm.model.xml.instance.ModelElementInstance; import org.junit.Test; import java.util.Arrays; diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/model/data/CallActivityTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/model/data/CallActivityTest.java index 5cc4f94c..fe0743af 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/model/data/CallActivityTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/model/data/CallActivityTest.java @@ -31,27 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.model.data; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.FileScanner; import de.viadee.bpm.vPAV.RuntimeConfig; @@ -59,8 +38,23 @@ import de.viadee.bpm.vPAV.processing.ElementGraphBuilder; import de.viadee.bpm.vPAV.processing.JavaReaderContext; import de.viadee.bpm.vPAV.processing.JavaReaderRegex; +import de.viadee.bpm.vPAV.processing.ProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.model.graph.IGraph; import de.viadee.bpm.vPAV.processing.model.graph.Path; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; /** * test the handling of call activities @@ -84,7 +78,7 @@ public static void setup() throws MalformedURLException { @Test public void testEmbedding() throws ParserConfigurationException, SAXException, IOException { - final OuterProcessVariablesScanner scanner = new OuterProcessVariablesScanner(null); + final ProcessVariablesScanner scanner = new ProcessVariablesScanner(null); final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); final String PATH = BASE_PATH + "CallActivityTest_embeddingCallActivity.bpmn"; final File processdefinition = new File(PATH); diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/model/data/IssueIDHashingTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/model/data/IssueIDHashingTest.java index 2e0d7a18..b839482d 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/model/data/IssueIDHashingTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/model/data/IssueIDHashingTest.java @@ -31,11 +31,11 @@ */ package de.viadee.bpm.vPAV.processing.model.data; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; -import org.junit.Test; - public class IssueIDHashingTest { /** diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/ComplexModelTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/ComplexModelTest.java index 0319582c..3a299079 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/ComplexModelTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/ComplexModelTest.java @@ -31,41 +31,32 @@ */ package de.viadee.bpm.vPAV.processing.model.graph; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; +import de.viadee.bpm.vPAV.BpmnScanner; +import de.viadee.bpm.vPAV.FileScanner; +import de.viadee.bpm.vPAV.RuntimeConfig; +import de.viadee.bpm.vPAV.constants.ConfigConstants; +import de.viadee.bpm.vPAV.processing.ElementGraphBuilder; +import de.viadee.bpm.vPAV.processing.JavaReaderContext; +import de.viadee.bpm.vPAV.processing.JavaReaderRegex; +import de.viadee.bpm.vPAV.processing.ProcessVariablesScanner; +import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; import org.camunda.bpm.model.bpmn.Bpmn; import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance; -import org.camunda.bpm.model.bpmn.instance.FlowNode; +import org.camunda.bpm.model.bpmn.instance.*; import org.camunda.bpm.model.bpmn.instance.Process; -import org.camunda.bpm.model.bpmn.instance.SequenceFlow; -import org.camunda.bpm.model.bpmn.instance.Task; import org.camunda.bpm.model.xml.instance.ModelElementInstance; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.xml.sax.SAXException; -import de.viadee.bpm.vPAV.BpmnScanner; -import de.viadee.bpm.vPAV.FileScanner; -import de.viadee.bpm.vPAV.RuntimeConfig; -import de.viadee.bpm.vPAV.constants.ConfigConstants; -import de.viadee.bpm.vPAV.processing.ElementGraphBuilder; -import de.viadee.bpm.vPAV.processing.JavaReaderContext; -import de.viadee.bpm.vPAV.processing.JavaReaderRegex; -import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; public class ComplexModelTest { @@ -96,7 +87,7 @@ public static void setup() throws MalformedURLException { */ @Test public void testGraphOnComplexModel() throws ParserConfigurationException, SAXException, IOException { - final OuterProcessVariablesScanner scanner = new OuterProcessVariablesScanner(null); + final ProcessVariablesScanner scanner = new ProcessVariablesScanner(null); final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); final String PATH = BASE_PATH + "ComplexModelTest_GraphOnComplexModel.bpmn"; final File processdefinition = new File(PATH); diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/GraphCreationTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/GraphCreationTest.java index a93c2704..644db4b1 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/GraphCreationTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/GraphCreationTest.java @@ -31,28 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.model.graph; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.FileScanner; import de.viadee.bpm.vPAV.RuntimeConfig; @@ -60,8 +38,24 @@ import de.viadee.bpm.vPAV.processing.ElementGraphBuilder; import de.viadee.bpm.vPAV.processing.JavaReaderContext; import de.viadee.bpm.vPAV.processing.JavaReaderRegex; +import de.viadee.bpm.vPAV.processing.ProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.model.data.Anomaly; import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; /** * Unit Tests for data flow graph creation and calculation of invalid paths @@ -98,7 +92,7 @@ public static void tearDown() { */ @Test public void testGraph() throws ParserConfigurationException, SAXException, IOException { - final OuterProcessVariablesScanner scanner = new OuterProcessVariablesScanner(null); + final ProcessVariablesScanner scanner = new ProcessVariablesScanner(null); final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); final String PATH = BASE_PATH + "ProcessVariablesModelCheckerTest_GraphCreation.bpmn"; final File processdefinition = new File(PATH); diff --git a/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/LoopAnalysisTest.java b/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/LoopAnalysisTest.java index 22830c33..8a443bb3 100644 --- a/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/LoopAnalysisTest.java +++ b/src/test/java/de/viadee/bpm/vPAV/processing/model/graph/LoopAnalysisTest.java @@ -31,27 +31,6 @@ */ package de.viadee.bpm.vPAV.processing.model.graph; -import java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; - -import de.viadee.bpm.vPAV.OuterProcessVariablesScanner; -import org.camunda.bpm.model.bpmn.Bpmn; -import org.camunda.bpm.model.bpmn.BpmnModelInstance; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.xml.sax.SAXException; - import de.viadee.bpm.vPAV.BpmnScanner; import de.viadee.bpm.vPAV.FileScanner; import de.viadee.bpm.vPAV.RuntimeConfig; @@ -59,8 +38,23 @@ import de.viadee.bpm.vPAV.processing.ElementGraphBuilder; import de.viadee.bpm.vPAV.processing.JavaReaderContext; import de.viadee.bpm.vPAV.processing.JavaReaderRegex; +import de.viadee.bpm.vPAV.processing.ProcessVariablesScanner; import de.viadee.bpm.vPAV.processing.model.data.Anomaly; import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer; +import org.camunda.bpm.model.bpmn.Bpmn; +import org.camunda.bpm.model.bpmn.BpmnModelInstance; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.xml.sax.SAXException; + +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; public class LoopAnalysisTest { @@ -87,7 +81,7 @@ public static void setup() throws MalformedURLException { */ @Test public void testLoop() throws ParserConfigurationException, SAXException, IOException { - final OuterProcessVariablesScanner scanner = new OuterProcessVariablesScanner(null); + final ProcessVariablesScanner scanner = new ProcessVariablesScanner(null); final FileScanner fileScanner = new FileScanner(new HashMap<>(), ConfigConstants.TEST_JAVAPATH); final String PATH = BASE_PATH + "LoopAnalysisTest_TestLoop.bpmn"; final File processdefinition = new File(PATH); diff --git a/src/test/resources/ProcessVariablesModelCheckerTest_InitialProcessVariables.bpmn b/src/test/resources/ProcessVariablesModelCheckerTest_InitialProcessVariables.bpmn new file mode 100644 index 00000000..1f0c6336 --- /dev/null +++ b/src/test/resources/ProcessVariablesModelCheckerTest_InitialProcessVariables.bpmn @@ -0,0 +1,50 @@ + + + + + SequenceFlow_0auv5wf + + + SequenceFlow_1yd40t9 + + + + + SequenceFlow_0auv5wf + SequenceFlow_1yd40t9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +