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.issues;
19  
20  import static org.junit.jupiter.api.Assertions.assertNotNull;
21  import static org.junit.jupiter.api.Assertions.assertTrue;
22  
23  import java.io.StringReader;
24  import java.util.List;
25  
26  import javax.xml.parsers.DocumentBuilder;
27  import javax.xml.parsers.DocumentBuilderFactory;
28  import javax.xml.parsers.ParserConfigurationException;
29  
30  import org.apache.commons.jxpath.AbstractJXPathTest;
31  import org.apache.commons.jxpath.JXPathContext;
32  import org.junit.jupiter.api.Test;
33  import org.w3c.dom.Document;
34  import org.xml.sax.InputSource;
35  
36  public class JXPath113Test extends AbstractJXPathTest {
37  
38      static class JAXP {
39  
40          public static Document getDocument(final InputSource is) throws Exception {
41              final DocumentBuilder builder = getDocumentBuilder();
42              return builder.parse(is);
43          }
44  
45          public static Document getDocument(final String xml) throws Exception {
46              return getDocument(new InputSource(new StringReader(xml)));
47          }
48  
49          private static DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
50              final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
51              factory.setValidating(false);
52              factory.setNamespaceAware(true);
53              factory.setExpandEntityReferences(false);
54              return factory.newDocumentBuilder();
55          }
56      }
57  
58      @Test
59      public void testIssue113() throws Exception {
60          final Document doc = JAXP.getDocument("<xml/>");
61          final JXPathContext context = JXPathContext.newContext(doc);
62          final List result = context.selectNodes("//following-sibling::node()");
63          assertNotNull(result);
64          assertTrue(result.isEmpty());
65      }
66  }