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  
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.SCXMLTestHelper;
27  import org.apache.commons.scxml.model.SCXML;
28  /***
29   * Unit tests {@link org.apache.commons.scxml.SCXMLParser}.
30   */
31  public class SCXMLParserTest extends TestCase {
32      /***
33       * Construct a new instance of SCXMLDigesterTest with
34       * the specified name
35       */
36      public SCXMLParserTest(String name) {
37          super(name);
38      }
39  
40      public static Test suite() {
41          TestSuite suite = new TestSuite(SCXMLParserTest.class);
42          suite.setName("SCXML Parser Tests");
43          return suite;
44      }
45  
46      // Test data
47      private URL microwave03, microwave04;
48      private SCXML scxml;
49      private String scxmlAsString;
50  
51      /***
52       * Set up instance variables required by this test case.
53       */
54      public void setUp() {
55          microwave03 = this.getClass().getClassLoader().
56              getResource("org/apache/commons/scxml/env/jexl/microwave-03.xml");
57          microwave04 = this.getClass().getClassLoader().
58              getResource("org/apache/commons/scxml/env/jexl/microwave-04.xml");
59      }
60  
61      /***
62       * Tear down instance variables required by this test case.
63       */
64      public void tearDown() {
65          microwave03 = microwave04 = null;
66          scxml = null;
67          scxmlAsString = null;
68      }
69  
70      /***
71       * Test the implementation
72       */
73      public void testSCXMLParserMicrowave03Sample() {
74          scxml = SCXMLTestHelper.parse(microwave03);
75          assertNotNull(scxml);
76          scxmlAsString = serialize(scxml);
77          assertNotNull(scxmlAsString);
78      }
79  
80      public void testSCXMLParserMicrowave04Sample() {
81          scxml = SCXMLTestHelper.parse(microwave04);
82          assertNotNull(scxml);
83          scxmlAsString = serialize(scxml);
84          assertNotNull(scxmlAsString);
85      }
86  
87      private String serialize(final SCXML scxml) {
88          scxmlAsString = SCXMLSerializer.serialize(scxml);
89          assertNotNull(scxmlAsString);
90          return scxmlAsString;
91      }
92  
93       public static void main(String args[]) {
94          TestRunner.run(suite());
95      }
96  }
97