    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    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         	//ignore
    111         }
    112     }
    113 }