01: package org.apache.dvsl;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: import java.io.StringReader;
23: import java.io.StringWriter;
24:
25: import junit.framework.TestCase;
26:
27: import org.dom4j.Document;
28: import org.dom4j.io.SAXReader;
29:
30: /**
31: * Simple testcase to ensure things are basically working.
32: * This tests both a serialized document as well as a 'live'
33: * dom4j one.
34: *
35: * @author <a href="mailto:geirm@apache.org>Geir Magnusson Jr.</a>
36: */
37: public class TransformTest extends TestCase {
38: /*
39: * use simple in-memory style and input strings
40: */
41:
42: private String dvslstyle = "#match(\"element\")Hello from element! $node.value()#end";
43: private String input = "<?xml version=\"1.0\"?><document><element>Foo</element></document>";
44:
45: public TransformTest(String name) {
46: super (name);
47: }
48:
49: public void testSelection() {
50: try {
51: doit();
52: } catch (Exception e) {
53: fail(e.getMessage());
54: }
55: }
56:
57: public void doit() throws Exception {
58: /*
59: * make a dvsl
60: */
61:
62: DVSL dvsl = new DVSL();
63:
64: /*
65: * register the stylesheet
66: */
67:
68: dvsl.setStylesheet(new StringReader(dvslstyle));
69:
70: /*
71: * render the document as a Reader
72: */
73:
74: StringWriter sw = new StringWriter();
75:
76: dvsl.transform(new StringReader(input), sw);
77:
78: if (!sw.toString().equals("Hello from element! Foo"))
79: fail("Result of first test is wrong : " + sw.toString());
80:
81: /*
82: * now test if we can pass it a Document
83: */
84:
85: SAXReader sr = new SAXReader();
86:
87: Document document = sr.read(new StringReader(input));
88:
89: sw = new StringWriter();
90:
91: dvsl.transform(document, sw);
92:
93: if (!sw.toString().equals("Hello from element! Foo"))
94: fail("Result of second test is wrong : " + sw.toString());
95: }
96: }
|