    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 java.net.URL;
    20
    21  import junit.framework.Test;
    22  import junit.framework.TestCase;
    23  import junit.framework.TestSuite;
    24  import junit.textui.TestRunner;
    25
    26  import org.apache.commons.scxml.SCXMLExecutor;
    27  import org.apache.commons.scxml.SCXMLTestHelper;
    28  import org.apache.commons.scxml.env.jsp.ELContext;
    29  import org.apache.commons.scxml.env.jsp.ELEvaluator;
    30  /***
    31   * Unit tests {@link org.apache.commons.scxml.model.Assign}.
    32   * Unit tests {@link org.apache.commons.scxml.model.Cancel}.
    33   * Unit tests {@link org.apache.commons.scxml.model.Else}.
    34   * Unit tests {@link org.apache.commons.scxml.model.Elseif}.
    35   * Unit tests {@link org.apache.commons.scxml.model.Exit}.
    36   * Unit tests {@link org.apache.commons.scxml.model.If}.
    37   * Unit tests {@link org.apache.commons.scxml.model.Log}.
    38   * Unit tests {@link org.apache.commons.scxml.model.Send}.
    39   * Unit tests {@link org.apache.commons.scxml.model.Var}.
    40   */
    41  public class ActionsTest extends TestCase {
    42      /***
    43       * Construct a new instance of ActionsTest with
    44       * the specified name
    45       */
    46      public ActionsTest(String name) {
    47          super(name);
    48      }
    49
    50      public static Test suite() {
    51          TestSuite suite = new TestSuite(ActionsTest.class);
    52          suite.setName("SCXML Model Actions Tests");
    53          return suite;
    54      }
    55
    56      // Test data
    57      private URL actionsSample;
    58      private ELEvaluator evaluator;
    59      private ELContext ctx;
    60      private SCXMLExecutor exec;
    61
    62      /***
    63       * Set up instance variables required by this test case.
    64       */
    65      public void setUp() {
    66          actionsSample = this.getClass().getClassLoader().
    67              getResource("org/apache/commons/scxml/model/actions-test.xml");
    68          evaluator = new ELEvaluator();
    69          ctx = new ELContext();
    70      }
    71
    72      /***
    73       * Tear down instance variables required by this test case.
    74       */
    75      public void tearDown() {
    76          actionsSample = null;
    77          evaluator = null;
    78          ctx = null;
    79          exec = null;
    80      }
    81
    82      /***
    83       * Test the implementation
    84       */
    85      public void testModelActions() {
    86          exec = SCXMLTestHelper.getExecutor(actionsSample, ctx, evaluator);
    87          ELContext ctx = (ELContext) SCXMLTestHelper.lookupContext(exec,
    88              "actionsTest");
    89          assertEquals((String) ctx.get("foo"), "foobar");
    90      }
    91
    92       public static void main(String args[]) {
    93          TestRunner.run(suite());
    94      }
    95  }
    96