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: TestModelToXML.java,v 1.6 2002/09/12 19:09:36 ludovicc Exp $
37 */
38 package test.view.servlet.xml;
39
40
41 import junit.framework.TestCase;
42 import org.scopemvc.core.Selector;
43 import org.scopemvc.view.servlet.xml.ModelToXML;
44 import org.scopemvc.view.servlet.xml.PropertyIDGenerator;
45
46 /***
47 * <P>
48 *
49 * ***** This is all dependent on Xalan's XPath API. </P>
50 *
51 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>Steve Meyfroidt</A>
52 * @created 05 September 2002
53 * @version $Revision: 1.6 $ $Date: 2002/09/12 19:09:36 $
54 */
55 public final class TestModelToXML extends TestCase {
56
57 private PropertyIDGenerator propertyIDGenerator;
58 private ModelToXML modelToXML;
59
60
61 /***
62 * Constructor for the TestModelToXML object
63 *
64 * @param inName Name of the test
65 */
66 public TestModelToXML(String inName) {
67 super(inName);
68 }
69
70 /***
71 * Empty test to make junit happy, to remove once the other tests are
72 * uncommented
73 */
74 public void testEmpty() {
75 // noop
76 }
77
78
79 /***
80 * The JUnit setup method
81 *
82 * @throws Exception Any abnormal exception
83 */
84 protected void setUp() throws Exception {
85 propertyIDGenerator =
86 new PropertyIDGenerator() {
87 public String getPropertyID() {
88 return Selector.asString(currentPropertySelector);
89 }
90 };
91 modelToXML = new ModelToXML();
92 }
93
94 /***
95 * [?xml ...] [data id="_0"] [a id="a"]99[/a] [name id="name"]Steve[/name]
96 * [/data]
97 */
98 // public void testSimpleModel() throws Exception {
99 // Document doc= DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
100 // ContentHandler domBuilder = new SAXResult(doc); new DOMBuilder(doc);
101 //
102 // Object model = new SimpleModel();
103 //
104 // modelToXML.modelToXML(model, domBuilder, propertyIDGenerator);
105 //
106 // Element root = doc.getDocumentElement();
107 // assertEquals("data", root.getNodeName());
108 // assertEquals("_0", XPathAPI.selectSingleNode(doc, "data/@id").getNodeValue());
109 //
110 // assertEquals("99", XPathAPI.selectSingleNode(doc, "data/a").getFirstChild().getNodeValue());
111 // assertEquals("a", XPathAPI.selectSingleNode(doc, "data/a/@id").getNodeValue());
112 //
113 // assertEquals("Steve", XPathAPI.selectSingleNode(doc, "data/name").getFirstChild().getNodeValue());
114 // assertEquals("name", XPathAPI.selectSingleNode(doc, "data/name/@id").getNodeValue());
115 // }
116
117
118 /***
119 * [?xml ...] [data id="_0"] [a id="a"]99[/a] [name id="name"]Steve[/name]
120 * [submodel id="submodel"] [data id="_1"] [a id="submodel.a"]99[/a] [name
121 * id="submodel.name"]Steve[/name] [/data] [/submodel] [/data]
122 */
123 // public void testContainerModel1() throws Exception {
124 // Document doc= DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
125 // ContentHandler domBuilder = new DOMBuilder(doc);
126 //
127 // ContainerModel model = new ContainerModel();
128 // model.setSubmodel(new ContainerModel());
129 //
130 // modelToXML.modelToXML(model, domBuilder, propertyIDGenerator);
131 //
132 // Element root = doc.getDocumentElement();
133 // assertEquals("data", root.getNodeName());
134 // assertEquals("_0", root.getAttribute("id"));
135 //
136 // assertEquals("99", XPathAPI.selectSingleNode(doc, "data/a").getFirstChild().getNodeValue());
137 // assertEquals("a", XPathAPI.selectSingleNode(doc, "data/a/@id").getNodeValue());
138 //
139 // assertEquals("Steve", XPathAPI.selectSingleNode(doc, "data/name").getFirstChild().getNodeValue());
140 // assertEquals("name", XPathAPI.selectSingleNode(doc, "data/name/@id").getNodeValue());
141 //
142 // assertEquals("submodel", XPathAPI.selectSingleNode(doc, "data/submodel/@id").getNodeValue());
143 // assertEquals("_1", XPathAPI.selectSingleNode(doc, "data/submodel/data/@id").getNodeValue());
144 //
145 // assertEquals("99", XPathAPI.selectSingleNode(doc, "data/submodel/data/a").getFirstChild().getNodeValue());
146 // assertEquals("submodel.a", XPathAPI.selectSingleNode(doc, "data/submodel/data/a/@id").getNodeValue());
147 //
148 // assertEquals("Steve", XPathAPI.selectSingleNode(doc, "data/submodel/data/name").getFirstChild().getNodeValue());
149 // assertEquals("submodel.name", XPathAPI.selectSingleNode(doc, "data/submodel/data/name/@id").getNodeValue());
150 // }
151
152
153 /***
154 * [?xml ...] [data id="_0"] [a id="a"]99[/a] [name id="name"]Steve[/name]
155 * [submodel id="submodel"] [data idref="_0" /] [/submodel] [/data]
156 */
157 // public void testContainerModel2() throws Exception {
158 // Document doc= DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
159 // ContentHandler domBuilder = new DOMBuilder(doc);
160 //
161 // ContainerModel model = new ContainerModel();
162 // model.setSubmodel(model);
163 //
164 // modelToXML.modelToXML(model, domBuilder, propertyIDGenerator);
165 //
166 // Element root = doc.getDocumentElement();
167 // assertEquals("data", root.getNodeName());
168 // assertEquals("_0", root.getAttribute("id"));
169 //
170 // assertEquals("99", XPathAPI.selectSingleNode(doc, "data/a").getFirstChild().getNodeValue());
171 // assertEquals("a", XPathAPI.selectSingleNode(doc, "data/a/@id").getNodeValue());
172 //
173 // assertEquals("Steve", XPathAPI.selectSingleNode(doc, "data/name").getFirstChild().getNodeValue());
174 // assertEquals("name", XPathAPI.selectSingleNode(doc, "data/name/@id").getNodeValue());
175 //
176 // assertEquals("submodel", XPathAPI.selectSingleNode(doc, "data/submodel/@id").getNodeValue());
177 // assertEquals("_0", XPathAPI.selectSingleNode(doc, "data/submodel/data/@idref").getNodeValue());
178 // }
179
180
181 /***
182 * [?xml ...] [data id="_0"] [element index="0" id="0"]a[/element] [element
183 * index="1" id="1"]b[/element] [element index="2" id="2"] [data id="_1"] [a
184 * id="2.a"]99[/a] [name id="2.name"]Steve[/a] [/data] [/element] [element
185 * index="3" id="3"] [data idref="_1" /] [/element] [/data]
186 */
187 // public void testList() throws Exception {
188 // Document doc= DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
189 // ContentHandler domBuilder = new DOMBuilder(doc);
190 //
191 // List model = Arrays.asList(new Object[]{"a","b","c","d"});
192 // SimpleModel simpleModel = new SimpleModel();
193 // model.set(2, simpleModel);
194 // model.set(3, simpleModel);
195 //
196 // modelToXML.modelToXML(model, domBuilder, propertyIDGenerator);
197 //
198 // Element root = doc.getDocumentElement();
199 // assertEquals("data", root.getNodeName());
200 // assertEquals("_0", root.getAttribute("id"));
201 //
202 // assertEquals("a", XPathAPI.selectSingleNode(doc, "data/element[@index='0']").getFirstChild().getNodeValue());
203 // assertEquals("0", XPathAPI.selectSingleNode(doc, "data/element[@index='0']/@id").getNodeValue());
204 //
205 // assertEquals("b", XPathAPI.selectSingleNode(doc, "data/element[@index='1']").getFirstChild().getNodeValue());
206 // assertEquals("1", XPathAPI.selectSingleNode(doc, "data/element[@index='1']/@id").getNodeValue());
207 //
208 // assertEquals("2", XPathAPI.selectSingleNode(doc, "data/element[@index='2']/@id").getNodeValue());
209 // assertEquals("_1", XPathAPI.selectSingleNode(doc, "data/element[@index='2']/data/@id").getNodeValue());
210 //
211 // assertEquals("2.a", XPathAPI.selectSingleNode(doc, "data/element[@index='2']/data/a/@id").getNodeValue());
212 // assertEquals("2.name", XPathAPI.selectSingleNode(doc, "data/element[@index='2']/data/name/@id").getNodeValue());
213 //
214 // assertEquals("99", XPathAPI.selectSingleNode(doc, "data/element[@index='2']/data/a").getFirstChild().getNodeValue());
215 // assertEquals("Steve", XPathAPI.selectSingleNode(doc, "data/element[@index='2']/data/name").getFirstChild().getNodeValue());
216 //
217 // assertEquals("3", XPathAPI.selectSingleNode(doc, "data/element[@index='3']/@id").getNodeValue());
218 // assertEquals("_1", XPathAPI.selectSingleNode(doc, "data/element[@index='3']/data/@idref").getNodeValue());
219 // }
220 }
This page was automatically generated by Maven