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  
18  package org.apache.commons.jxpath.ri.model;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  
22  import org.apache.commons.jxpath.AbstractJXPathTest;
23  import org.apache.commons.jxpath.JXPathContext;
24  import org.apache.commons.jxpath.xml.DocumentContainer;
25  import org.junit.jupiter.api.Test;
26  
27  /**
28   * Test for uppercase element matching, etc. showing JXPATH-136 is not reproducible.
29   */
30  public class XMLUpperCaseElementsTest extends AbstractJXPathTest {
31  
32      protected JXPathContext context;
33  
34      protected JXPathContext createContext(final String model) {
35          final JXPathContext context = JXPathContext.newContext(createDocumentContainer(model));
36          return context;
37      }
38  
39      protected DocumentContainer createDocumentContainer(final String model) {
40          return new DocumentContainer(AbstractJXPathTest.class.getResource("VendorUpper.xml"), model);
41      }
42  
43      protected void doTest(final String id, final String model, final String expectedValue) {
44          final JXPathContext context = JXPathContext.newContext(createDocumentContainer(model));
45          assertEquals(expectedValue, context.getValue("test/text[@id='" + id + "']"));
46      }
47  
48      @Test
49      public void testBasicGetDOM() {
50          assertXPathValue(createContext(DocumentContainer.MODEL_DOM), "/Vendor[1]/Contact[1]", "John");
51      }
52  
53      @Test
54      public void testBasicGetJDOM() {
55          assertXPathValue(createContext(DocumentContainer.MODEL_JDOM), "/Vendor[1]/Contact[1]", "John");
56      }
57  
58      @Test
59      public void testBasicIterateDOM() {
60          assertXPathValueIterator(createContext(DocumentContainer.MODEL_DOM), "/Vendor/Contact", list("John", "Jack", "Jim", "Jack Black"));
61      }
62  
63      @Test
64      public void testBasicIterateJDOM() {
65          assertXPathValueIterator(createContext(DocumentContainer.MODEL_JDOM), "/Vendor/Contact", list("John", "Jack", "Jim", "Jack Black"));
66      }
67  }