View Javadoc
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.scxml2.model;
18  
19  import org.apache.commons.scxml2.Context;
20  import org.apache.commons.scxml2.SCXMLExecutor;
21  import org.apache.commons.scxml2.SCXMLTestHelper;
22  import org.junit.Assert;
23  import org.junit.Test;
24  /**
25   * Unit tests {@link org.apache.commons.scxml2.model.Assign}.
26   * Unit tests {@link org.apache.commons.scxml2.model.Cancel}.
27   * Unit tests {@link org.apache.commons.scxml2.model.Else}.
28   * Unit tests {@link org.apache.commons.scxml2.model.ElseIf}.
29   * Unit tests {@link org.apache.commons.scxml2.model.If}.
30   * Unit tests {@link org.apache.commons.scxml2.model.Log}.
31   * Unit tests {@link org.apache.commons.scxml2.model.Send}.
32   * Unit tests {@link org.apache.commons.scxml2.model.Var}.
33   */
34  public class ActionsTest {
35  
36      @Test
37      public void testStateActions() throws Exception {
38          SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/actions-state-test.xml");
39          exec.go();
40          runTest(exec);
41      }
42      
43      @Test
44      public void testParallelActions() throws Exception {
45          SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/actions-parallel-test.xml");
46          exec.go();
47          runTest(exec);
48      }
49      
50      @Test
51      public void testInitialActions() throws Exception {
52          SCXMLExecutor exec = SCXMLTestHelper.getExecutor("org/apache/commons/scxml2/model/actions-initial-test.xml");
53          exec.go();
54          runTest(exec);
55      }
56  
57      private void runTest(SCXMLExecutor exec) throws Exception {
58          Context ctx = SCXMLTestHelper.lookupContext(exec, "actionsTest");
59          Assert.assertEquals(ctx.get("foo"), "foobar");
60          Assert.assertEquals("Missed event transition",
61              true, ctx.get("eventsent"));
62      }
63  }
64