1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml.io;
18
19 import java.net.URL;
20 import java.util.List;
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25 import junit.textui.TestRunner;
26
27 import org.apache.commons.scxml.SCXMLTestHelper;
28 import org.apache.commons.scxml.model.SCXML;
29 import org.apache.commons.scxml.model.Send;
30 import org.apache.commons.scxml.model.State;
31 import org.apache.commons.scxml.model.Transition;
32 /***
33 * Unit tests {@link org.apache.commons.scxml.SCXMLDigester}.
34 */
35 public class SCXMLDigesterTest extends TestCase {
36 /***
37 * Construct a new instance of SCXMLDigesterTest with
38 * the specified name
39 */
40 public SCXMLDigesterTest(String name) {
41 super(name);
42 }
43
44 public static Test suite() {
45 TestSuite suite = new TestSuite(SCXMLDigesterTest.class);
46 suite.setName("SCXML Digester Tests");
47 return suite;
48 }
49
50
51 private URL microwave01, microwave02, transitions01, send01, prefix01;
52 private SCXML scxml;
53 private String scxmlAsString;
54
55 /***
56 * Set up instance variables required by this test case.
57 */
58 public void setUp() {
59 microwave01 = this.getClass().getClassLoader().
60 getResource("org/apache/commons/scxml/env/jsp/microwave-01.xml");
61 microwave02 = this.getClass().getClassLoader().
62 getResource("org/apache/commons/scxml/env/jsp/microwave-02.xml");
63 transitions01 = this.getClass().getClassLoader().
64 getResource("org/apache/commons/scxml/transitions-01.xml");
65 send01 = this.getClass().getClassLoader().
66 getResource("org/apache/commons/scxml/send-01.xml");
67 prefix01 = this.getClass().getClassLoader().
68 getResource("org/apache/commons/scxml/prefix-01.xml");
69 }
70
71 /***
72 * Tear down instance variables required by this test case.
73 */
74 public void tearDown() {
75 microwave01 = microwave02 = transitions01 = prefix01 = send01 = null;
76 scxml = null;
77 scxmlAsString = null;
78 }
79
80 /***
81 * Test the implementation
82 */
83 public void testSCXMLDigesterMicrowave01Sample() {
84 scxml = SCXMLTestHelper.digest(microwave01);
85 assertNotNull(scxml);
86 scxmlAsString = serialize(scxml);
87 assertNotNull(scxmlAsString);
88 }
89
90 public void testSCXMLDigesterMicrowave02Sample() {
91 scxml = SCXMLTestHelper.digest(microwave02);
92 assertNotNull(scxml);
93 scxmlAsString = serialize(scxml);
94 assertNotNull(scxmlAsString);
95 }
96
97 public void testSCXMLDigesterTransitions01Sample() {
98 scxml = SCXMLTestHelper.digest(transitions01);
99 assertNotNull(scxml);
100 scxmlAsString = serialize(scxml);
101 assertNotNull(scxmlAsString);
102 }
103
104 public void testSCXMLDigesterPrefix01Sample() {
105 scxml = SCXMLTestHelper.digest(prefix01);
106 assertNotNull(scxml);
107 scxmlAsString = serialize(scxml);
108 assertNotNull(scxmlAsString);
109 }
110
111 public void testSCXMLDigesterSend01Sample() {
112
113 scxml = SCXMLTestHelper.digest(send01);
114 State ten = scxml.getInitialState();
115 assertEquals("ten", ten.getId());
116 List ten_done = ten.getTransitionsList("ten.done");
117 assertEquals(1, ten_done.size());
118 Transition ten2twenty = (Transition) ten_done.get(0);
119 List actions = ten2twenty.getActions();
120 assertEquals(1, actions.size());
121 Send send = (Send) actions.get(0);
122 assertEquals("send1", send.getSendid());
123
124
125
126
127
128
129
130
131
132 }
133
134 private String serialize(final SCXML scxml) {
135 scxmlAsString = SCXMLSerializer.serialize(scxml);
136 assertNotNull(scxmlAsString);
137 return scxmlAsString;
138 }
139
140 public static void main(String args[]) {
141 TestRunner.run(suite());
142 }
143 }
144