1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.scxml.model;
17
18 import junit.framework.Test;
19 import junit.framework.TestCase;
20 import junit.framework.TestSuite;
21
22 public class ActionTest extends TestCase {
23
24 public ActionTest(String testName) {
25 super(testName);
26 }
27
28 public static Test suite() {
29 return new TestSuite(ActionTest.class);
30 }
31
32 public static void main(String args[]) {
33 String[] testCaseName = { ActionTest.class.getName()};
34 junit.textui.TestRunner.main(testCaseName);
35 }
36
37 private Action action;
38
39 public void setUp() {
40 action = new Assign();
41 }
42
43 public void testGetParentStateIsState() throws Exception {
44 Transition transition = new Transition();
45
46 State state = new State();
47 state.setId("on");
48
49 transition.setParent(state);
50 action.setParent(transition);
51
52 State returnValue = action.getParentState();
53
54 assertEquals("on", returnValue.getId());
55 }
56
57 public void testGetParentStateIsParallel() throws Exception {
58 Transition transition = new Transition();
59
60 Parallel parallel = new Parallel();
61 parallel.setId("on");
62
63 State state = new State();
64 state.setId("off");
65
66 parallel.setParent(state);
67
68 transition.setParent(parallel);
69 action.setParent(transition);
70
71 State returnValue = action.getParentState();
72
73 assertEquals("off", returnValue.getId());
74 }
75
76 public void testGetParentStateIsHistory() throws Exception {
77 Transition transition = new Transition();
78
79 History history = new History();
80 history.setId("on");
81
82 State state = new State();
83 state.setId("off");
84
85 history.setParent(state);
86
87 transition.setParent(history);
88 action.setParent(transition);
89
90 State returnValue = action.getParentState();
91
92 assertEquals("off", returnValue.getId());
93 }
94
95 public void testGetParentStateIsInitial() {
96 Transition transition = new Transition();
97
98 Initial initial = new Initial();
99 initial.setId("on");
100
101 transition.setParent(initial);
102 action.setParent(transition);
103
104 try{
105 action.getParentState();
106 fail("Unknown TransitionTarget subclass:Initial");
107 }
108 catch( ModelException e ){
109
110 }
111 }
112 }