RuleFlowProcessValidator implements ProcessValidator { public ProcessValidationError[] validateProcess(final RuleFlowProcess process) { final List<ProcessValidationError> errors = new ArrayList<>(); if (process.getName() == null) { errors.add(new ProcessValidationErrorImpl(process, "Process has no name.")); } if (process.getId() == null || "".equals(process.getId())) { errors.add(new ProcessValidationErrorImpl(process, "Process has no id.")); } if (process.getStartNodes().isEmpty() && !process.isDynamic()) { errors.add(new ProcessValidationErrorImpl(process, "Process has no start node.")); } if (process.getEndNodes().isEmpty() && !process.isDynamic()) { errors.add(new ProcessValidationErrorImpl(process, "Process has no end node.")); } validateNodes(process.getNodes(), errors, process); validateVariables(errors, process); checkAllNodesConnectedToStart(process, process.isDynamic(), errors, process); return errors.toArray(new ProcessValidationError[errors.size()]); } private  RuleFlowProcessValidator(); static RuleFlowProcessValidator getInstance(); ProcessValidationError[] validateProcess(final RuleFlowProcess process); ProcessValidationError[] validateProcess(Process process); @Override boolean accept(Process process,
                          Resource resource); @Override boolean compilationSupported(); static final String ASSOCIATIONS; }
@Test void testDynamicNodeValidationInNotDynamicProcess() { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process"); process.setName("Dynamic Node Process"); process.setPackageName("org.mycomp.myprocess"); process.setDynamic(false); DynamicNode dynamicNode = new DynamicNode(); dynamicNode.setName("MyDynamicNode"); dynamicNode.setId(1); dynamicNode.setAutoComplete(false); process.addNode(dynamicNode); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(6, errors.length); assertEquals("Process has no start node.", errors[0].getMessage()); assertEquals("Process has no end node.", errors[1].getMessage()); assertEquals("Node 'MyDynamicNode' [1] Dynamic has no incoming connection", errors[2].getMessage()); assertEquals("Node 'MyDynamicNode' [1] Dynamic has no outgoing connection", errors[3].getMessage()); assertEquals("Node 'MyDynamicNode' [1] Dynamic has no completion condition set", errors[4].getMessage()); assertEquals("Node 'MyDynamicNode' [1] Has no connection to the start node.", errors[5].getMessage()); }
@Test void testDynamicNodeValidationInDynamicProcess() { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process"); process.setName("Dynamic Node Process"); process.setPackageName("org.mycomp.myprocess"); process.setDynamic(true); DynamicNode dynamicNode = new DynamicNode(); dynamicNode.setName("MyDynamicNode"); dynamicNode.setId(1); dynamicNode.setAutoComplete(false); dynamicNode.setCompletionExpression(kcontext -> true); process.addNode(dynamicNode); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(0, errors.length); process.removeNode(dynamicNode); DynamicNode dynamicNode2 = new DynamicNode(); dynamicNode2.setName("MyDynamicNode"); dynamicNode2.setId(1); dynamicNode2.setAutoComplete(false); process.addNode(dynamicNode2); ProcessValidationError[] errors2 = validator.validateProcess(process); assertNotNull(errors2); assertEquals(1, errors2.length); assertEquals("Node 'MyDynamicNode' [1] Dynamic has no completion condition set", errors2[0].getMessage()); }
@Test void testEmptyPackageName() { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process"); process.setName("Empty Package Name Process"); process.setPackageName(""); process.setDynamic(true); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(0, errors.length); }
@Test void testNoPackageName() { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process"); process.setName("No Package Name Process"); process.setDynamic(true); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(0, errors.length); }
@Test void testCompositeNodeNoStart() { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process.process"); process.setName("Process"); StartNode startNode = new StartNode(); startNode.setName("Start"); startNode.setId(1); process.addNode(startNode); EndNode endNode = new EndNode(); endNode.setName("EndNode"); endNode.setId(2); process.addNode(endNode); CompositeNode compositeNode = new CompositeNode(); compositeNode.setName("CompositeNode"); compositeNode.setId(3); process.addNode(compositeNode); new org.jbpm.workflow.core.impl.ConnectionImpl( startNode, Node.CONNECTION_DEFAULT_TYPE, compositeNode, Node.CONNECTION_DEFAULT_TYPE ); new org.jbpm.workflow.core.impl.ConnectionImpl( compositeNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE ); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(1, errors.length); assertEquals("Node 'CompositeNode' [3] Composite has no start node defined.", errors[0].getMessage()); }
@Test public void testDynamicNodeValidationInNotDynamicProcess() throws Exception { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process"); process.setName("Dynamic Node Process"); process.setPackageName("org.mycomp.myprocess"); process.setDynamic(false); DynamicNode dynamicNode = new DynamicNode(); dynamicNode.setName("MyDynamicNode"); dynamicNode.setId(1); dynamicNode.setAutoComplete(false); dynamicNode.setCompletionExpression(""); process.addNode(dynamicNode); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(6, errors.length); assertEquals("Process has no start node.", errors[0].getMessage()); assertEquals("Process has no end node.", errors[1].getMessage()); assertEquals("Node 'MyDynamicNode' [1] Dynamic has no incoming connection", errors[2].getMessage()); assertEquals("Node 'MyDynamicNode' [1] Dynamic has no outgoing connection", errors[3].getMessage()); assertEquals("Node 'MyDynamicNode' [1] Dynamic has no completion condition set", errors[4].getMessage()); assertEquals("Node 'MyDynamicNode' [1] Has no connection to the start node.", errors[5].getMessage()); }
@Test public void testDynamicNodeValidationInDynamicProcess() throws Exception { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process"); process.setName("Dynamic Node Process"); process.setPackageName("org.mycomp.myprocess"); process.setDynamic(true); DynamicNode dynamicNode = new DynamicNode(); dynamicNode.setName("MyDynamicNode"); dynamicNode.setId(1); dynamicNode.setAutoComplete(false); dynamicNode.setCompletionExpression("completion-expression"); process.addNode(dynamicNode); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(0, errors.length); process.removeNode(dynamicNode); DynamicNode dynamicNode2 = new DynamicNode(); dynamicNode2.setName("MyDynamicNode"); dynamicNode2.setId(1); dynamicNode2.setAutoComplete(false); dynamicNode2.setCompletionExpression(""); process.addNode(dynamicNode2); ProcessValidationError[] errors2 = validator.validateProcess(process); assertNotNull(errors2); assertEquals(1, errors2.length); assertEquals("Node 'MyDynamicNode' [1] Dynamic has no completion condition set", errors2[0].getMessage()); }
@Test public void testEmptyPackageName() throws Exception { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process"); process.setName("Empty Package Name Process"); process.setPackageName(""); process.setDynamic(true); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(0, errors.length); }
@Test public void testNoPackageName() throws Exception { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process"); process.setName("No Package Name Process"); process.setDynamic(true); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(0, errors.length); }
@Test public void testCompositeNodeNoStart() throws Exception { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process.process"); process.setName("Process"); StartNode startNode = new StartNode(); startNode.setName("Start"); startNode.setId(1); process.addNode(startNode); EndNode endNode = new EndNode(); endNode.setName("EndNode"); endNode.setId(2); process.addNode(endNode); CompositeNode compositeNode = new CompositeNode(); compositeNode.setName("CompositeNode"); compositeNode.setId(3); process.addNode(compositeNode); new org.jbpm.workflow.core.impl.ConnectionImpl( startNode, Node.CONNECTION_DEFAULT_TYPE, compositeNode, Node.CONNECTION_DEFAULT_TYPE ); new org.jbpm.workflow.core.impl.ConnectionImpl( compositeNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE ); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(1, errors.length); assertEquals("Node 'CompositeNode' [3] Composite has no start node defined.", errors[0].getMessage()); }
@Test public void testSubprocessCallActivity() throws Exception { RuleFlowProcess process = new RuleFlowProcess(); process.setId("org.drools.core.process.process"); process.setName("Process"); StartNode startNode = new StartNode(); startNode.setName("Start"); startNode.setId(1); process.addNode(startNode); EndNode endNode = new EndNode(); endNode.setName("EndNode"); endNode.setId(2); process.addNode(endNode); SubProcessNode subProcessNode = new SubProcessNode(); subProcessNode.setName("CallActivityNode"); subProcessNode.setId(3); subProcessNode.setIsCallActivity(true); process.addNode(subProcessNode); new org.jbpm.workflow.core.impl.ConnectionImpl( startNode, Node.CONNECTION_DEFAULT_TYPE, subProcessNode, Node.CONNECTION_DEFAULT_TYPE ); new org.jbpm.workflow.core.impl.ConnectionImpl( subProcessNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE ); ProcessValidationError[] errors = validator.validateProcess(process); assertNotNull(errors); assertEquals(1, errors.length); assertEquals("Node 'CallActivityNode' [3] Reusable Subprocess has no called element specified.", errors[0].getMessage()); }