1   package org.apache.dvsl;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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  {
38      public static Test suite()
39      {
40          return new TestSuite(XPathTest.class);
41      }
42  
43      public XPathTest(String testName)
44      {
45          super(testName);
46      }
47  
48      /**
49       *  ensure we can match CDATA sections
50       */
51      public void testCDATA()
52          throws Exception
53      {
54          String dvslstyle = "#match(\"text()\")$node.value()#end";
55          String input = "<?xml version=\"1.0\"?><document><![CDATA[Hello from CDATA]]></document>";
56          DVSL dvsl = new DVSL();
57  
58          /*
59           *  register the stylesheet
60           */
61  
62          dvsl.setStylesheet( new StringReader(dvslstyle) );
63  
64          /*
65           *  render the document as a Reader
66           */
67  
68          StringWriter sw = new StringWriter();
69  
70          dvsl.transform( new StringReader( input ), sw );
71  
72          assertTrue("First Test : " + sw.toString(),
73                  sw.toString().equals("Hello from CDATA"));
74      }
75  
76      /**
77       *  ensure that the Union is working
78       */
79      public void testUNION()
80          throws Exception
81      {
82          String dvslstyle = "#match(\"p | document \")Matched#end";
83          String input = "<?xml version=\"1.0\"?><document>document</document>";
84          DVSL dvsl = new DVSL();
85  
86          /*
87           *  register the stylesheet
88           */
89  
90          dvsl.setStylesheet( new StringReader(dvslstyle) );
91  
92          /*
93           *  render the document as a Reader
94           */
95  
96          StringWriter sw = new StringWriter();
97  
98          dvsl.transform( new StringReader( input ), sw );
99  
100         assertTrue("First Test : " + sw.toString(),
101                sw.toString().equals("Matched"));
102     }
103 
104 }