assertEquals(0, workingMemory.getProcessInstances().size());
}
public void testVariableMapping() throws Exception {
RuleBase ruleBase = readRule(false);
WorkingMemory workingMemory = ruleBase.newStatefulSession();
Map<String, Object> map = new HashMap<String, Object>();
map.put("x", "x-value");
org.jbpm.process.instance.ProcessInstance processInstance = ( org.jbpm.process.instance.ProcessInstance )
workingMemory.startProcess("com.sample.ruleflow", map);
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(2, workingMemory.getProcessInstances().size());
for (ProcessInstance p: workingMemory.getProcessInstances()) {
VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
(( org.jbpm.process.instance.ProcessInstance )p).getContextInstance(VariableScope.VARIABLE_SCOPE);
if ("com.sample.ruleflow".equals(p.getProcessId())) {
assertEquals("x-value", variableScopeInstance.getVariable("x"));
} else if ("com.sample.subflow".equals(p.getProcessId())) {
assertEquals("x-value", variableScopeInstance.getVariable("y"));
assertEquals("z-value", variableScopeInstance.getVariable("z"));
assertEquals(7, variableScopeInstance.getVariable("n"));
assertEquals(10, variableScopeInstance.getVariable("o"));
}
}
workingMemory.insert(new Person());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
VariableScopeInstance variableScopeInstance = (VariableScopeInstance)
processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
assertEquals("z-value", variableScopeInstance.getVariable("x"));
assertEquals(10, variableScopeInstance.getVariable("m"));
assertEquals(0, workingMemory.getProcessInstances().size());
}