View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.jxpath.ri.model;
18  
19  import org.apache.commons.jxpath.JXPathContext;
20  import org.apache.commons.jxpath.JXPathTestCase;
21  import org.apache.commons.jxpath.xml.DocumentContainer;
22  
23  /**
24   * Test for text trimming from JXPATH-83.
25   *
26   * @author Matt Benson
27   * @version $Revision: 652845 $ $Date: 2008-05-02 19:46:46 +0200 (Fr, 02 Mai 2008) $
28   */
29  public class XMLSpaceTest extends JXPathTestCase {
30      protected JXPathContext context;
31  
32      protected DocumentContainer createDocumentContainer(String model) {
33          return new DocumentContainer(JXPathTestCase.class
34                  .getResource("XmlSpace.xml"), model);
35      }
36  
37      protected JXPathContext createContext(String model) {
38          JXPathContext context = JXPathContext
39                  .newContext(createDocumentContainer(model));
40          return context;
41      }
42  
43      protected void doTest(String id, String model, String expectedValue) {
44          JXPathContext context = JXPathContext
45                  .newContext(createDocumentContainer(model));
46          assertEquals(context.getValue("test/text[@id='" + id + "']"), expectedValue);
47      }
48  
49      public void testUnspecifiedDOM() {
50          doTest("unspecified", DocumentContainer.MODEL_DOM, "foo");
51      }
52  
53      public void testDefaultDOM() {
54          doTest("default", DocumentContainer.MODEL_DOM, "foo");
55      }
56  
57      public void testPreserveDOM() {
58          doTest("preserve", DocumentContainer.MODEL_DOM, " foo ");
59      }
60  
61      public void testNestedDOM() {
62          doTest("nested", DocumentContainer.MODEL_DOM, "foo;bar; baz ");
63      }
64  
65      public void testNestedWithCommentsDOM() {
66          doTest("nested-with-comments", DocumentContainer.MODEL_DOM, "foo;bar; baz ");
67      }
68  
69      public void testUnspecifiedJDOM() {
70          doTest("unspecified", DocumentContainer.MODEL_JDOM, "foo");
71      }
72  
73      public void testDefaultJDOM() {
74          doTest("default", DocumentContainer.MODEL_JDOM, "foo");
75      }
76  
77      public void testPreserveJDOM() {
78          doTest("preserve", DocumentContainer.MODEL_JDOM, " foo ");
79      }
80  
81      public void testNestedJDOM() {
82          doTest("nested", DocumentContainer.MODEL_JDOM, "foo;bar; baz ");
83      }
84  
85      public void testNestedWithCommentsJDOM() {
86          doTest("nested-with-comments", DocumentContainer.MODEL_JDOM, "foo;bar; baz ");
87      }
88  }