001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.scxml.model;
018:
019: import junit.framework.Test;
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: public class ActionTest extends TestCase {
024:
025: public ActionTest(String testName) {
026: super (testName);
027: }
028:
029: public static Test suite() {
030: return new TestSuite(ActionTest.class);
031: }
032:
033: public static void main(String args[]) {
034: String[] testCaseName = { ActionTest.class.getName() };
035: junit.textui.TestRunner.main(testCaseName);
036: }
037:
038: private Action action;
039:
040: public void setUp() {
041: action = new Assign();
042: }
043:
044: public void testGetParentStateIsState() throws Exception {
045: Transition transition = new Transition();
046:
047: State state = new State();
048: state.setId("on");
049:
050: transition.setParent(state);
051: action.setParent(transition);
052:
053: State returnValue = action.getParentState();
054:
055: assertEquals("on", returnValue.getId());
056: }
057:
058: public void testGetParentStateIsParallel() throws Exception {
059: Transition transition = new Transition();
060:
061: Parallel parallel = new Parallel();
062: parallel.setId("on");
063:
064: State state = new State();
065: state.setId("off");
066:
067: parallel.setParent(state);
068:
069: transition.setParent(parallel);
070: action.setParent(transition);
071:
072: State returnValue = action.getParentState();
073:
074: assertEquals("off", returnValue.getId());
075: }
076:
077: public void testGetParentStateIsHistory() throws Exception {
078: Transition transition = new Transition();
079:
080: History history = new History();
081: history.setId("on");
082:
083: State state = new State();
084: state.setId("off");
085:
086: history.setParent(state);
087:
088: transition.setParent(history);
089: action.setParent(transition);
090:
091: State returnValue = action.getParentState();
092:
093: assertEquals("off", returnValue.getId());
094: }
095:
096: public void testGetParentStateIsInitial() {
097: Transition transition = new Transition();
098:
099: 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: } catch (ModelException e) {
109: //ignore
110: }
111: }
112: }
|