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 junit.framework.TestCase;
23: import junit.framework.Test;
24: import junit.framework.TestSuite;
25:
26: import java.io.StringReader;
27: import java.io.StringWriter;
28:
29: /**
30: * Tests some Xpath peculiarities
31: *
32: * @author <a href="mailto:geirm@apache.org>Geir Magnusson Jr.</a>
33: * @version $Id: XPathTest.java 537999 2007-05-14 21:58:32Z cbrisson $
34: *
35: */
36: public class XPathTest extends TestCase {
37: public static Test suite() {
38: return new TestSuite(XPathTest.class);
39: }
40:
41: public XPathTest(String testName) {
42: super (testName);
43: }
44:
45: /**
46: * ensure we can match CDATA sections
47: */
48: public void testCDATA() throws Exception {
49: String dvslstyle = "#match(\"text()\")$node.value()#end";
50: String input = "<?xml version=\"1.0\"?><document><![CDATA[Hello from CDATA]]></document>";
51: DVSL dvsl = new DVSL();
52:
53: /*
54: * register the stylesheet
55: */
56:
57: dvsl.setStylesheet(new StringReader(dvslstyle));
58:
59: /*
60: * render the document as a Reader
61: */
62:
63: StringWriter sw = new StringWriter();
64:
65: dvsl.transform(new StringReader(input), sw);
66:
67: assertTrue("First Test : " + sw.toString(), sw.toString()
68: .equals("Hello from CDATA"));
69: }
70:
71: /**
72: * ensure that the Union is working
73: */
74: public void testUNION() throws Exception {
75: String dvslstyle = "#match(\"p | document \")Matched#end";
76: String input = "<?xml version=\"1.0\"?><document>document</document>";
77: DVSL dvsl = new DVSL();
78:
79: /*
80: * register the stylesheet
81: */
82:
83: dvsl.setStylesheet(new StringReader(dvslstyle));
84:
85: /*
86: * render the document as a Reader
87: */
88:
89: StringWriter sw = new StringWriter();
90:
91: dvsl.transform(new StringReader(input), sw);
92:
93: assertTrue("First Test : " + sw.toString(), sw.toString()
94: .equals("Matched"));
95: }
96:
97: }
|