    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.io;
    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.SCXMLExecutor;
    28  import org.apache.commons.scxml.SCXMLTestHelper;
    29  import org.apache.commons.scxml.model.SCXML;
    30  import org.apache.commons.scxml.model.State;
    31  /***
    32   * Unit tests {@link org.apache.commons.scxml.SCXMLDigester}
    33   * Test white box nature of <state> element "src" attribute.
    34   */
    35  public class StateSrcTest extends TestCase {
    36      /***
    37       * Construct a new instance of SCXMLDigesterTest with
    38       * the specified name
    39       */
    40      public StateSrcTest(String name) {
    41          super(name);
    42      }
    43
    44      public static Test suite() {
    45          TestSuite suite = new TestSuite(StateSrcTest.class);
    46          suite.setName("SCXML Digester Tests");
    47          return suite;
    48      }
    49
    50      // Test data
    51      private URL src01;
    52      private SCXML scxml;
    53      private SCXMLExecutor exec;
    54
    55      /***
    56       * Set up instance variables required by this test case.
    57       */
    58      public void setUp() {
    59          src01 = this.getClass().getClassLoader().
    60              getResource("org/apache/commons/scxml/io/src-test-1.xml");
    61      }
    62
    63      /***
    64       * Tear down instance variables required by this test case.
    65       */
    66      public void tearDown() {
    67          src01 = null;
    68          scxml = null;
    69          exec = null;
    70      }
    71
    72      /***
    73       * Test the implementation
    74       */
    75      public void testRecursiveSrcInclude() {
    76          scxml = SCXMLTestHelper.digest(src01);
    77          assertNotNull(scxml);
    78          exec = SCXMLTestHelper.getExecutor(scxml);
    79          assertNotNull(exec);
    80          Set states = exec.getCurrentStatus().getStates();
    81          assertEquals(1, states.size());
    82          assertEquals("srctest3", ((State) states.iterator().next()).getId());
    83          states = SCXMLTestHelper.fireEvent(exec, "src.test");
    84          assertEquals(1, states.size());
    85          assertEquals("srctest1end", ((State) states.iterator().next()).getId());
    86          assertTrue(exec.getCurrentStatus().isFinal());
    87      }
    88
    89       public static void main(String args[]) {
    90          TestRunner.run(suite());
    91      }
    92  }
    93