1 package org.jbpm.context.exe; 2 3 import java.util.*; 4 5 import org.jbpm.context.def.*; 6 import org.jbpm.context.exe.variableinstance.*; 7 import org.jbpm.db.*; 8 import org.jbpm.graph.def.*; 9 import org.jbpm.graph.exe.*; 10 11 public class TokenVariableMapDbTest extends AbstractDbTestCase { 12 13 ProcessDefinition processDefinition; 14 ProcessInstance processInstance; 15 Token token; 16 ContextInstance contextInstance; 17 Map tokenVariableMaps; 18 TokenVariableMap tokenVariableMap; 19 20 public void setUp() { 21 super.setUp(); 22 23 processDefinition = new ProcessDefinition(); 24 processDefinition.addDefinition(new ContextDefinition()); 25 graphSession.saveProcessDefinition(processDefinition); 26 27 processInstance = new ProcessInstance(processDefinition); 28 token = processInstance.getRootToken(); 29 30 contextInstance = processInstance.getContextInstance(); 31 tokenVariableMaps = new HashMap(); 32 tokenVariableMap = contextInstance.getOrCreateTokenVariableMap(token); 33 tokenVariableMaps.put(token, tokenVariableMap); 34 contextInstance.tokenVariableMaps = tokenVariableMaps; 35 } 36 37 public void testTokenVariableMapContextInstance() { 38 processInstance = saveAndReload(processInstance); 39 40 token = processInstance.getRootToken(); 41 contextInstance = processInstance.getContextInstance(); 42 tokenVariableMaps = contextInstance.tokenVariableMaps; 43 tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(token); 44 45 assertSame(contextInstance, tokenVariableMap.getContextInstance()); 46 } 47 48 public void testTokenVariableMapToken() { 49 processInstance = saveAndReload(processInstance); 50 51 token = processInstance.getRootToken(); 52 contextInstance = processInstance.getContextInstance(); 53 tokenVariableMaps = contextInstance.tokenVariableMaps; 54 tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(token); 55 56 assertSame(token, tokenVariableMap.getToken()); 57 } 58 59 public void testTokenVariableMapVariableInstances() { 60 StringInstance stringVariable = (StringInstance) VariableInstance.create(tokenVariableMap, "one", String .class); 61 stringVariable.setValue("hello"); 62 tokenVariableMap.addVariableInstance(stringVariable); 63 stringVariable = (StringInstance) VariableInstance.create(tokenVariableMap, "two", String .class); 64 stringVariable.setValue("world"); 65 tokenVariableMap.addVariableInstance(stringVariable); 66 67 processInstance = saveAndReload(processInstance); 68 69 token = processInstance.getRootToken(); 70 contextInstance = processInstance.getContextInstance(); 71 tokenVariableMaps = contextInstance.tokenVariableMaps; 72 tokenVariableMap = (TokenVariableMap) tokenVariableMaps.get(processInstance.getRootToken()); 73 74 System.out.println(tokenVariableMap.getVariable("one")); 75 System.out.println(tokenVariableMap.getVariable("two")); 76 77 assertEquals("hello", ((StringInstance)tokenVariableMap.variableInstances.get("one")).getValue() ); 78 assertEquals("world", ((StringInstance)tokenVariableMap.variableInstances.get("two")).getValue() ); 79 } 80 } 81 | Popular Tags |