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.apache.commons.scxml2.Context; 020import org.apache.commons.scxml2.SCXMLExecutor; 021import org.apache.commons.scxml2.SCXMLTestHelper; 022import org.junit.Assert; 023import org.junit.Test; 024/** 025 * Unit tests {@link org.apache.commons.scxml2.model.Assign}. 026 * Unit tests {@link org.apache.commons.scxml2.model.Cancel}. 027 * Unit tests {@link org.apache.commons.scxml2.model.Else}. 028 * Unit tests {@link org.apache.commons.scxml2.model.ElseIf}. 029 * Unit tests {@link org.apache.commons.scxml2.model.If}. 030 * Unit tests {@link org.apache.commons.scxml2.model.Log}. 031 * Unit tests {@link org.apache.commons.scxml2.model.Send}. 032 * Unit tests {@link org.apache.commons.scxml2.model.Var}. 033 */ 034public class ActionsTest { 035 036 @Test 037 public void testStateActions() throws Exception { 038 SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/actions-state-test.xml"); 039 exec.go(); 040 runTest(exec); 041 } 042 043 @Test 044 public void testParallelActions() throws Exception { 045 SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/actions-parallel-test.xml"); 046 exec.go(); 047 runTest(exec); 048 } 049 050 @Test 051 public void testInitialActions() throws Exception { 052 SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/actions-initial-test.xml"); 053 exec.go(); 054 runTest(exec); 055 } 056 057 private void runTest(SCXMLExecutor exec) throws Exception { 058 Context ctx = SCXMLTestHelper.lookupContext(exec, "actionsTest"); 059 Assert.assertEquals(ctx.get("foo"), "foobar"); 060 Assert.assertEquals("Missed event transition", 061 true, ctx.get("eventsent")); 062 } 063} 064