KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > context > exe > VariableTypeTest


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 JavaDoc("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 JavaDoc(' '));
37     assertEquals(new Character JavaDoc(' '), contextInstance.getVariable("a"));
38   }
39
40   public void testFloat() {
41     contextInstance.setVariable("a", new Float JavaDoc(3.3));
42     assertEquals(new Float JavaDoc(3.3), contextInstance.getVariable("a"));
43   }
44   
45   public void testDouble() {
46     contextInstance.setVariable("a", new Double JavaDoc(3.3));
47     assertEquals(new Double JavaDoc(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 JavaDoc 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 JavaDoc('c'));
66     assertEquals(new Character JavaDoc('c'), contextInstance.getVariable("a"));
67   }
68
69   public void testLong() {
70     contextInstance.setVariable("a", new Long JavaDoc(3));
71     assertEquals(new Long JavaDoc(3), contextInstance.getVariable("a"));
72   }
73   
74   public void testByte() {
75     contextInstance.setVariable("a", new Byte JavaDoc("3"));
76     assertEquals(new Byte JavaDoc("3"), contextInstance.getVariable("a"));
77   }
78   
79   public void testShort() {
80     contextInstance.setVariable("a", new Short JavaDoc("3"));
81     assertEquals(new Short JavaDoc("3"), contextInstance.getVariable("a"));
82   }
83   
84   public void testInteger() {
85     contextInstance.setVariable("a", new Integer JavaDoc(3));
86     assertEquals(new Integer JavaDoc(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     // this one does not use a converter
103
contextInstance.setVariable("a", new String JavaDoc("3"));
104     try {
105       contextInstance.setVariable("a", new Integer JavaDoc(3));
106       fail("expected exception");
107     } catch (RuntimeException JavaDoc e) {
108       // OK
109
}
110   }
111
112   public void testChangeTypeException2() {
113     // this one uses a converter
114
contextInstance.setVariable("a", new Integer JavaDoc(3));
115     try {
116       contextInstance.setVariable("a", new String JavaDoc("3"));
117       fail("expected exception");
118     } catch (RuntimeException JavaDoc e) {
119       // OK
120
}
121   }
122
123   public void testChangeTypeWithDeleteIsAllowed() {
124     contextInstance.setVariable("a", new String JavaDoc("3"));
125     contextInstance.deleteVariable("a");
126     contextInstance.setVariable("a", new Integer JavaDoc(3));
127   }
128
129   public void testUnsupportedType() {
130     try {
131       contextInstance.setVariable("a", new Thread JavaDoc());
132       fail("expected exception");
133     } catch (RuntimeException JavaDoc e) {
134       // OK
135
}
136   }
137 }
138
Popular Tags