    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;
    18
    19  import java.net.URL;
    20  import java.util.Set;
    21
    22  import junit.framework.Test;
    23  import junit.framework.TestCase;
    24  import junit.framework.TestSuite;
    25  import junit.textui.TestRunner;
    26
    27  import org.apache.commons.scxml.model.State;
    28  /***
    29   * Unit tests {@link org.apache.commons.scxml.SCXMLExecutor}.
    30   * Testing wildcard event matching (*)
    31   */
    32  public class WildcardTest extends TestCase {
    33      /***
    34       * Construct a new instance of SCXMLExecutorTest with
    35       * the specified name
    36       */
    37      public WildcardTest(String name) {
    38          super(name);
    39      }
    40
    41      public static Test suite() {
    42          TestSuite suite = new TestSuite(WildcardTest.class);
    43          suite.setName("SCXML Executor Tests, wildcard event match");
    44          return suite;
    45      }
    46
    47      // Test data
    48      private URL wildcard01;
    49      private SCXMLExecutor exec;
    50
    51      /***
    52       * Set up instance variables required by this test case.
    53       */
    54      public void setUp() {
    55          wildcard01 = this.getClass().getClassLoader().
    56              getResource("org/apache/commons/scxml/env/jexl/wildcard-01.xml");
    57      }
    58
    59      /***
    60       * Tear down instance variables required by this test case.
    61       */
    62      public void tearDown() {
    63          wildcard01 = null;
    64      }
    65
    66      /***
    67       * Test the SCXML documents, usage of "_eventdata"
    68       */
    69      public void testWildcard01Sample() {
    70      	exec = SCXMLTestHelper.getExecutor(wildcard01);
    71          assertNotNull(exec);
    72          try {
    73              Set currentStates = exec.getCurrentStatus().getStates();
    74              assertEquals(1, currentStates.size());
    75              assertEquals("state1", ((State)currentStates.iterator().
    76                  next()).getId());
    77              exec = SCXMLTestHelper.testExecutorSerializability(exec);
    78              currentStates = SCXMLTestHelper.fireEvent(exec, "*");
    79              assertEquals(1, currentStates.size());
    80              assertEquals("state4", ((State)currentStates.iterator().
    81                  next()).getId());
    82          } catch (Exception e) {
    83              fail(e.getMessage());
    84          }
    85      }
    86
    87      public static void main(String args[]) {
    88          TestRunner.run(suite());
    89      }
    90  }