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;
17  
18  import java.io.ByteArrayOutputStream;
19  
20  import org.apache.commons.jelly.Script;
21  import org.apache.commons.jelly.XMLOutput;
22  import org.apache.commons.jelly.test.BaseJellyTest;
23  
24  /***
25   * @author Hans Gilde
26   *
27   */
28  public class TestXMLOutput extends BaseJellyTest {
29  
30      /*** JUnit constructor
31       * @param name
32       */
33      public TestXMLOutput(String name) {
34          super(name);
35      }
36      
37      public void testOutputGood() throws Exception {
38          setUpScript("outputGood.jelly");
39          Script script = getJelly().compileScript();
40          
41          ByteArrayOutputStream bos = new ByteArrayOutputStream();
42          
43          script.run(getJellyContext(),XMLOutput.createXMLOutput(bos));
44          assertEquals("<html></html>x",bos.toString());
45      }
46      
47      public void testOutputBad() throws Exception {
48          setUpScript("outputBad.jelly");
49          Script script = getJelly().compileScript();
50          
51          ByteArrayOutputStream bos = new ByteArrayOutputStream();
52          
53          script.run(getJellyContext(),XMLOutput.createXMLOutput(bos));
54          assertEquals("<html></html>",bos.toString());
55      }
56      
57      public void testOutputBadGood() throws Exception {
58          setUpScript("outputBad.jelly");
59          Script script = getJelly().compileScript();
60          
61          ByteArrayOutputStream bos = new ByteArrayOutputStream();
62          
63          XMLOutput ouput = XMLOutput.createXMLOutput(bos);
64          
65          script.run(getJellyContext(),ouput);
66          ouput.flush();
67          assertEquals("<html></html>",bos.toString());
68      }
69      
70      public void testOutputData() throws Exception {
71          setUpScript("outputData.jelly");
72          Script script = getJelly().compileScript();
73  
74          ByteArrayOutputStream bos = new ByteArrayOutputStream();
75          XMLOutput ouput = XMLOutput.createXMLOutput(bos);
76  
77          script.run(getJellyContext(),ouput);
78          ouput.flush();
79          assertEquals("[string]",bos.toString().trim());
80  	}
81  }