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 */
017package org.apache.commons.scxml2.model;
018
019import org.junit.Assert;
020import org.junit.Before;
021import org.junit.Test;
022
023public class ActionTest {
024
025    private Action action;
026    
027    @Before
028    public void setUp() {
029        action = new Assign();
030    }
031    @Test
032    public void testGetParentStateIsState() throws Exception {
033        Transition transition = new Transition();
034        
035        State state = new State();
036        state.setId("on");
037        
038        transition.setParent(state);
039        action.setParent(transition);
040
041        TransitionTarget returnValue = action.getParentEnterableState();
042        
043        Assert.assertEquals("on", returnValue.getId());
044    }
045    
046    @Test
047    public void testGetParentStateIsParallel() throws Exception {
048        Transition transition = new Transition();
049        
050        Parallel parallel = new Parallel();
051        parallel.setId("on");
052 
053        State state = new State();
054        state.setId("off");
055        
056        parallel.setParent(state);
057
058        transition.setParent(parallel);
059        action.setParent(transition);
060
061        TransitionTarget returnValue = action.getParentEnterableState();
062        
063        Assert.assertEquals("on", returnValue.getId());
064    }
065    
066    @Test
067    public void testGetParentStateIsHistory() throws Exception {
068        Transition transition = new Transition();
069        
070        History history = new History();
071        history.setId("on");
072 
073        State state = new State();
074        state.setId("off");
075        
076        history.setParent(state);
077
078        transition.setParent(history.getParent());
079        action.setParent(transition);
080
081        TransitionTarget returnValue = action.getParentEnterableState();
082        
083        Assert.assertEquals("off", returnValue.getId());
084    }
085    
086    @Test
087    public void testGetParentStateIsInitial() throws Exception {
088        SimpleTransition transition = new SimpleTransition();
089        
090        Initial initial = new Initial();
091
092        State state = new State();
093        state.setId("off");
094
095        initial.setParent(state);
096
097        initial.setTransition(transition);
098        action.setParent(transition);
099
100        TransitionTarget returnValue = action.getParentEnterableState();
101
102        Assert.assertEquals("off", returnValue.getId());
103    }
104}