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