KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > jpdl > xml > NodeXmlTest


1 package org.jbpm.jpdl.xml;
2
3 import org.dom4j.*;
4 import org.jbpm.graph.def.*;
5 import org.jbpm.graph.def.Node;
6
7 public class NodeXmlTest extends AbstractXmlTestCase {
8
9   public void testReadNode() {
10     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
11       "<process-definition>" +
12       " <node />" +
13       "</process-definition>"
14     );
15     assertNotNull(processDefinition.getNodes().get(0));
16   }
17
18   public void testWriteNode() throws Exception JavaDoc {
19     ProcessDefinition processDefinition = new ProcessDefinition();
20     processDefinition.addNode(new Node());
21     Element element = toXmlAndParse( processDefinition, "/process-definition/node" );
22     assertNotNull(element);
23     assertEquals("node", element.getName());
24     assertEquals(0, element.attributeCount());
25   }
26
27   public void testReadNodeName() {
28     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
29       "<process-definition>" +
30       " <node name='wash car' />" +
31       "</process-definition>"
32     );
33     assertEquals("wash car", processDefinition.getNode("wash car").getName());
34   }
35
36   public void testWriteNodeName() throws Exception JavaDoc {
37     ProcessDefinition processDefinition = new ProcessDefinition();
38     processDefinition.addNode(new Node("n"));
39     Element element = toXmlAndParse( processDefinition, "/process-definition/node" );
40     assertNotNull(element);
41     assertEquals("n", element.attributeValue("name"));
42     assertEquals(1, element.attributeCount());
43   }
44   
45   public void testReadNodeEvents() {
46     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
47       "<process-definition>" +
48       " <node name='n'>" +
49       " <event type='node-enter'/>" +
50       " <event type='customeventtype' />" +
51       " </node>" +
52       "</process-definition>"
53     );
54     Node node = processDefinition.getNode("n");
55     assertEquals(2,node.getEvents().size());
56     assertEquals("node-enter",node.getEvent("node-enter").getEventType());
57     assertEquals("customeventtype",node.getEvent("customeventtype").getEventType());
58   }
59
60   public void testWriteNodeEvents() throws Exception JavaDoc {
61     ProcessDefinition processDefinition = new ProcessDefinition();
62     Node node = new Node("n");
63     processDefinition.addNode(node);
64     node.addEvent(new Event("one"));
65     node.addEvent(new Event("two"));
66     node.addEvent(new Event("three"));
67     printXml(processDefinition);
68     Element element = toXmlAndParse( processDefinition, "/process-definition/node" );
69     assertNotNull(element);
70     assertEquals(3, element.elements("event").size());
71     assertEquals("one", ((Element)element.elements("event").get(0)).attributeValue("type"));
72     assertEquals("two", ((Element)element.elements("event").get(1)).attributeValue("type"));
73     assertEquals("three", ((Element)element.elements("event").get(2)).attributeValue("type"));
74   }
75   
76   public void testReadNodeTransitions() {
77     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
78       "<process-definition>" +
79       " <node name='n'>" +
80       " <transition name='one' to='n'/>" +
81       " <transition name='two' to='n'/>" +
82       " <transition name='three' to='n'/>" +
83       " </node>" +
84       "</process-definition>"
85     );
86     Node node = processDefinition.getNode("n");
87     assertEquals(3,node.getLeavingTransitionsMap().size());
88     assertEquals("one",((Transition)node.getLeavingTransitionsList().get(0)).getName());
89     assertEquals("two",((Transition)node.getLeavingTransitionsList().get(1)).getName());
90     assertEquals("three",((Transition)node.getLeavingTransitionsList().get(2)).getName());
91   }
92
93   public void testWriteNodeTransitions() throws Exception JavaDoc {
94     ProcessDefinition processDefinition = new ProcessDefinition();
95     Node node = new Node("n");
96     processDefinition.addNode(node);
97     node.addLeavingTransition(new Transition("one"));
98     node.addLeavingTransition(new Transition("two"));
99     node.addLeavingTransition(new Transition("three"));
100     Element element = toXmlAndParse( processDefinition, "/process-definition/node" );
101     assertEquals(3, element.elements("transition").size());
102     assertEquals("one", ((Element)element.elements("transition").get(0)).attributeValue("name"));
103     assertEquals("two", ((Element)element.elements("transition").get(1)).attributeValue("name"));
104     assertEquals("three", ((Element)element.elements("transition").get(2)).attributeValue("name"));
105   }
106 }
107
Popular Tags