1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.commons.scxml.model;
17  
18  import java.net.URL;
19  
20  import junit.framework.Test;
21  import junit.framework.TestCase;
22  import junit.framework.TestSuite;
23  import junit.textui.TestRunner;
24  
25  import org.apache.commons.scxml.SCXMLExecutor;
26  import org.apache.commons.scxml.SCXMLTestHelper;
27  import org.apache.commons.scxml.env.jsp.ELContext;
28  import org.apache.commons.scxml.env.jsp.ELEvaluator;
29  /***
30   * Unit tests {@link org.apache.commons.scxml.model.Assign}.
31   * Unit tests {@link org.apache.commons.scxml.model.Cancel}.
32   * Unit tests {@link org.apache.commons.scxml.model.Else}.
33   * Unit tests {@link org.apache.commons.scxml.model.Elseif}.
34   * Unit tests {@link org.apache.commons.scxml.model.Exit}.
35   * Unit tests {@link org.apache.commons.scxml.model.If}.
36   * Unit tests {@link org.apache.commons.scxml.model.Log}.
37   * Unit tests {@link org.apache.commons.scxml.model.Send}.
38   * Unit tests {@link org.apache.commons.scxml.model.Var}.
39   */
40  public class ActionsTest extends TestCase {
41      /***
42       * Construct a new instance of ActionsTest with
43       * the specified name
44       */
45      public ActionsTest(String name) {
46          super(name);
47      }
48  
49      public static Test suite() {
50          TestSuite suite = new TestSuite(ActionsTest.class);
51          suite.setName("SCXML Model Actions Tests");
52          return suite;
53      }
54  
55      // Test data
56      private URL actionsSample;
57      private ELEvaluator evaluator;
58      private ELContext ctx;
59      private SCXMLExecutor exec;
60  
61      /***
62       * Set up instance variables required by this test case.
63       */
64      public void setUp() {
65          actionsSample = this.getClass().getClassLoader().
66              getResource("org/apache/commons/scxml/model/actions-test.xml");
67          evaluator = new ELEvaluator();
68          ctx = new ELContext();
69      }
70  
71      /***
72       * Tear down instance variables required by this test case.
73       */
74      public void tearDown() {
75          actionsSample = null;
76          evaluator = null;
77          ctx = null;
78          exec = null;
79      }
80  
81      /***
82       * Test the implementation
83       */
84      public void testModelActions() {
85          exec = SCXMLTestHelper.getExecutor(actionsSample, ctx, evaluator);
86          ELContext ctx = (ELContext) SCXMLTestHelper.lookupContext(exec,
87              "actionsTest");
88          assertEquals((String) ctx.get("foo"), "foobar");
89      }
90  
91       public static void main(String args[]) {
92          TestRunner.run(suite());
93      }
94  }
95