1   /*
2    * Copyright 2002,2004 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.jelly.test.xml;
17  
18  import java.net.URL;
19  
20  import junit.framework.TestCase;
21  import junit.framework.TestSuite;
22  
23  import org.apache.commons.jelly.Jelly;
24  import org.apache.commons.jelly.JellyContext;
25  import org.apache.commons.jelly.Script;
26  import org.apache.commons.jelly.XMLOutput;
27  
28  /***
29   * Confirm that <i>XMLOutput.createDummyXMLOutput()</i>
30   * doesn't do anything funky.
31   *
32   * @author Morgan Delagrange
33   * @version $Revision: 155420 $
34   */
35  public class TestDummyXMLOutput extends TestCase {
36  
37      Jelly jelly = null;
38      JellyContext context = null;
39      XMLOutput xmlOutput = null;
40  
41      public TestDummyXMLOutput(String name) {
42          super(name);
43      }
44  
45      public static TestSuite suite() throws Exception {
46          return new TestSuite(TestDummyXMLOutput.class);
47      }
48  
49      public void setUp(String scriptName) throws Exception {
50          this.context = new JellyContext();
51          this.xmlOutput = XMLOutput.createDummyXMLOutput();
52  
53          this.jelly = new Jelly();
54  
55          String script = scriptName;
56          URL url = this.getClass().getResource(script);
57          if ( url == null ) {
58              throw new Exception(
59                  "Could not find Jelly script: " + script
60                  + " in package of class: " + this.getClass().getName()
61              );
62          }
63          this.jelly.setUrl(url);
64      }
65  
66      public void testDummyXMLOutput() throws Exception {
67          // without validation
68          setUp("producesOutput.jelly");
69          Script script = this.jelly.compileScript();
70          script.run(this.context,this.xmlOutput);
71          assertTrue("should have set 'foo' variable to 'bar'",
72                     this.context.getVariable("foo").equals("bar"));
73  
74      }
75  
76  }