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.core;
17  
18  import java.io.StringWriter;
19  
20  import junit.framework.TestSuite;
21  
22  import org.apache.commons.jelly.Script;
23  import org.apache.commons.jelly.XMLOutput;
24  import org.dom4j.io.HTMLWriter;
25  import org.dom4j.io.OutputFormat;
26  import org.dom4j.io.XMLWriter;
27  import org.xml.sax.SAXException;
28  
29  /***
30   * @author <a href="mailto:robert@bull-enterprises.com">Robert McIntosh</a>
31   * @version $Revision: 1.6 $
32   */
33  public class TestFileTag extends BaseJellyTest
34  {
35  
36      public TestFileTag(String name)
37      {
38          super(name);
39      }
40  
41      public static TestSuite suite() throws Exception
42      {
43          return new TestSuite(TestFileTag.class);
44      }
45  
46      public void testSimpleFileTag() throws Exception
47      {
48          setUpScript("testFileTag.jelly");
49          Script script = getJelly().compileScript();
50  
51          script.run(getJellyContext(), getXMLOutput());
52  
53          String data = (String)getJellyContext().getVariable("testFileTag");
54  
55          //FIXME This doesn't take into account attribute ordering
56          assertEquals("fully qualified attributes not passed",
57                  "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"></html>",
58                  data);
59      }
60  
61      public void testDom4Xmlns() throws SAXException {
62          StringWriter writer = new StringWriter();
63          OutputFormat format = new OutputFormat();
64          final XMLWriter xmlWriter = new HTMLWriter(writer, format);
65          xmlWriter.setEscapeText(false);
66  
67          XMLOutput output = new XMLOutput(xmlWriter, xmlWriter);
68  
69          String golden = "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
70          golden += "<html>";
71  
72          output.startDocument();
73          output.write(golden);
74          output.endDocument();
75          assertEquals("output should contain the namespaces", golden, writer.toString());
76      }
77  
78  }