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  import java.util.Set;
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  /***
29   * Unit tests for <assign> element, particular the "src" attribute.
30   */
31  public class AssignTest extends TestCase {
32      /***
33       * Construct a new instance of AssignTest with
34       * the specified name
35       */
36      public AssignTest(String name) {
37          super(name);
38      }
39  
40      public static Test suite() {
41          TestSuite suite = new TestSuite(AssignTest.class);
42          suite.setName("SCXML Model Assign Tests");
43          return suite;
44      }
45  
46      // Test data
47      private SCXMLExecutor exec;
48  
49      /***
50       * Set up instance variables required by this test case.
51       */
52      public void setUp() {
53          URL assignSample = this.getClass().getClassLoader().
54              getResource("org/apache/commons/scxml/model/assign-test.xml");
55          exec = SCXMLTestHelper.getExecutor(assignSample);
56      }
57  
58      /***
59       * Tear down instance variables required by this test case.
60       */
61      public void tearDown() {
62          exec = null;
63      }
64  
65      /***
66       * Test the implementation
67       */
68      public void testAssignSrc() {
69          Set currentStates = exec.getCurrentStatus().getStates();
70          assertEquals(1, currentStates.size());
71          assertEquals("assign2", ((State)currentStates.iterator().
72              next()).getId());
73          assertTrue(exec.getCurrentStatus().isFinal());
74      }
75  
76       public static void main(String args[]) {
77          TestRunner.run(suite());
78      }
79  }
80