1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, The Scope team
4 * All rights reserved.
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Neither the name "Scope" nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 *
36 * $Id: TestAbstractServletXSLView.java,v 1.7 2002/09/12 19:09:36 ludovicc Exp $
37 */
38 package test.view.servlet.xml;
39
40 import java.io.FileOutputStream;
41 import java.io.OutputStream;
42 import java.io.StringWriter;
43 import java.net.URL;
44 import java.util.HashMap;
45 import org.w3c.dom.Document;
46 import org.w3c.dom.Element;
47 import junit.framework.TestCase;
48
49 import org.scopemvc.view.servlet.xml.AbstractXSLPage;
50 import org.scopemvc.view.servlet.xml.XSLPage;
51 import org.xml.sax.ContentHandler;
52
53 /***
54 * <P>
55 *
56 * </P>
57 *
58 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>Steve Meyfroidt</A>
59 * @created 05 September 2002
60 * @version $Revision: 1.7 $ $Date: 2002/09/12 19:09:36 $
61 */
62 public final class TestAbstractServletXSLView extends TestCase {
63
64 private DummyXSLView view;
65
66
67 /***
68 * Constructor for the TestAbstractServletXSLView object
69 *
70 * @param inName Name of the test
71 */
72 public TestAbstractServletXSLView(String inName) {
73 super(inName);
74 }
75
76
77 /***
78 * A unit test for JUnit
79 *
80 * @throws Exception Any abnormal exception
81 */
82 public void testGetSetSystemID() throws Exception {
83 assertEquals("", view.getSystemID());
84
85 view.setSystemID("a");
86 assertEquals("a", view.getSystemID());
87
88 view.setSystemID(null);
89 }
90
91
92 /***
93 * A unit test for JUnit
94 *
95 * @throws Exception Any abnormal exception
96 */
97 public void testGetSetXslUri() throws Exception {
98 DummyXSLView v = new DummyXSLView();
99 assertNull(v.getXslURI());
100
101 assertTrue(view.getXslURI().endsWith("/test/view/servlet/xml/test.xsl"));
102
103 view.setXslURI("xyz");
104 assertEquals("xyz", view.getXslURI());
105 }
106
107
108 /***
109 * A unit test for JUnit
110 *
111 * @throws Exception Any abnormal exception
112 */
113 public void testGetContentType() throws Exception {
114 assertEquals("text/html", view.getContentType());
115
116 view = new DummyXSLView();
117 assertEquals("text/xml", view.getContentType());
118 }
119
120
121 /***
122 * The JUnit setup method
123 *
124 * @throws Exception Any abnormal exception
125 */
126 protected void setUp() throws Exception {
127 view = new DummyXSLView();
128 URL xslURL = getClass().getResource("/test/view/servlet/xml/test.xsl");
129 assertTrue(xslURL != null);
130 view.setXslURI(xslURL.toString());
131 }
132
133 // Both these fail with LinkageErrors trying load org.xmlContentHandler
134 // public void testStream1() throws Exception {
135 // assertEquals("", view.getSystemID());
136 // StringWriter writer = new StringWriter();
137 // view.streamView(writer);
138 // assertTrue(writer.toString().indexOf("<HTML>") > -1);
139 //
140 // writer = new StringWriter();
141 // view.streamView(writer);
142 // assertTrue(writer.toString().indexOf("<HTML>") > -1);
143 // }
144 //
145 //
146 // public void testStream2() throws Exception {
147 // view.setCache(true);
148 // StringWriter writer = new StringWriter();
149 // view.streamView(writer);
150 // assertTrue(writer.toString().indexOf("<HTML>") > -1);
151 //
152 // writer = new StringWriter();
153 // view.streamView(writer);
154 // assertTrue(writer.toString().indexOf("<HTML>") > -1);
155 // }
156 }
157
158 final class DummyXSLView extends AbstractXSLPage {
159
160 /***
161 * Constructor for the DummyXSLView object
162 */
163 DummyXSLView() {
164 super(null, null);
165 shouldCacheTemplates = false;
166 }
167
168 /***
169 * TODO: document the method
170 *
171 * @param inContentHandler TODO: Describe the Parameter
172 * @throws Exception Any abnormal exception
173 */
174 protected void generateXMLDocument(ContentHandler inContentHandler) throws Exception {
175 inContentHandler.startDocument();
176
177 inContentHandler.startElement("", "elem", "elem", null);
178 inContentHandler.endElement("", "elem", "elem");
179
180 inContentHandler.endDocument();
181 }
182
183 /***
184 * Sets the cache
185 *
186 * @param inCache The new cache value
187 */
188 void setCache(boolean inCache) {
189 shouldCacheTemplates = inCache;
190 }
191 }
This page was automatically generated by Maven