1 package org.jbpm.context.exe; 2 3 import java.io.*; 4 import java.util.*; 5 6 import org.jbpm.context.def.*; 7 import org.jbpm.graph.def.*; 8 import org.jbpm.graph.exe.*; 9 10 import junit.framework.*; 11 12 public class VariableTypeTest extends TestCase { 13 14 private ProcessDefinition processDefinition = null; 15 private ProcessInstance processInstance = null; 16 private ContextInstance contextInstance = null; 17 18 public void setUp() { 19 processDefinition = new ProcessDefinition(); 20 processDefinition.addDefinition(new ContextDefinition()); 21 processInstance = new ProcessInstance( processDefinition ); 22 contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class); 23 } 24 25 public void testString() { 26 contextInstance.setVariable("a", new String ("3")); 27 assertEquals("3", contextInstance.getVariable("a")); 28 } 29 30 public void testBoolean() { 31 contextInstance.setVariable("a", Boolean.TRUE); 32 assertEquals(Boolean.TRUE, contextInstance.getVariable("a")); 33 } 34 35 public void testCharacter() { 36 contextInstance.setVariable("a", new Character (' ')); 37 assertEquals(new Character (' '), contextInstance.getVariable("a")); 38 } 39 40 public void testFloat() { 41 contextInstance.setVariable("a", new Float (3.3)); 42 assertEquals(new Float (3.3), contextInstance.getVariable("a")); 43 } 44 45 public void testDouble() { 46 contextInstance.setVariable("a", new Double (3.3)); 47 assertEquals(new Double (3.3), contextInstance.getVariable("a")); 48 } 49 50 public static class MySerializableClass implements Serializable { 51 private static final long serialVersionUID = 1L; 52 int member; 53 MySerializableClass(int member){this.member = member;} 54 public boolean equals(Object o) { 55 if (! (o instanceof MySerializableClass)) return false; 56 return ( member == ((MySerializableClass)o).member ); 57 } 58 } 59 public void testCustomTypeSerializable() { 60 contextInstance.setVariable("a", new MySerializableClass(4)); 61 assertEquals(new MySerializableClass(4), contextInstance.getVariable("a")); 62 } 63 64 public void testBasicTypeSerializable() { 65 contextInstance.setVariable("a", new Character ('c')); 66 assertEquals(new Character ('c'), contextInstance.getVariable("a")); 67 } 68 69 public void testLong() { 70 contextInstance.setVariable("a", new Long (3)); 71 assertEquals(new Long (3), contextInstance.getVariable("a")); 72 } 73 74 public void testByte() { 75 contextInstance.setVariable("a", new Byte ("3")); 76 assertEquals(new Byte ("3"), contextInstance.getVariable("a")); 77 } 78 79 public void testShort() { 80 contextInstance.setVariable("a", new Short ("3")); 81 assertEquals(new Short ("3"), contextInstance.getVariable("a")); 82 } 83 84 public void testInteger() { 85 contextInstance.setVariable("a", new Integer (3)); 86 assertEquals(new Integer (3), contextInstance.getVariable("a")); 87 } 88 89 public void testDate() { 90 Date now = new Date(); 91 contextInstance.setVariable("a", now); 92 assertEquals(now, contextInstance.getVariable("a")); 93 } 94 95 public void testNullUpdate() { 96 contextInstance.setVariable("a", "blablabla"); 97 contextInstance.setVariable("a", null); 98 assertNull(contextInstance.getVariable("a")); 99 } 100 101 public void testChangeTypeException() { 102 contextInstance.setVariable("a", new String ("3")); 104 try { 105 contextInstance.setVariable("a", new Integer (3)); 106 fail("expected exception"); 107 } catch (RuntimeException e) { 108 } 110 } 111 112 public void testChangeTypeException2() { 113 contextInstance.setVariable("a", new Integer (3)); 115 try { 116 contextInstance.setVariable("a", new String ("3")); 117 fail("expected exception"); 118 } catch (RuntimeException e) { 119 } 121 } 122 123 public void testChangeTypeWithDeleteIsAllowed() { 124 contextInstance.setVariable("a", new String ("3")); 125 contextInstance.deleteVariable("a"); 126 contextInstance.setVariable("a", new Integer (3)); 127 } 128 129 public void testUnsupportedType() { 130 try { 131 contextInstance.setVariable("a", new Thread ()); 132 fail("expected exception"); 133 } catch (RuntimeException e) { 134 } 136 } 137 } 138 | Popular Tags |