KickJava   Java API By Example, From Geeks To Geeks.

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


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 TransitionXmlTest extends AbstractXmlTestCase {
8
9   public void testReadNodeTransition() {
10     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
11       "<process-definition>" +
12       " <node name='a'>" +
13       " <transition to='b' />" +
14       " </node>" +
15       " <node name='b' />" +
16       "</process-definition>"
17     );
18     Node a = processDefinition.getNode("a");
19     Node b = processDefinition.getNode("b");
20     assertSame(a, a.getDefaultLeavingTransition().getFrom());
21     assertSame(b, a.getDefaultLeavingTransition().getTo());
22   }
23
24   public void testWriteNodeTransition() throws Exception JavaDoc {
25     ProcessDefinition processDefinition = new ProcessDefinition();
26     Node a = new Node("a");
27     Node b = new Node("b");
28     processDefinition.addNode(a);
29     processDefinition.addNode(b);
30
31     Transition t = new Transition();
32     a.addLeavingTransition(t);
33     b.addArrivingTransition(t);
34     
35     Element element = AbstractXmlTestCase.toXmlAndParse( processDefinition, "/process-definition/node[1]/transition" );
36     assertNotNull(element);
37     assertEquals("transition", element.getName());
38     assertEquals(1, element.attributeCount());
39     assertEquals("b", element.attributeValue("to"));
40   }
41
42   public void testReadNodeTransitionName() throws Exception JavaDoc {
43     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
44       "<process-definition>" +
45       " <node name='a'>" +
46       " <transition name='hertransition' to='b' />" +
47       " </node>" +
48       " <node name='b' />" +
49       "</process-definition>"
50     );
51             
52     Element element = AbstractXmlTestCase.toXmlAndParse( processDefinition, "/process-definition/node[1]/transition[1]" );
53     assertNotNull(element);
54     assertEquals("hertransition", element.attributeValue("name"));
55   }
56
57   public void testWriteNodeTransitionName() throws Exception JavaDoc {
58     ProcessDefinition processDefinition = new ProcessDefinition();
59     Node a = new Node("a");
60     Node b = new Node("b");
61     processDefinition.addNode(a);
62     processDefinition.addNode(b);
63
64     Transition t = new Transition("hertransition");
65     a.addLeavingTransition(t);
66     b.addArrivingTransition(t);
67
68     Element element = AbstractXmlTestCase.toXmlAndParse( processDefinition, "/process-definition/node[1]/transition" );
69     assertNotNull(element);
70     assertEquals("hertransition", element.attributeValue("name"));
71   }
72
73   public void testTransitionOrder() throws Exception JavaDoc {
74     ProcessDefinition processDefinition = new ProcessDefinition();
75     Node a = new Node("a");
76     Node b = new Node("b");
77     processDefinition.addNode(a);
78     processDefinition.addNode(b);
79
80     Transition t = new Transition("one");
81     a.addLeavingTransition(t);
82     b.addArrivingTransition(t);
83
84     t = new Transition("two");
85     a.addLeavingTransition(t);
86     b.addArrivingTransition(t);
87
88     t = new Transition("three");
89     a.addLeavingTransition(t);
90     b.addArrivingTransition(t);
91
92     Element element = AbstractXmlTestCase.toXmlAndParse( processDefinition );
93     assertNotNull(element);
94     assertEquals( "one", ((Element)element.selectSingleNode("/process-definition/node[1]/transition[1]")).attributeValue("name"));
95     assertEquals( "two", ((Element)element.selectSingleNode("/process-definition/node[1]/transition[2]")).attributeValue("name"));
96     assertEquals( "three", ((Element)element.selectSingleNode("/process-definition/node[1]/transition[3]")).attributeValue("name"));
97   }
98   
99 }
100
Popular Tags