1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.scxml2.semantics;
18
19 import java.util.HashSet;
20 import java.util.Set;
21
22 import org.apache.commons.scxml2.env.MockErrorReporter;
23 import org.apache.commons.scxml2.env.SimpleErrorReporter;
24 import org.apache.commons.scxml2.model.EnterableState;
25 import org.apache.commons.scxml2.model.Parallel;
26 import org.apache.commons.scxml2.model.State;
27 import org.junit.Assert;
28 import org.junit.Test;
29
30 public class SCXMLSemanticsImplTest {
31
32 @Test
33 public void testIsLegalConfigNoStates() {
34 Set<EnterableState> states = new HashSet<EnterableState>();
35
36 Assert.assertTrue(new SCXMLSemanticsImpl().isLegalConfiguration(states, new SimpleErrorReporter()));
37 }
38
39 @Test
40 public void testIsLegalConfigInvalidParallel() {
41 Set<EnterableState> states = new HashSet<EnterableState>();
42 Parallel parallel = new Parallel();
43
44 Parallel parent = new Parallel();
45 parent.setId("4");
46
47 State state1 = new State();
48 state1.setId("1");
49 State state2 = new State();
50 state2.setId("2");
51
52 parent.addChild(state1);
53 parent.addChild(state2);
54
55 parallel.setParent(parent);
56
57 states.add(parallel);
58
59 MockErrorReporter errorReporter = new MockErrorReporter();
60
61 Assert.assertFalse(new SCXMLSemanticsImpl().isLegalConfiguration(states, errorReporter));
62 Assert.assertEquals(ErrorConstants.ILLEGAL_CONFIG, errorReporter.getErrCode());
63 Assert.assertEquals("Not all AND states active for parallel 4", errorReporter.getErrDetail());
64 }
65
66 @Test
67 public void testIsLegalConfigMultipleTopLevel() {
68 Set<EnterableState> states = new HashSet<EnterableState>();
69
70 State state1 = new State();
71 state1.setId("1");
72 State state2 = new State();
73 state2.setId("2");
74
75 states.add(state1);
76 states.add(state2);
77
78 MockErrorReporter errorReporter = new MockErrorReporter();
79
80 Assert.assertFalse(new SCXMLSemanticsImpl().isLegalConfiguration(states, errorReporter));
81 Assert.assertEquals(ErrorConstants.ILLEGAL_CONFIG, errorReporter.getErrCode());
82 Assert.assertEquals("Multiple top-level OR states active!", errorReporter.getErrDetail());
83 }
84
85 @Test
86 public void testIsLegalConfigMultipleStatesActive() {
87 Set<EnterableState> states = new HashSet<EnterableState>();
88
89 State state1 = new State();
90 state1.setId("1");
91
92 State state2 = new State();
93 state2.setId("2");
94
95 State parent = new State();
96 parent.setId("parentid");
97
98 state2.setParent(parent);
99 state1.setParent(parent);
100
101 states.add(state1);
102 states.add(state2);
103
104 MockErrorReporter errorReporter = new MockErrorReporter();
105
106 Assert.assertFalse(new SCXMLSemanticsImpl().isLegalConfiguration(states, errorReporter));
107 Assert.assertEquals(ErrorConstants.ILLEGAL_CONFIG, errorReporter.getErrCode());
108 Assert.assertEquals("Multiple OR states active for state parentid", errorReporter.getErrDetail());
109 }
110 }