Search in sources :

Example 1 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.

the class ProcessHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    final String id = attrs.getValue("id");
    final String name = attrs.getValue("name");
    final String version = attrs.getValue("version");
    final String type = attrs.getValue("type");
    final String packageName = attrs.getValue("package-name");
    final String routerLayout = attrs.getValue("routerLayout");
    RuleFlowProcess process = new RuleFlowProcess();
    process.setId(id);
    process.setName(name);
    process.setVersion(version);
    process.setType(type);
    process.setPackageName(packageName);
    if (routerLayout != null) {
        process.setMetaData("routerLayout", new Integer(routerLayout));
    }
    ((ProcessBuildData) parser.getData()).addProcess(process);
    return process;
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessBuildData(org.jbpm.compiler.xml.ProcessBuildData)

Example 2 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.

the class StartNodeInstanceTest method testStartNode.

@Test
public void testStartNode() {
    KieBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    KieSession ksession = kbase.newKieSession();
    MockNode mockNode = new MockNode();
    MockNodeInstanceFactory mockNodeFactory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
    NodeInstanceFactoryRegistry.getInstance(ksession.getEnvironment()).register(mockNode.getClass(), mockNodeFactory);
    RuleFlowProcess process = new RuleFlowProcess();
    StartNode startNode = new StartNode();
    startNode.setId(1);
    startNode.setName("start node");
    mockNode.setId(2);
    new ConnectionImpl(startNode, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE, mockNode, org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(startNode);
    process.addNode(mockNode);
    RuleFlowProcessInstance processInstance = new RuleFlowProcessInstance();
    processInstance.setProcess(process);
    processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) ksession);
    assertEquals(ProcessInstance.STATE_PENDING, processInstance.getState());
    processInstance.start();
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    MockNodeInstance mockNodeInstance = mockNodeFactory.getMockNodeInstance();
    List<NodeInstance> triggeredBy = mockNodeInstance.getTriggers().get(org.jbpm.workflow.core.Node.CONNECTION_DEFAULT_TYPE);
    assertNotNull(triggeredBy);
    assertEquals(1, triggeredBy.size());
    assertSame(startNode.getId(), triggeredBy.get(0).getNodeId());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) StartNode(org.jbpm.workflow.core.node.StartNode) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) KieBase(org.kie.api.KieBase) ConnectionImpl(org.jbpm.workflow.core.impl.ConnectionImpl) KieSession(org.kie.api.runtime.KieSession) NodeInstance(org.kie.api.runtime.process.NodeInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 3 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.

the class RuleFlowProcessValidatorTest method testDynamicNodeValidationInNotDynamicProcess.

@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);
    // empty completion expression to trigger validation error
    dynamicNode.setCompletionExpression("");
    process.addNode(dynamicNode);
    ProcessValidationError[] errors = validator.validateProcess(process);
    assertNotNull(errors);
    // in non-dynamic processes all check should be triggered
    // they should also include process level checks (start node, end node etc)
    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());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) ProcessValidationError(org.jbpm.process.core.validation.ProcessValidationError) Test(org.junit.Test)

Example 4 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.

the class RuleFlowProcessValidatorTest method testDynamicNodeValidationInDynamicProcess.

@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);
    // if dynamic process no longer triggering incoming / outgoing connection errors for dynamic nodes
    assertEquals(0, errors.length);
    // empty completion expression to trigger validation error
    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);
    // autocomplete set to false and empty completion condition triggers error
    assertEquals(1, errors2.length);
    assertEquals("Node 'MyDynamicNode' [1] Dynamic has no completion condition set", errors2[0].getMessage());
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) ProcessValidationError(org.jbpm.process.core.validation.ProcessValidationError) Test(org.junit.Test)

Example 5 with RuleFlowProcess

use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.

the class RuleFlowProcessValidatorTest method testNoPackageName.

@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);
}
Also used : RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) ProcessValidationError(org.jbpm.process.core.validation.ProcessValidationError) Test(org.junit.Test)

Aggregations

RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)85 Test (org.junit.Test)47 ArrayList (java.util.ArrayList)38 StartNode (org.jbpm.workflow.core.node.StartNode)38 EndNode (org.jbpm.workflow.core.node.EndNode)37 ActionNode (org.jbpm.workflow.core.node.ActionNode)33 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)32 DroolsConsequenceAction (org.jbpm.workflow.core.impl.DroolsConsequenceAction)24 KieSession (org.kie.api.runtime.KieSession)20 DroolsAction (org.jbpm.workflow.core.DroolsAction)19 ConnectionImpl (org.jbpm.workflow.core.impl.ConnectionImpl)19 WorkItemNode (org.jbpm.workflow.core.node.WorkItemNode)19 EventTypeFilter (org.jbpm.process.core.event.EventTypeFilter)17 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)17 Variable (org.jbpm.process.core.context.variable.Variable)16 ObjectDataType (org.jbpm.process.core.datatype.impl.type.ObjectDataType)16 Action (org.jbpm.process.instance.impl.Action)16 CompositeNode (org.jbpm.workflow.core.node.CompositeNode)16 ProcessContext (org.kie.api.runtime.process.ProcessContext)16 KieBase (org.kie.api.KieBase)15