12-14-2015 10:02 AM
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
<process id="myProcess" name="My process" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<endEvent id="endevent1" name="End"></endEvent>
<userTask id="usertask1" name="User Task">
<extensionElements>
<activiti:formProperty id="field1" name="Field1" type="string" expression="${myobject.field1}" required="true"></activiti:formProperty>
<activiti:formProperty id="field2" name="Field2" type="string" expression="${myobject.field2}" required="true"></activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
<serviceTask id="servicetask1" name="Service Task" activiti:class="com.example.mytest.MyServiceTask"></serviceTask>
<sequenceFlow id="flow4" sourceRef="servicetask1" targetRef="usertask1"></sequenceFlow>
<userTask id="usertask2" name="User Task">
<extensionElements>
<activiti:formProperty id="field1" name="Field1" type="string" expression="${myobject.field1}" required="true"></activiti:formProperty>
<activiti:formProperty id="field2" name="Field2" type="string" expression="${myobject.field2}" required="true"></activiti:formProperty>
</extensionElements>
</userTask>
<sequenceFlow id="flow5" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow6" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
</process>
</definitions>
package com.example.mytest;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
public class MyServiceTask implements JavaDelegate {
public void execute(DelegateExecution execution) throws Exception {
execution.setVariable("myobject", new MyBean());
}
}
package com.example.mytest;
import java.io.Serializable;
public class MyBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String field1;
private String field2;
public String getField1() {
return field1;
}
public void setField1(String field1) {
this.field1 = field1;
}
public String getField2() {
return field2;
}
public void setField2(String field2) {
this.field2 = field2;
}
}
package com.example.mytest;
import java.util.HashMap;
import java.util.Map;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.ActivitiRule;
import org.activiti.engine.test.Deployment;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
public class ProcessTest {
@Rule
public ActivitiRule activitiRule = new ActivitiRule();
@Deployment(resources = {"MyProcess.bpmn"})
@Test
public void test() {
ProcessInstance pi = activitiRule.getRuntimeService().startProcessInstanceByKey("myProcess");
Map<String, String> properties;
Task task;
MyBean myobject;
properties = new HashMap<String, String>();
properties.put("field1", "value1");
properties.put("field2", "value2");
task = activitiRule.getTaskService().createTaskQuery().processInstanceId(pi.getId()).singleResult();
activitiRule.getFormService().submitTaskFormData(task.getId(), properties);
properties = new HashMap<String, String>();
properties.put("field1", "value3");
properties.put("field2", "value4");
task = activitiRule.getTaskService().createTaskQuery().processInstanceId(pi.getId()).singleResult();
activitiRule.getFormService().submitTaskFormData(task.getId(), properties);
Assert.assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().count());
myobject = (MyBean) activitiRule.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(pi.getId()).variableName("myobject").singleResult().getValue();
Assert.assertEquals("value4", myobject.getField2());
}
}
org.junit.ComparisonFailure: expected:<value[4]> but was:<value[2]>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at com.example.mytest.ProcessTest.test(ProcessTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.activiti.engine.test.ActivitiRule$1.evaluate(ActivitiRule.java:126)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
12-16-2015 07:35 AM
12-21-2015 04:38 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.