001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.scxml.io;
018:
019: import java.net.URL;
020: import java.util.List;
021:
022: import junit.framework.Test;
023: import junit.framework.TestCase;
024: import junit.framework.TestSuite;
025: import junit.textui.TestRunner;
026:
027: import org.apache.commons.scxml.SCXMLTestHelper;
028: import org.apache.commons.scxml.model.SCXML;
029: import org.apache.commons.scxml.model.Send;
030: import org.apache.commons.scxml.model.State;
031: import org.apache.commons.scxml.model.Transition;
032:
033: /**
034: * Unit tests {@link org.apache.commons.scxml.SCXMLDigester}.
035: */
036: public class SCXMLDigesterTest extends TestCase {
037: /**
038: * Construct a new instance of SCXMLDigesterTest with
039: * the specified name
040: */
041: public SCXMLDigesterTest(String name) {
042: super (name);
043: }
044:
045: public static Test suite() {
046: TestSuite suite = new TestSuite(SCXMLDigesterTest.class);
047: suite.setName("SCXML Digester Tests");
048: return suite;
049: }
050:
051: // Test data
052: private URL microwave01, microwave02, transitions01, send01,
053: prefix01;
054: private SCXML scxml;
055: private String scxmlAsString;
056:
057: /**
058: * Set up instance variables required by this test case.
059: */
060: public void setUp() {
061: microwave01 = this .getClass().getClassLoader().getResource(
062: "org/apache/commons/scxml/env/jsp/microwave-01.xml");
063: microwave02 = this .getClass().getClassLoader().getResource(
064: "org/apache/commons/scxml/env/jsp/microwave-02.xml");
065: transitions01 = this .getClass().getClassLoader().getResource(
066: "org/apache/commons/scxml/transitions-01.xml");
067: send01 = this .getClass().getClassLoader().getResource(
068: "org/apache/commons/scxml/send-01.xml");
069: prefix01 = this .getClass().getClassLoader().getResource(
070: "org/apache/commons/scxml/prefix-01.xml");
071: }
072:
073: /**
074: * Tear down instance variables required by this test case.
075: */
076: public void tearDown() {
077: microwave01 = microwave02 = transitions01 = prefix01 = send01 = null;
078: scxml = null;
079: scxmlAsString = null;
080: }
081:
082: /**
083: * Test the implementation
084: */
085: public void testSCXMLDigesterMicrowave01Sample() {
086: scxml = SCXMLTestHelper.digest(microwave01);
087: assertNotNull(scxml);
088: scxmlAsString = serialize(scxml);
089: assertNotNull(scxmlAsString);
090: }
091:
092: public void testSCXMLDigesterMicrowave02Sample() {
093: scxml = SCXMLTestHelper.digest(microwave02);
094: assertNotNull(scxml);
095: scxmlAsString = serialize(scxml);
096: assertNotNull(scxmlAsString);
097: }
098:
099: public void testSCXMLDigesterTransitions01Sample() {
100: scxml = SCXMLTestHelper.digest(transitions01);
101: assertNotNull(scxml);
102: scxmlAsString = serialize(scxml);
103: assertNotNull(scxmlAsString);
104: }
105:
106: public void testSCXMLDigesterPrefix01Sample() {
107: scxml = SCXMLTestHelper.digest(prefix01);
108: assertNotNull(scxml);
109: scxmlAsString = serialize(scxml);
110: assertNotNull(scxmlAsString);
111: }
112:
113: public void testSCXMLDigesterSend01Sample() {
114: // Digest
115: scxml = SCXMLTestHelper.digest(send01);
116: State ten = scxml.getInitialState();
117: assertEquals("ten", ten.getId());
118: List ten_done = ten.getTransitionsList("ten.done");
119: assertEquals(1, ten_done.size());
120: Transition ten2twenty = (Transition) ten_done.get(0);
121: List actions = ten2twenty.getActions();
122: assertEquals(1, actions.size());
123: Send send = (Send) actions.get(0);
124: assertEquals("send1", send.getSendid());
125: /* Serialize
126: scxmlAsString = serialize(scxml);
127: assertNotNull(scxmlAsString);
128: String expectedFoo2Serialization =
129: "<foo xmlns=\"http://my.test.namespace\" id=\"foo2\">"
130: + "<prompt xmlns=\"http://foo.bar.com/vxml3\">This is just"
131: + " an example.</prompt></foo>";
132: assertFalse(scxmlAsString.indexOf(expectedFoo2Serialization) == -1);
133: */
134: }
135:
136: private String serialize(final SCXML scxml) {
137: scxmlAsString = SCXMLSerializer.serialize(scxml);
138: assertNotNull(scxmlAsString);
139: return scxmlAsString;
140: }
141:
142: public static void main(String args[]) {
143: TestRunner.run(suite());
144: }
145: }
|