KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.jpdl.xml;
2
3 import org.dom4j.*;
4 import org.jbpm.graph.def.*;
5 import org.jbpm.graph.node.*;
6
7 public class StateXmlTest extends AbstractXmlTestCase {
8
9   public void testMultipleStates() {
10     ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
11       "<process-definition>" +
12       " <state name='one' />" +
13       " <state name='two' />" +
14       " <state name='three' />" +
15       " <state name='four' />" +
16       "</process-definition>"
17     );
18     assertEquals(4, processDefinition.getNodes().size());
19     assertEquals(State.class, processDefinition.getNode("one").getClass());
20   }
21
22   public void testState() throws Exception JavaDoc {
23     ProcessDefinition processDefinition = new ProcessDefinition();
24     processDefinition.addNode( new State() );
25     Element element = AbstractXmlTestCase.toXmlAndParse( processDefinition, "/process-definition/state[1]" );
26     assertNotNull(element);
27     assertEquals("state", element.getName());
28     assertEquals(0, element.attributeCount());
29   }
30   
31   public void testStateName() throws Exception JavaDoc {
32     ProcessDefinition processDefinition = new ProcessDefinition();
33     processDefinition.addNode( new State("mystate") );
34     Element element = AbstractXmlTestCase.toXmlAndParse( processDefinition, "/process-definition/state[1]" );
35     assertNotNull(element);
36     assertEquals("state", element.getName());
37     assertEquals(1, element.attributeCount());
38     assertEquals("mystate", element.attributeValue("name"));
39   }
40   
41   public void testThreeStatesOrder() throws Exception JavaDoc {
42     ProcessDefinition processDefinition = new ProcessDefinition();
43     processDefinition.addNode( new State("one") );
44     processDefinition.addNode( new State("two") );
45     processDefinition.addNode( new State("three") );
46     processDefinition.addNode( new State("four") );
47     Element element = AbstractXmlTestCase.toXmlAndParse( processDefinition );
48     assertNotNull(element);
49     assertEquals( "one", ((Element)element.selectSingleNode("/process-definition/state[1]")).attributeValue("name"));
50     assertEquals( "two", ((Element)element.selectSingleNode("/process-definition/state[2]")).attributeValue("name"));
51     assertEquals( "three", ((Element)element.selectSingleNode("/process-definition/state[3]")).attributeValue("name"));
52     assertEquals( "four", ((Element)element.selectSingleNode("/process-definition/state[4]")).attributeValue("name"));
53   }
54 }
55
Popular Tags