|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -16,21 +16,19 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.util.xml; |
|
|
|
package org.springframework.util.xml; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.StringReader; |
|
|
|
|
|
|
|
import javax.xml.parsers.DocumentBuilder; |
|
|
|
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.w3c.dom.Document; |
|
|
|
import org.w3c.dom.Document; |
|
|
|
import org.w3c.dom.Element; |
|
|
|
import org.w3c.dom.Element; |
|
|
|
import org.xml.sax.InputSource; |
|
|
|
import org.xml.sax.InputSource; |
|
|
|
import org.xml.sax.XMLReader; |
|
|
|
import org.xml.sax.XMLReader; |
|
|
|
import org.xml.sax.helpers.XMLReaderFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.xml.parsers.DocumentBuilder; |
|
|
|
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory; |
|
|
|
|
|
|
|
import java.io.StringReader; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertThat; |
|
|
|
|
|
|
|
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.*; |
|
|
|
|
|
|
|
import static org.xmlunit.matchers.CompareMatcher.*; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unit tests for {@link DomContentHandler}. |
|
|
|
* Unit tests for {@link DomContentHandler}. |
|
|
|
@ -49,6 +47,7 @@ public class DomContentHandlerTests { |
|
|
|
private static final String XML_2_SNIPPET = |
|
|
|
private static final String XML_2_SNIPPET = |
|
|
|
"<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />"; |
|
|
|
"<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Document expected; |
|
|
|
private Document expected; |
|
|
|
|
|
|
|
|
|
|
|
private DomContentHandler handler; |
|
|
|
private DomContentHandler handler; |
|
|
|
@ -59,15 +58,18 @@ public class DomContentHandlerTests { |
|
|
|
|
|
|
|
|
|
|
|
private DocumentBuilder documentBuilder; |
|
|
|
private DocumentBuilder documentBuilder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
|
|
|
|
@SuppressWarnings("deprecation") // on JDK 9
|
|
|
|
public void setUp() throws Exception { |
|
|
|
public void setUp() throws Exception { |
|
|
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); |
|
|
|
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); |
|
|
|
documentBuilderFactory.setNamespaceAware(true); |
|
|
|
documentBuilderFactory.setNamespaceAware(true); |
|
|
|
documentBuilder = documentBuilderFactory.newDocumentBuilder(); |
|
|
|
documentBuilder = documentBuilderFactory.newDocumentBuilder(); |
|
|
|
result = documentBuilder.newDocument(); |
|
|
|
result = documentBuilder.newDocument(); |
|
|
|
xmlReader = XMLReaderFactory.createXMLReader(); |
|
|
|
xmlReader = org.xml.sax.helpers.XMLReaderFactory.createXMLReader(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void contentHandlerDocumentNamespacePrefixes() throws Exception { |
|
|
|
public void contentHandlerDocumentNamespacePrefixes() throws Exception { |
|
|
|
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); |
|
|
|
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); |
|
|
|
@ -96,7 +98,6 @@ public class DomContentHandlerTests { |
|
|
|
xmlReader.setContentHandler(handler); |
|
|
|
xmlReader.setContentHandler(handler); |
|
|
|
xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET))); |
|
|
|
xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET))); |
|
|
|
assertThat("Invalid result", result, isSimilarTo(expected)); |
|
|
|
assertThat("Invalid result", result, isSimilarTo(expected)); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|