Converted spaces to tabs
This commit changes leading spaces in all Java source files to tabs, to be consistent with other Spring projects.
This commit is contained in:
@@ -32,64 +32,64 @@ import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class DomContentHandlerTest {
|
||||
|
||||
private static final String XML_1 = "<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>" +
|
||||
"<root xmlns='namespace'>" +
|
||||
"<prefix:child xmlns:prefix='namespace2' xmlns:prefix2='namespace3' prefix2:attr='value'>content</prefix:child>" +
|
||||
"</root>";
|
||||
private static final String XML_1 = "<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>" +
|
||||
"<root xmlns='namespace'>" +
|
||||
"<prefix:child xmlns:prefix='namespace2' xmlns:prefix2='namespace3' prefix2:attr='value'>content</prefix:child>" +
|
||||
"</root>";
|
||||
|
||||
private static final String XML_2_EXPECTED = "<?xml version='1.0' encoding='UTF-8'?>" + "<root xmlns='namespace'>" +
|
||||
"<child xmlns='namespace2' />" + "</root>";
|
||||
private static final String XML_2_EXPECTED = "<?xml version='1.0' encoding='UTF-8'?>" + "<root xmlns='namespace'>" +
|
||||
"<child xmlns='namespace2' />" + "</root>";
|
||||
|
||||
private static final String XML_2_SNIPPET =
|
||||
"<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />";
|
||||
private static final String XML_2_SNIPPET =
|
||||
"<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace2' />";
|
||||
|
||||
private Document expected;
|
||||
private Document expected;
|
||||
|
||||
private DomContentHandler handler;
|
||||
private DomContentHandler handler;
|
||||
|
||||
private Document result;
|
||||
private Document result;
|
||||
|
||||
private XMLReader xmlReader;
|
||||
private XMLReader xmlReader;
|
||||
|
||||
private DocumentBuilder documentBuilder;
|
||||
private DocumentBuilder documentBuilder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
result = documentBuilder.newDocument();
|
||||
xmlReader = XMLReaderFactory.createXMLReader();
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
result = documentBuilder.newDocument();
|
||||
xmlReader = XMLReaderFactory.createXMLReader();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentHandlerDocumentNamespacePrefixes() throws Exception {
|
||||
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
|
||||
handler = new DomContentHandler(result);
|
||||
expected = documentBuilder.parse(new InputSource(new StringReader(XML_1)));
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_1)));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
}
|
||||
@Test
|
||||
public void testContentHandlerDocumentNamespacePrefixes() throws Exception {
|
||||
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
|
||||
handler = new DomContentHandler(result);
|
||||
expected = documentBuilder.parse(new InputSource(new StringReader(XML_1)));
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_1)));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentHandlerDocumentNoNamespacePrefixes() throws Exception {
|
||||
handler = new DomContentHandler(result);
|
||||
expected = documentBuilder.parse(new InputSource(new StringReader(XML_1)));
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_1)));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
}
|
||||
@Test
|
||||
public void testContentHandlerDocumentNoNamespacePrefixes() throws Exception {
|
||||
handler = new DomContentHandler(result);
|
||||
expected = documentBuilder.parse(new InputSource(new StringReader(XML_1)));
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_1)));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentHandlerElement() throws Exception {
|
||||
Element rootElement = result.createElementNS("namespace", "root");
|
||||
result.appendChild(rootElement);
|
||||
handler = new DomContentHandler(rootElement);
|
||||
expected = documentBuilder.parse(new InputSource(new StringReader(XML_2_EXPECTED)));
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET)));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
@Test
|
||||
public void testContentHandlerElement() throws Exception {
|
||||
Element rootElement = result.createElementNS("namespace", "root");
|
||||
result.appendChild(rootElement);
|
||||
handler = new DomContentHandler(rootElement);
|
||||
expected = documentBuilder.parse(new InputSource(new StringReader(XML_2_EXPECTED)));
|
||||
xmlReader.setContentHandler(handler);
|
||||
xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET)));
|
||||
assertXMLEqual("Invalid result", expected, result);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,41 +24,41 @@ import org.junit.Test;
|
||||
|
||||
public class QNameEditorTest {
|
||||
|
||||
private QNameEditor editor;
|
||||
private QNameEditor editor;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
editor = new QNameEditor();
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
editor = new QNameEditor();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamespaceLocalPartPrefix() throws Exception {
|
||||
QName qname = new QName("namespace", "localpart", "prefix");
|
||||
doTest(qname);
|
||||
}
|
||||
@Test
|
||||
public void testNamespaceLocalPartPrefix() throws Exception {
|
||||
QName qname = new QName("namespace", "localpart", "prefix");
|
||||
doTest(qname);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamespaceLocalPart() throws Exception {
|
||||
QName qname = new QName("namespace", "localpart");
|
||||
doTest(qname);
|
||||
}
|
||||
@Test
|
||||
public void testNamespaceLocalPart() throws Exception {
|
||||
QName qname = new QName("namespace", "localpart");
|
||||
doTest(qname);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalPart() throws Exception {
|
||||
QName qname = new QName("localpart");
|
||||
doTest(qname);
|
||||
}
|
||||
@Test
|
||||
public void testLocalPart() throws Exception {
|
||||
QName qname = new QName("localpart");
|
||||
doTest(qname);
|
||||
}
|
||||
|
||||
private void doTest(QName qname) {
|
||||
editor.setValue(qname);
|
||||
String text = editor.getAsText();
|
||||
Assert.assertNotNull("getAsText returns null", text);
|
||||
editor.setAsText(text);
|
||||
QName result = (QName) editor.getValue();
|
||||
Assert.assertNotNull("getValue returns null", result);
|
||||
Assert.assertEquals("Parsed QName local part is not equal to original", qname.getLocalPart(), result.getLocalPart());
|
||||
Assert.assertEquals("Parsed QName prefix is not equal to original", qname.getPrefix(), result.getPrefix());
|
||||
Assert.assertEquals("Parsed QName namespace is not equal to original", qname.getNamespaceURI(),
|
||||
result.getNamespaceURI());
|
||||
}
|
||||
private void doTest(QName qname) {
|
||||
editor.setValue(qname);
|
||||
String text = editor.getAsText();
|
||||
Assert.assertNotNull("getAsText returns null", text);
|
||||
editor.setAsText(text);
|
||||
QName result = (QName) editor.getValue();
|
||||
Assert.assertNotNull("getValue returns null", result);
|
||||
Assert.assertEquals("Parsed QName local part is not equal to original", qname.getLocalPart(), result.getLocalPart());
|
||||
Assert.assertEquals("Parsed QName prefix is not equal to original", qname.getPrefix(), result.getPrefix());
|
||||
Assert.assertEquals("Parsed QName namespace is not equal to original", qname.getNamespaceURI(),
|
||||
result.getNamespaceURI());
|
||||
}
|
||||
}
|
||||
@@ -29,89 +29,89 @@ import org.w3c.dom.Element;
|
||||
|
||||
public class QNameUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testValidQNames() {
|
||||
Assert.assertTrue("Namespace QName not validated", QNameUtils.validateQName("{namespace}local"));
|
||||
Assert.assertTrue("No Namespace QName not validated", QNameUtils.validateQName("local"));
|
||||
}
|
||||
@Test
|
||||
public void testValidQNames() {
|
||||
Assert.assertTrue("Namespace QName not validated", QNameUtils.validateQName("{namespace}local"));
|
||||
Assert.assertTrue("No Namespace QName not validated", QNameUtils.validateQName("local"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidQNames() {
|
||||
Assert.assertFalse("Null QName validated", QNameUtils.validateQName(null));
|
||||
Assert.assertFalse("Empty QName validated", QNameUtils.validateQName(""));
|
||||
Assert.assertFalse("Invalid QName validated", QNameUtils.validateQName("{namespace}"));
|
||||
Assert.assertFalse("Invalid QName validated", QNameUtils.validateQName("{namespace"));
|
||||
}
|
||||
@Test
|
||||
public void testInvalidQNames() {
|
||||
Assert.assertFalse("Null QName validated", QNameUtils.validateQName(null));
|
||||
Assert.assertFalse("Empty QName validated", QNameUtils.validateQName(""));
|
||||
Assert.assertFalse("Invalid QName validated", QNameUtils.validateQName("{namespace}"));
|
||||
Assert.assertFalse("Invalid QName validated", QNameUtils.validateQName("{namespace"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQNameForNodeNoNamespace() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElement("localname");
|
||||
QName qName = QNameUtils.getQNameForNode(element);
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertFalse("Qname has invalid namespace", StringUtils.hasLength(qName.getNamespaceURI()));
|
||||
Assert.assertFalse("Qname has invalid prefix", StringUtils.hasLength(qName.getPrefix()));
|
||||
@Test
|
||||
public void testGetQNameForNodeNoNamespace() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElement("localname");
|
||||
QName qName = QNameUtils.getQNameForNode(element);
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertFalse("Qname has invalid namespace", StringUtils.hasLength(qName.getNamespaceURI()));
|
||||
Assert.assertFalse("Qname has invalid prefix", StringUtils.hasLength(qName.getPrefix()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQNameForNodeNoPrefix() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElementNS("namespace", "localname");
|
||||
QName qName = QNameUtils.getQNameForNode(element);
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
Assert.assertFalse("Qname has invalid prefix", StringUtils.hasLength(qName.getPrefix()));
|
||||
}
|
||||
@Test
|
||||
public void testGetQNameForNodeNoPrefix() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElementNS("namespace", "localname");
|
||||
QName qName = QNameUtils.getQNameForNode(element);
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
Assert.assertFalse("Qname has invalid prefix", StringUtils.hasLength(qName.getPrefix()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQNameForNode() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElementNS("namespace", "prefix:localname");
|
||||
QName qName = QNameUtils.getQNameForNode(element);
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
}
|
||||
@Test
|
||||
public void testGetQNameForNode() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.newDocument();
|
||||
Element element = document.createElementNS("namespace", "prefix:localname");
|
||||
QName qName = QNameUtils.getQNameForNode(element);
|
||||
Assert.assertNotNull("getQNameForNode returns null", qName);
|
||||
Assert.assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
|
||||
Assert.assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
|
||||
Assert.assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToQualifiedNamePrefix() throws Exception {
|
||||
QName qName = new QName("namespace", "localName", "prefix");
|
||||
String result = QNameUtils.toQualifiedName(qName);
|
||||
Assert.assertEquals("Invalid result", "prefix:localName", result);
|
||||
}
|
||||
@Test
|
||||
public void testToQualifiedNamePrefix() throws Exception {
|
||||
QName qName = new QName("namespace", "localName", "prefix");
|
||||
String result = QNameUtils.toQualifiedName(qName);
|
||||
Assert.assertEquals("Invalid result", "prefix:localName", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToQualifiedNameNoPrefix() throws Exception {
|
||||
QName qName = new QName("localName");
|
||||
String result = QNameUtils.toQualifiedName(qName);
|
||||
Assert.assertEquals("Invalid result", "localName", result);
|
||||
}
|
||||
@Test
|
||||
public void testToQualifiedNameNoPrefix() throws Exception {
|
||||
QName qName = new QName("localName");
|
||||
String result = QNameUtils.toQualifiedName(qName);
|
||||
Assert.assertEquals("Invalid result", "localName", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToQNamePrefix() throws Exception {
|
||||
QName result = QNameUtils.toQName("namespace", "prefix:localName");
|
||||
Assert.assertEquals("invalid namespace", "namespace", result.getNamespaceURI());
|
||||
Assert.assertEquals("invalid prefix", "prefix", result.getPrefix());
|
||||
Assert.assertEquals("invalid localname", "localName", result.getLocalPart());
|
||||
}
|
||||
@Test
|
||||
public void testToQNamePrefix() throws Exception {
|
||||
QName result = QNameUtils.toQName("namespace", "prefix:localName");
|
||||
Assert.assertEquals("invalid namespace", "namespace", result.getNamespaceURI());
|
||||
Assert.assertEquals("invalid prefix", "prefix", result.getPrefix());
|
||||
Assert.assertEquals("invalid localname", "localName", result.getLocalPart());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToQNameNoPrefix() throws Exception {
|
||||
QName result = QNameUtils.toQName("namespace", "localName");
|
||||
Assert.assertEquals("invalid namespace", "namespace", result.getNamespaceURI());
|
||||
Assert.assertEquals("invalid prefix", "", result.getPrefix());
|
||||
Assert.assertEquals("invalid localname", "localName", result.getLocalPart());
|
||||
}
|
||||
@Test
|
||||
public void testToQNameNoPrefix() throws Exception {
|
||||
QName result = QNameUtils.toQName("namespace", "localName");
|
||||
Assert.assertEquals("invalid namespace", "namespace", result.getNamespaceURI());
|
||||
Assert.assertEquals("invalid prefix", "", result.getPrefix());
|
||||
Assert.assertEquals("invalid localname", "localName", result.getLocalPart());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,157 +26,157 @@ import org.junit.Test;
|
||||
|
||||
public class SimpleNamespaceContextTest {
|
||||
|
||||
private SimpleNamespaceContext context;
|
||||
private SimpleNamespaceContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
context = new SimpleNamespaceContext();
|
||||
context.bindNamespaceUri("prefix", "namespaceURI");
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
context = new SimpleNamespaceContext();
|
||||
context.bindNamespaceUri("prefix", "namespaceURI");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNamespaceURI() {
|
||||
Assert.assertEquals("Invalid namespaceURI for default namespace", "", context
|
||||
.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
|
||||
String defaultNamespaceUri = "defaultNamespace";
|
||||
context.bindNamespaceUri(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespaceUri);
|
||||
Assert.assertEquals("Invalid namespaceURI for default namespace", defaultNamespaceUri, context
|
||||
.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
|
||||
Assert.assertEquals("Invalid namespaceURI for bound prefix", "namespaceURI", context.getNamespaceURI("prefix"));
|
||||
Assert.assertEquals("Invalid namespaceURI for unbound prefix", "", context.getNamespaceURI("unbound"));
|
||||
Assert.assertEquals("Invalid namespaceURI for namespace prefix", XMLConstants.XML_NS_URI, context
|
||||
.getNamespaceURI(XMLConstants.XML_NS_PREFIX));
|
||||
Assert.assertEquals("Invalid namespaceURI for attribute prefix", XMLConstants.XMLNS_ATTRIBUTE_NS_URI, context
|
||||
.getNamespaceURI(XMLConstants.XMLNS_ATTRIBUTE));
|
||||
@Test
|
||||
public void testGetNamespaceURI() {
|
||||
Assert.assertEquals("Invalid namespaceURI for default namespace", "", context
|
||||
.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
|
||||
String defaultNamespaceUri = "defaultNamespace";
|
||||
context.bindNamespaceUri(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespaceUri);
|
||||
Assert.assertEquals("Invalid namespaceURI for default namespace", defaultNamespaceUri, context
|
||||
.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
|
||||
Assert.assertEquals("Invalid namespaceURI for bound prefix", "namespaceURI", context.getNamespaceURI("prefix"));
|
||||
Assert.assertEquals("Invalid namespaceURI for unbound prefix", "", context.getNamespaceURI("unbound"));
|
||||
Assert.assertEquals("Invalid namespaceURI for namespace prefix", XMLConstants.XML_NS_URI, context
|
||||
.getNamespaceURI(XMLConstants.XML_NS_PREFIX));
|
||||
Assert.assertEquals("Invalid namespaceURI for attribute prefix", XMLConstants.XMLNS_ATTRIBUTE_NS_URI, context
|
||||
.getNamespaceURI(XMLConstants.XMLNS_ATTRIBUTE));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPrefix() {
|
||||
context.bindDefaultNamespaceUri("defaultNamespaceURI");
|
||||
Assert.assertEquals("Invalid prefix for default namespace", XMLConstants.DEFAULT_NS_PREFIX, context.getPrefix("defaultNamespaceURI"));
|
||||
Assert.assertEquals("Invalid prefix for bound namespace", "prefix", context.getPrefix("namespaceURI"));
|
||||
Assert.assertNull("Invalid prefix for unbound namespace", context.getPrefix("unbound"));
|
||||
Assert.assertEquals("Invalid prefix for namespace", XMLConstants.XML_NS_PREFIX, context
|
||||
.getPrefix(XMLConstants.XML_NS_URI));
|
||||
Assert.assertEquals("Invalid prefix for attribute namespace", XMLConstants.XMLNS_ATTRIBUTE, context
|
||||
.getPrefix(XMLConstants.XMLNS_ATTRIBUTE_NS_URI));
|
||||
}
|
||||
@Test
|
||||
public void testGetPrefix() {
|
||||
context.bindDefaultNamespaceUri("defaultNamespaceURI");
|
||||
Assert.assertEquals("Invalid prefix for default namespace", XMLConstants.DEFAULT_NS_PREFIX, context.getPrefix("defaultNamespaceURI"));
|
||||
Assert.assertEquals("Invalid prefix for bound namespace", "prefix", context.getPrefix("namespaceURI"));
|
||||
Assert.assertNull("Invalid prefix for unbound namespace", context.getPrefix("unbound"));
|
||||
Assert.assertEquals("Invalid prefix for namespace", XMLConstants.XML_NS_PREFIX, context
|
||||
.getPrefix(XMLConstants.XML_NS_URI));
|
||||
Assert.assertEquals("Invalid prefix for attribute namespace", XMLConstants.XMLNS_ATTRIBUTE, context
|
||||
.getPrefix(XMLConstants.XMLNS_ATTRIBUTE_NS_URI));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPrefixes() {
|
||||
context.bindDefaultNamespaceUri("defaultNamespaceURI");
|
||||
assertPrefixes("defaultNamespaceURI", XMLConstants.DEFAULT_NS_PREFIX);
|
||||
assertPrefixes("namespaceURI", "prefix");
|
||||
Assert.assertFalse("Invalid prefix for unbound namespace", context.getPrefixes("unbound").hasNext());
|
||||
assertPrefixes(XMLConstants.XML_NS_URI, XMLConstants.XML_NS_PREFIX);
|
||||
assertPrefixes(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE);
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void unmodifiableGetPrefixes() {
|
||||
String namespaceUri = "namespaceUri";
|
||||
context.bindNamespaceUri("prefix1", namespaceUri);
|
||||
context.bindNamespaceUri("prefix2", namespaceUri);
|
||||
@Test
|
||||
public void testGetPrefixes() {
|
||||
context.bindDefaultNamespaceUri("defaultNamespaceURI");
|
||||
assertPrefixes("defaultNamespaceURI", XMLConstants.DEFAULT_NS_PREFIX);
|
||||
assertPrefixes("namespaceURI", "prefix");
|
||||
Assert.assertFalse("Invalid prefix for unbound namespace", context.getPrefixes("unbound").hasNext());
|
||||
assertPrefixes(XMLConstants.XML_NS_URI, XMLConstants.XML_NS_PREFIX);
|
||||
assertPrefixes(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE);
|
||||
}
|
||||
|
||||
Iterator<String> prefixes = context.getPrefixes(namespaceUri);
|
||||
prefixes.next();
|
||||
prefixes.remove();
|
||||
}
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void unmodifiableGetPrefixes() {
|
||||
String namespaceUri = "namespaceUri";
|
||||
context.bindNamespaceUri("prefix1", namespaceUri);
|
||||
context.bindNamespaceUri("prefix2", namespaceUri);
|
||||
|
||||
@Test
|
||||
public void testMultiplePrefixes() {
|
||||
context.bindNamespaceUri("prefix1", "namespace");
|
||||
context.bindNamespaceUri("prefix2", "namespace");
|
||||
Iterator<String> iterator = context.getPrefixes("namespace");
|
||||
Assert.assertNotNull("getPrefixes returns null", iterator);
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
String result = iterator.next();
|
||||
Assert.assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
result = iterator.next();
|
||||
Assert.assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
|
||||
Assert.assertFalse("iterator contains more than two values", iterator.hasNext());
|
||||
}
|
||||
Iterator<String> prefixes = context.getPrefixes(namespaceUri);
|
||||
prefixes.next();
|
||||
prefixes.remove();
|
||||
}
|
||||
|
||||
private void assertPrefixes(String namespaceUri, String prefix) {
|
||||
Iterator<String> iterator = context.getPrefixes(namespaceUri);
|
||||
Assert.assertNotNull("getPrefixes returns null", iterator);
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
String result = iterator.next();
|
||||
Assert.assertEquals("Invalid prefix", prefix, result);
|
||||
Assert.assertFalse("iterator contains multiple values", iterator.hasNext());
|
||||
}
|
||||
@Test
|
||||
public void testMultiplePrefixes() {
|
||||
context.bindNamespaceUri("prefix1", "namespace");
|
||||
context.bindNamespaceUri("prefix2", "namespace");
|
||||
Iterator<String> iterator = context.getPrefixes("namespace");
|
||||
Assert.assertNotNull("getPrefixes returns null", iterator);
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
String result = iterator.next();
|
||||
Assert.assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
result = iterator.next();
|
||||
Assert.assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
|
||||
Assert.assertFalse("iterator contains more than two values", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBoundPrefixes() throws Exception {
|
||||
Iterator<String> iterator = context.getBoundPrefixes();
|
||||
Assert.assertNotNull("getPrefixes returns null", iterator);
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
String result = iterator.next();
|
||||
Assert.assertEquals("Invalid prefix", "prefix", result);
|
||||
Assert.assertFalse("iterator contains multiple values", iterator.hasNext());
|
||||
}
|
||||
private void assertPrefixes(String namespaceUri, String prefix) {
|
||||
Iterator<String> iterator = context.getPrefixes(namespaceUri);
|
||||
Assert.assertNotNull("getPrefixes returns null", iterator);
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
String result = iterator.next();
|
||||
Assert.assertEquals("Invalid prefix", prefix, result);
|
||||
Assert.assertFalse("iterator contains multiple values", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetBindings() throws Exception {
|
||||
context.setBindings(Collections.singletonMap("prefix", "namespace"));
|
||||
Assert.assertEquals("Invalid namespace uri", "namespace", context.getNamespaceURI("prefix"));
|
||||
}
|
||||
@Test
|
||||
public void testGetBoundPrefixes() throws Exception {
|
||||
Iterator<String> iterator = context.getBoundPrefixes();
|
||||
Assert.assertNotNull("getPrefixes returns null", iterator);
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
String result = iterator.next();
|
||||
Assert.assertEquals("Invalid prefix", "prefix", result);
|
||||
Assert.assertFalse("iterator contains multiple values", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveBinding() {
|
||||
context.clear();
|
||||
String prefix1 = "prefix1";
|
||||
String prefix2 = "prefix2";
|
||||
String namespaceUri = "namespaceUri";
|
||||
context.bindNamespaceUri(prefix1, namespaceUri);
|
||||
context.bindNamespaceUri(prefix2, namespaceUri);
|
||||
Iterator<String> iter = context.getPrefixes(namespaceUri);
|
||||
Assert.assertTrue("iterator is empty", iter.hasNext());
|
||||
Assert.assertEquals(prefix1, iter.next());
|
||||
Assert.assertTrue("iterator is empty", iter.hasNext());
|
||||
Assert.assertEquals(prefix2, iter.next());
|
||||
Assert.assertFalse("iterator not empty", iter.hasNext());
|
||||
@Test
|
||||
public void testSetBindings() throws Exception {
|
||||
context.setBindings(Collections.singletonMap("prefix", "namespace"));
|
||||
Assert.assertEquals("Invalid namespace uri", "namespace", context.getNamespaceURI("prefix"));
|
||||
}
|
||||
|
||||
context.removeBinding(prefix1);
|
||||
@Test
|
||||
public void testRemoveBinding() {
|
||||
context.clear();
|
||||
String prefix1 = "prefix1";
|
||||
String prefix2 = "prefix2";
|
||||
String namespaceUri = "namespaceUri";
|
||||
context.bindNamespaceUri(prefix1, namespaceUri);
|
||||
context.bindNamespaceUri(prefix2, namespaceUri);
|
||||
Iterator<String> iter = context.getPrefixes(namespaceUri);
|
||||
Assert.assertTrue("iterator is empty", iter.hasNext());
|
||||
Assert.assertEquals(prefix1, iter.next());
|
||||
Assert.assertTrue("iterator is empty", iter.hasNext());
|
||||
Assert.assertEquals(prefix2, iter.next());
|
||||
Assert.assertFalse("iterator not empty", iter.hasNext());
|
||||
|
||||
iter = context.getPrefixes(namespaceUri);
|
||||
Assert.assertTrue("iterator is empty", iter.hasNext());
|
||||
Assert.assertEquals(prefix2, iter.next());
|
||||
Assert.assertFalse("iterator not empty", iter.hasNext());
|
||||
context.removeBinding(prefix1);
|
||||
|
||||
context.removeBinding(prefix2);
|
||||
iter = context.getPrefixes(namespaceUri);
|
||||
Assert.assertTrue("iterator is empty", iter.hasNext());
|
||||
Assert.assertEquals(prefix2, iter.next());
|
||||
Assert.assertFalse("iterator not empty", iter.hasNext());
|
||||
|
||||
iter = context.getPrefixes(namespaceUri);
|
||||
Assert.assertFalse("iterator not empty", iter.hasNext());
|
||||
}
|
||||
context.removeBinding(prefix2);
|
||||
|
||||
@Test
|
||||
public void testHasBinding() {
|
||||
context.clear();
|
||||
String prefix = "prefix";
|
||||
Assert.assertFalse("Context has binding", context.hasBinding(prefix));
|
||||
String namespaceUri = "namespaceUri";
|
||||
context.bindNamespaceUri(prefix, namespaceUri);
|
||||
Assert.assertTrue("Context has no binding", context.hasBinding(prefix));
|
||||
}
|
||||
iter = context.getPrefixes(namespaceUri);
|
||||
Assert.assertFalse("iterator not empty", iter.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultNamespaceMultiplePrefixes() {
|
||||
String defaultNamespace = "http://springframework.org/spring-ws";
|
||||
context.bindDefaultNamespaceUri(defaultNamespace);
|
||||
context.bindNamespaceUri("prefix", defaultNamespace);
|
||||
Assert.assertEquals("Invalid prefix", XMLConstants.DEFAULT_NS_PREFIX, context.getPrefix(defaultNamespace));
|
||||
Iterator<String> iterator = context.getPrefixes(defaultNamespace);
|
||||
Assert.assertNotNull("getPrefixes returns null", iterator);
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
String result = iterator.next();
|
||||
Assert.assertTrue("Invalid prefix", result.equals(XMLConstants.DEFAULT_NS_PREFIX) || result.equals("prefix"));
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
result = iterator.next();
|
||||
Assert.assertTrue("Invalid prefix", result.equals(XMLConstants.DEFAULT_NS_PREFIX) || result.equals("prefix"));
|
||||
Assert.assertFalse("iterator contains more than two values", iterator.hasNext());
|
||||
}
|
||||
@Test
|
||||
public void testHasBinding() {
|
||||
context.clear();
|
||||
String prefix = "prefix";
|
||||
Assert.assertFalse("Context has binding", context.hasBinding(prefix));
|
||||
String namespaceUri = "namespaceUri";
|
||||
context.bindNamespaceUri(prefix, namespaceUri);
|
||||
Assert.assertTrue("Context has no binding", context.hasBinding(prefix));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultNamespaceMultiplePrefixes() {
|
||||
String defaultNamespace = "http://springframework.org/spring-ws";
|
||||
context.bindDefaultNamespaceUri(defaultNamespace);
|
||||
context.bindNamespaceUri("prefix", defaultNamespace);
|
||||
Assert.assertEquals("Invalid prefix", XMLConstants.DEFAULT_NS_PREFIX, context.getPrefix(defaultNamespace));
|
||||
Iterator<String> iterator = context.getPrefixes(defaultNamespace);
|
||||
Assert.assertNotNull("getPrefixes returns null", iterator);
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
String result = iterator.next();
|
||||
Assert.assertTrue("Invalid prefix", result.equals(XMLConstants.DEFAULT_NS_PREFIX) || result.equals("prefix"));
|
||||
Assert.assertTrue("iterator is empty", iterator.hasNext());
|
||||
result = iterator.next();
|
||||
Assert.assertTrue("Invalid prefix", result.equals(XMLConstants.DEFAULT_NS_PREFIX) || result.equals("prefix"));
|
||||
Assert.assertFalse("iterator contains more than two values", iterator.hasNext());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ import org.junit.Test;
|
||||
|
||||
public class SaxUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetSystemId() throws Exception {
|
||||
Resource resource = new FileSystemResource("/path with spaces/file with spaces.txt");
|
||||
String systemId = SaxUtils.getSystemId(resource);
|
||||
Assert.assertNotNull("No systemId returned", systemId);
|
||||
Assert.assertTrue("Invalid system id", systemId.endsWith("path%20with%20spaces/file%20with%20spaces.txt"));
|
||||
}
|
||||
@Test
|
||||
public void testGetSystemId() throws Exception {
|
||||
Resource resource = new FileSystemResource("/path with spaces/file with spaces.txt");
|
||||
String systemId = SaxUtils.getSystemId(resource);
|
||||
Assert.assertNotNull("No systemId returned", systemId);
|
||||
Assert.assertTrue("Invalid system id", systemId.endsWith("path%20with%20spaces/file%20with%20spaces.txt"));
|
||||
}
|
||||
}
|
||||
@@ -28,16 +28,16 @@ import org.w3c.dom.Element;
|
||||
|
||||
public class ResourceSourceTest {
|
||||
|
||||
@Test
|
||||
public void testStringSource() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
DOMResult result = new DOMResult();
|
||||
ResourceSource source = new ResourceSource(new ClassPathResource("resourceSource.xml", getClass()));
|
||||
transformer.transform(source, result);
|
||||
Element rootElement = (Element) result.getNode().getFirstChild();
|
||||
Assert.assertEquals("Invalid local name", "content", rootElement.getLocalName());
|
||||
Assert.assertEquals("Invalid prefix", "prefix", rootElement.getPrefix());
|
||||
Assert.assertEquals("Invalid namespace", "namespace", rootElement.getNamespaceURI());
|
||||
}
|
||||
@Test
|
||||
public void testStringSource() throws Exception {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
DOMResult result = new DOMResult();
|
||||
ResourceSource source = new ResourceSource(new ClassPathResource("resourceSource.xml", getClass()));
|
||||
transformer.transform(source, result);
|
||||
Element rootElement = (Element) result.getNode().getFirstChild();
|
||||
Assert.assertEquals("Invalid local name", "content", rootElement.getLocalName());
|
||||
Assert.assertEquals("Invalid prefix", "prefix", rootElement.getPrefix());
|
||||
Assert.assertEquals("Invalid namespace", "namespace", rootElement.getNamespaceURI());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,15 +29,15 @@ import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class StringResultTest {
|
||||
|
||||
@Test
|
||||
public void testStringResult() throws Exception {
|
||||
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
|
||||
Element element = document.createElementNS("namespace", "prefix:localName");
|
||||
document.appendChild(element);
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(new DOMSource(document), result);
|
||||
assertXMLEqual("Invalid result", "<prefix:localName xmlns:prefix='namespace'/>", result.toString());
|
||||
}
|
||||
@Test
|
||||
public void testStringResult() throws Exception {
|
||||
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
|
||||
Element element = document.createElementNS("namespace", "prefix:localName");
|
||||
document.appendChild(element);
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(new DOMSource(document), result);
|
||||
assertXMLEqual("Invalid result", "<prefix:localName xmlns:prefix='namespace'/>", result.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,15 +27,15 @@ import org.w3c.dom.Element;
|
||||
|
||||
public class StringSourceTest {
|
||||
|
||||
@Test
|
||||
public void testStringSource() throws TransformerException {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
String content = "<prefix:content xmlns:prefix='namespace'/>";
|
||||
DOMResult result = new DOMResult();
|
||||
transformer.transform(new StringSource(content), result);
|
||||
Element rootElement = (Element) result.getNode().getFirstChild();
|
||||
Assert.assertEquals("Invalid local name", "content", rootElement.getLocalName());
|
||||
Assert.assertEquals("Invalid prefix", "prefix", rootElement.getPrefix());
|
||||
Assert.assertEquals("Invalid namespace", "namespace", rootElement.getNamespaceURI());
|
||||
}
|
||||
@Test
|
||||
public void testStringSource() throws TransformerException {
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
String content = "<prefix:content xmlns:prefix='namespace'/>";
|
||||
DOMResult result = new DOMResult();
|
||||
transformer.transform(new StringSource(content), result);
|
||||
Element rootElement = (Element) result.getNode().getFirstChild();
|
||||
Assert.assertEquals("Invalid local name", "content", rootElement.getLocalName());
|
||||
Assert.assertEquals("Invalid prefix", "prefix", rootElement.getPrefix());
|
||||
Assert.assertEquals("Invalid namespace", "namespace", rootElement.getNamespaceURI());
|
||||
}
|
||||
}
|
||||
@@ -30,31 +30,31 @@ import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class TransformerHelperTest {
|
||||
|
||||
private TransformerHelper helper;
|
||||
private TransformerHelper helper;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
helper = new TransformerHelper();
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
helper = new TransformerHelper();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultTransformerFactory() throws TransformerException, IOException, SAXException {
|
||||
doTest();
|
||||
}
|
||||
@Test
|
||||
public void defaultTransformerFactory() throws TransformerException, IOException, SAXException {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customTransformerFactory() throws TransformerException, IOException, SAXException {
|
||||
helper.setTransformerFactoryClass(TransformerFactoryImpl.class);
|
||||
doTest();
|
||||
}
|
||||
@Test
|
||||
public void customTransformerFactory() throws TransformerException, IOException, SAXException {
|
||||
helper.setTransformerFactoryClass(TransformerFactoryImpl.class);
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() throws TransformerException, SAXException, IOException {
|
||||
String xml = "<root xmlns='http://springframework.org/spring-ws'><child>text</child></root>";
|
||||
Source source = new StringSource(xml);
|
||||
Result result = new StringResult();
|
||||
private void doTest() throws TransformerException, SAXException, IOException {
|
||||
String xml = "<root xmlns='http://springframework.org/spring-ws'><child>text</child></root>";
|
||||
Source source = new StringSource(xml);
|
||||
Result result = new StringResult();
|
||||
|
||||
helper.transform(source, result);
|
||||
helper.transform(source, result);
|
||||
|
||||
assertXMLEqual(xml, result.toString());
|
||||
}
|
||||
assertXMLEqual(xml, result.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,268 +59,268 @@ import static org.easymock.EasyMock.*;
|
||||
|
||||
public class TraxUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testGetDocument() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
Assert.assertSame("Invalid document", document, TraxUtils.getDocument(new DOMSource(document)));
|
||||
Element element = document.createElement("element");
|
||||
document.appendChild(element);
|
||||
Assert.assertSame("Invalid document", document, TraxUtils.getDocument(new DOMSource(element)));
|
||||
}
|
||||
@Test
|
||||
public void testGetDocument() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
Assert.assertSame("Invalid document", document, TraxUtils.getDocument(new DOMSource(document)));
|
||||
Element element = document.createElement("element");
|
||||
document.appendChild(element);
|
||||
Assert.assertSame("Invalid document", document, TraxUtils.getDocument(new DOMSource(element)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithDomSource() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
@Test
|
||||
public void testDoWithDomSource() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.domSource(document);
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.domSource(document);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithSource(new DOMSource(document), mock);
|
||||
TraxUtils.doWithSource(new DOMSource(document), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithDomResult() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
@Test
|
||||
public void testDoWithDomResult() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.newDocument();
|
||||
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.domResult(document);
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.domResult(document);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithResult(new DOMResult(document), mock);
|
||||
TraxUtils.doWithResult(new DOMResult(document), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithSaxSource() throws Exception {
|
||||
XMLReader reader = XMLReaderFactory.createXMLReader();
|
||||
InputSource inputSource = new InputSource();
|
||||
@Test
|
||||
public void testDoWithSaxSource() throws Exception {
|
||||
XMLReader reader = XMLReaderFactory.createXMLReader();
|
||||
InputSource inputSource = new InputSource();
|
||||
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.saxSource(reader, inputSource);
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.saxSource(reader, inputSource);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithSource(new SAXSource(reader, inputSource), mock);
|
||||
TraxUtils.doWithSource(new SAXSource(reader, inputSource), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithSaxResult() throws Exception {
|
||||
ContentHandler contentHandler = new DefaultHandler();
|
||||
LexicalHandler lexicalHandler = new DefaultHandler2();
|
||||
@Test
|
||||
public void testDoWithSaxResult() throws Exception {
|
||||
ContentHandler contentHandler = new DefaultHandler();
|
||||
LexicalHandler lexicalHandler = new DefaultHandler2();
|
||||
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.saxResult(contentHandler, lexicalHandler);
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.saxResult(contentHandler, lexicalHandler);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
SAXResult result = new SAXResult(contentHandler);
|
||||
result.setLexicalHandler(lexicalHandler);
|
||||
TraxUtils.doWithResult(result, mock);
|
||||
SAXResult result = new SAXResult(contentHandler);
|
||||
result.setLexicalHandler(lexicalHandler);
|
||||
TraxUtils.doWithResult(result, mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithStaxSourceEventReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader("<element/>"));
|
||||
@Test
|
||||
public void testDoWithStaxSourceEventReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader("<element/>"));
|
||||
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.staxSource(eventReader);
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.staxSource(eventReader);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithSource(StaxUtils.createStaxSource(eventReader), mock);
|
||||
TraxUtils.doWithSource(StaxUtils.createStaxSource(eventReader), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithStaxResultEventWriter() throws Exception {
|
||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new StringWriter());
|
||||
@Test
|
||||
public void testDoWithStaxResultEventWriter() throws Exception {
|
||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new StringWriter());
|
||||
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.staxResult(eventWriter);
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.staxResult(eventWriter);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithResult(StaxUtils.createStaxResult(eventWriter), mock);
|
||||
TraxUtils.doWithResult(StaxUtils.createStaxResult(eventWriter), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithStaxSourceStreamReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader("<element/>"));
|
||||
@Test
|
||||
public void testDoWithStaxSourceStreamReader() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader("<element/>"));
|
||||
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.staxSource(streamReader);
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.staxSource(streamReader);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithSource(StaxUtils.createStaxSource(streamReader), mock);
|
||||
TraxUtils.doWithSource(StaxUtils.createStaxSource(streamReader), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithStaxResultStreamWriter() throws Exception {
|
||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
|
||||
@Test
|
||||
public void testDoWithStaxResultStreamWriter() throws Exception {
|
||||
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
|
||||
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
|
||||
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.staxResult(streamWriter);
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.staxResult(streamWriter);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithResult(StaxUtils.createStaxResult(streamWriter), mock);
|
||||
TraxUtils.doWithResult(StaxUtils.createStaxResult(streamWriter), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithStreamSourceInputStream() throws Exception {
|
||||
byte[] xml = "<element/>".getBytes("UTF-8");
|
||||
InputStream inputStream = new ByteArrayInputStream(xml);
|
||||
@Test
|
||||
public void testDoWithStreamSourceInputStream() throws Exception {
|
||||
byte[] xml = "<element/>".getBytes("UTF-8");
|
||||
InputStream inputStream = new ByteArrayInputStream(xml);
|
||||
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.streamSource(inputStream);
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.streamSource(inputStream);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithSource(new StreamSource(inputStream), mock);
|
||||
TraxUtils.doWithSource(new StreamSource(inputStream), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithStreamResultOutputStream() throws Exception {
|
||||
OutputStream outputStream = new ByteArrayOutputStream();
|
||||
@Test
|
||||
public void testDoWithStreamResultOutputStream() throws Exception {
|
||||
OutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.streamResult(outputStream);
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.streamResult(outputStream);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithResult(new StreamResult(outputStream), mock);
|
||||
TraxUtils.doWithResult(new StreamResult(outputStream), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithStreamSourceReader() throws Exception {
|
||||
String xml = "<element/>";
|
||||
Reader reader = new StringReader(xml);
|
||||
@Test
|
||||
public void testDoWithStreamSourceReader() throws Exception {
|
||||
String xml = "<element/>";
|
||||
Reader reader = new StringReader(xml);
|
||||
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.streamSource(reader);
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.streamSource(reader);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithSource(new StreamSource(reader), mock);
|
||||
TraxUtils.doWithSource(new StreamSource(reader), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithStreamResultWriter() throws Exception {
|
||||
Writer writer = new StringWriter();
|
||||
@Test
|
||||
public void testDoWithStreamResultWriter() throws Exception {
|
||||
Writer writer = new StringWriter();
|
||||
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.streamResult(writer);
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.streamResult(writer);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithResult(new StreamResult(writer), mock);
|
||||
TraxUtils.doWithResult(new StreamResult(writer), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithSystemIdSource() throws Exception {
|
||||
String systemId = "http://www.springframework.org/dtd/spring-beans.dtd";
|
||||
@Test
|
||||
public void testDoWithSystemIdSource() throws Exception {
|
||||
String systemId = "http://www.springframework.org/dtd/spring-beans.dtd";
|
||||
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.source(systemId);
|
||||
TraxUtils.SourceCallback mock = createMock(TraxUtils.SourceCallback.class);
|
||||
mock.source(systemId);
|
||||
|
||||
replay(mock);
|
||||
replay(mock);
|
||||
|
||||
TraxUtils.doWithSource(new StreamSource(systemId), mock);
|
||||
TraxUtils.doWithSource(new StreamSource(systemId), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithSystemIdResult() throws Exception {
|
||||
String systemId = "http://www.springframework.org/dtd/spring-beans.dtd";
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.result(systemId);
|
||||
@Test
|
||||
public void testDoWithSystemIdResult() throws Exception {
|
||||
String systemId = "http://www.springframework.org/dtd/spring-beans.dtd";
|
||||
|
||||
replay(mock);
|
||||
TraxUtils.ResultCallback mock = createMock(TraxUtils.ResultCallback.class);
|
||||
mock.result(systemId);
|
||||
|
||||
TraxUtils.doWithResult(new StreamResult(systemId), mock);
|
||||
replay(mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
TraxUtils.doWithResult(new StreamResult(systemId), mock);
|
||||
|
||||
verify(mock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWithInvalidSource() throws Exception {
|
||||
Source source = new Source() {
|
||||
|
||||
public void setSystemId(String systemId) {
|
||||
}
|
||||
@Test
|
||||
public void testDoWithInvalidSource() throws Exception {
|
||||
Source source = new Source() {
|
||||
|
||||
public String getSystemId() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
public void setSystemId(String systemId) {
|
||||
}
|
||||
|
||||
try {
|
||||
TraxUtils.doWithSource(source, null);
|
||||
Assert.fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
public String getSystemId() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
@Test
|
||||
public void testDoWithInvalidResult() throws Exception {
|
||||
Result result = new Result() {
|
||||
try {
|
||||
TraxUtils.doWithSource(source, null);
|
||||
Assert.fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void setSystemId(String systemId) {
|
||||
}
|
||||
@Test
|
||||
public void testDoWithInvalidResult() throws Exception {
|
||||
Result result = new Result() {
|
||||
|
||||
public String getSystemId() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
public void setSystemId(String systemId) {
|
||||
}
|
||||
|
||||
try {
|
||||
TraxUtils.doWithResult(result, null);
|
||||
Assert.fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
public String getSystemId() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
TraxUtils.doWithResult(result, null);
|
||||
Assert.fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -38,123 +38,123 @@ import org.xml.sax.SAXParseException;
|
||||
|
||||
public abstract class AbstractValidatorFactoryTestCase {
|
||||
|
||||
private XmlValidator validator;
|
||||
private XmlValidator validator;
|
||||
|
||||
private InputStream validInputStream;
|
||||
private InputStream validInputStream;
|
||||
|
||||
private InputStream invalidInputStream;
|
||||
private InputStream invalidInputStream;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Resource[] schemaResource =
|
||||
new Resource[]{new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class)};
|
||||
validator = createValidator(schemaResource, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
validInputStream = AbstractValidatorFactoryTestCase.class.getResourceAsStream("validDocument.xml");
|
||||
invalidInputStream = AbstractValidatorFactoryTestCase.class.getResourceAsStream("invalidDocument.xml");
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Resource[] schemaResource =
|
||||
new Resource[]{new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class)};
|
||||
validator = createValidator(schemaResource, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
validInputStream = AbstractValidatorFactoryTestCase.class.getResourceAsStream("validDocument.xml");
|
||||
invalidInputStream = AbstractValidatorFactoryTestCase.class.getResourceAsStream("invalidDocument.xml");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
validInputStream.close();
|
||||
invalidInputStream.close();
|
||||
}
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
validInputStream.close();
|
||||
invalidInputStream.close();
|
||||
}
|
||||
|
||||
protected abstract XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws Exception;
|
||||
protected abstract XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws Exception;
|
||||
|
||||
@Test
|
||||
public void testHandleValidMessageStream() throws Exception {
|
||||
SAXParseException[] errors = validator.validate(new StreamSource(validInputStream));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
@Test
|
||||
public void testHandleValidMessageStream() throws Exception {
|
||||
SAXParseException[] errors = validator.validate(new StreamSource(validInputStream));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateTwice() throws Exception {
|
||||
validator.validate(new StreamSource(validInputStream));
|
||||
validInputStream = AbstractValidatorFactoryTestCase.class.getResourceAsStream("validDocument.xml");
|
||||
validator.validate(new StreamSource(validInputStream));
|
||||
}
|
||||
@Test
|
||||
public void testValidateTwice() throws Exception {
|
||||
validator.validate(new StreamSource(validInputStream));
|
||||
validInputStream = AbstractValidatorFactoryTestCase.class.getResourceAsStream("validDocument.xml");
|
||||
validator.validate(new StreamSource(validInputStream));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleInvalidMessageStream() throws Exception {
|
||||
SAXParseException[] errors = validator.validate(new StreamSource(invalidInputStream));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 3, errors.length);
|
||||
}
|
||||
@Test
|
||||
public void testHandleInvalidMessageStream() throws Exception {
|
||||
SAXParseException[] errors = validator.validate(new StreamSource(invalidInputStream));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 3, errors.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleValidMessageSax() throws Exception {
|
||||
SAXParseException[] errors = validator.validate(new SAXSource(new InputSource(validInputStream)));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
@Test
|
||||
public void testHandleValidMessageSax() throws Exception {
|
||||
SAXParseException[] errors = validator.validate(new SAXSource(new InputSource(validInputStream)));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleInvalidMessageSax() throws Exception {
|
||||
SAXParseException[] errors = validator.validate(new SAXSource(new InputSource(invalidInputStream)));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 3, errors.length);
|
||||
}
|
||||
@Test
|
||||
public void testHandleInvalidMessageSax() throws Exception {
|
||||
SAXParseException[] errors = validator.validate(new SAXSource(new InputSource(invalidInputStream)));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 3, errors.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleValidMessageDom() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
Document document = documentBuilderFactory.newDocumentBuilder()
|
||||
.parse(new InputSource(validInputStream));
|
||||
SAXParseException[] errors = validator.validate(new DOMSource(document));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
@Test
|
||||
public void testHandleValidMessageDom() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
Document document = documentBuilderFactory.newDocumentBuilder()
|
||||
.parse(new InputSource(validInputStream));
|
||||
SAXParseException[] errors = validator.validate(new DOMSource(document));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleInvalidMessageDom() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
Document document = documentBuilderFactory.newDocumentBuilder()
|
||||
.parse(new InputSource(invalidInputStream));
|
||||
SAXParseException[] errors = validator.validate(new DOMSource(document));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 3, errors.length);
|
||||
}
|
||||
@Test
|
||||
public void testHandleInvalidMessageDom() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
Document document = documentBuilderFactory.newDocumentBuilder()
|
||||
.parse(new InputSource(invalidInputStream));
|
||||
SAXParseException[] errors = validator.validate(new DOMSource(document));
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 3, errors.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleSchemasValidMessage() throws Exception {
|
||||
Resource[] schemaResources = new Resource[]{
|
||||
new ClassPathResource("multipleSchemas1.xsd", AbstractValidatorFactoryTestCase.class),
|
||||
new ClassPathResource("multipleSchemas2.xsd", AbstractValidatorFactoryTestCase.class)};
|
||||
validator = createValidator(schemaResources, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
@Test
|
||||
public void testMultipleSchemasValidMessage() throws Exception {
|
||||
Resource[] schemaResources = new Resource[]{
|
||||
new ClassPathResource("multipleSchemas1.xsd", AbstractValidatorFactoryTestCase.class),
|
||||
new ClassPathResource("multipleSchemas2.xsd", AbstractValidatorFactoryTestCase.class)};
|
||||
validator = createValidator(schemaResources, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
|
||||
Source document = new ResourceSource(
|
||||
new ClassPathResource("multipleSchemas1.xml", AbstractValidatorFactoryTestCase.class));
|
||||
SAXParseException[] errors = validator.validate(document);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
validator = createValidator(schemaResources, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
document = new ResourceSource(
|
||||
new ClassPathResource("multipleSchemas2.xml", AbstractValidatorFactoryTestCase.class));
|
||||
errors = validator.validate(document);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
Source document = new ResourceSource(
|
||||
new ClassPathResource("multipleSchemas1.xml", AbstractValidatorFactoryTestCase.class));
|
||||
SAXParseException[] errors = validator.validate(document);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
validator = createValidator(schemaResources, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
document = new ResourceSource(
|
||||
new ClassPathResource("multipleSchemas2.xml", AbstractValidatorFactoryTestCase.class));
|
||||
errors = validator.validate(document);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customErrorHandler() throws Exception {
|
||||
ValidationErrorHandler myHandler = new ValidationErrorHandler() {
|
||||
public SAXParseException[] getErrors() {
|
||||
return new SAXParseException[0];
|
||||
}
|
||||
@Test
|
||||
public void customErrorHandler() throws Exception {
|
||||
ValidationErrorHandler myHandler = new ValidationErrorHandler() {
|
||||
public SAXParseException[] getErrors() {
|
||||
return new SAXParseException[0];
|
||||
}
|
||||
|
||||
public void warning(SAXParseException exception) throws SAXException {
|
||||
}
|
||||
public void warning(SAXParseException exception) throws SAXException {
|
||||
}
|
||||
|
||||
public void error(SAXParseException exception) throws SAXException {
|
||||
}
|
||||
public void error(SAXParseException exception) throws SAXException {
|
||||
}
|
||||
|
||||
public void fatalError(SAXParseException exception) throws SAXException {
|
||||
}
|
||||
};
|
||||
SAXParseException[] errors = validator.validate(new StreamSource(invalidInputStream), myHandler);
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
public void fatalError(SAXParseException exception) throws SAXException {
|
||||
}
|
||||
};
|
||||
SAXParseException[] errors = validator.validate(new StreamSource(invalidInputStream), myHandler);
|
||||
Assert.assertNotNull("Null returned for errors", errors);
|
||||
Assert.assertEquals("ValidationErrors returned", 0, errors.length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ import org.springframework.core.io.Resource;
|
||||
|
||||
public class Jaxp13ValidatorFactoryTest extends AbstractValidatorFactoryTestCase {
|
||||
|
||||
@Override
|
||||
protected XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws IOException {
|
||||
return Jaxp13ValidatorFactory.createValidator(schemaResources, schemaLanguage);
|
||||
}
|
||||
@Override
|
||||
protected XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws IOException {
|
||||
return Jaxp13ValidatorFactory.createValidator(schemaResources, schemaLanguage);
|
||||
}
|
||||
}
|
||||
@@ -27,45 +27,45 @@ import org.junit.Test;
|
||||
|
||||
public class SchemaLoaderUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testLoadSchema() throws Exception {
|
||||
Resource resource = new ClassPathResource("schema.xsd", getClass());
|
||||
Schema schema = SchemaLoaderUtils.loadSchema(resource, XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Assert.assertNotNull("No schema returned", schema);
|
||||
Assert.assertFalse("Resource not closed", resource.isOpen());
|
||||
}
|
||||
@Test
|
||||
public void testLoadSchema() throws Exception {
|
||||
Resource resource = new ClassPathResource("schema.xsd", getClass());
|
||||
Schema schema = SchemaLoaderUtils.loadSchema(resource, XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Assert.assertNotNull("No schema returned", schema);
|
||||
Assert.assertFalse("Resource not closed", resource.isOpen());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadNonExistantSchema() throws Exception {
|
||||
try {
|
||||
Resource nonExistant = new ClassPathResource("bla");
|
||||
SchemaLoaderUtils.loadSchema(nonExistant, XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Assert.fail("Should have thrown an IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testLoadNonExistantSchema() throws Exception {
|
||||
try {
|
||||
Resource nonExistant = new ClassPathResource("bla");
|
||||
SchemaLoaderUtils.loadSchema(nonExistant, XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Assert.fail("Should have thrown an IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadNullSchema() throws Exception {
|
||||
try {
|
||||
SchemaLoaderUtils.loadSchema((Resource) null, XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Assert.fail("Should have thrown an IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testLoadNullSchema() throws Exception {
|
||||
try {
|
||||
SchemaLoaderUtils.loadSchema((Resource) null, XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Assert.fail("Should have thrown an IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadMultipleSchemas() throws Exception {
|
||||
Resource envelope = new ClassPathResource("envelope.xsd", getClass());
|
||||
Resource encoding = new ClassPathResource("encoding.xsd", getClass());
|
||||
Schema schema =
|
||||
SchemaLoaderUtils.loadSchema(new Resource[]{envelope, encoding}, XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Assert.assertNotNull("No schema returned", schema);
|
||||
Assert.assertFalse("Resource not closed", envelope.isOpen());
|
||||
Assert.assertFalse("Resource not closed", encoding.isOpen());
|
||||
}
|
||||
@Test
|
||||
public void testLoadMultipleSchemas() throws Exception {
|
||||
Resource envelope = new ClassPathResource("envelope.xsd", getClass());
|
||||
Resource encoding = new ClassPathResource("encoding.xsd", getClass());
|
||||
Schema schema =
|
||||
SchemaLoaderUtils.loadSchema(new Resource[]{envelope, encoding}, XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
||||
Assert.assertNotNull("No schema returned", schema);
|
||||
Assert.assertFalse("Resource not closed", envelope.isOpen());
|
||||
Assert.assertFalse("Resource not closed", encoding.isOpen());
|
||||
}
|
||||
}
|
||||
@@ -31,87 +31,87 @@ import org.springframework.core.io.Resource;
|
||||
|
||||
public class XmlValidatorFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testCreateValidator() throws Exception {
|
||||
Resource resource = new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class);
|
||||
XmlValidator validator = XmlValidatorFactory.createValidator(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
Assert.assertNotNull("No validator returned", validator);
|
||||
}
|
||||
@Test
|
||||
public void testCreateValidator() throws Exception {
|
||||
Resource resource = new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class);
|
||||
XmlValidator validator = XmlValidatorFactory.createValidator(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
Assert.assertNotNull("No validator returned", validator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistentResource() throws Exception {
|
||||
Resource resource = new NonExistentResource();
|
||||
try {
|
||||
XmlValidatorFactory.createValidator(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
Assert.fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testNonExistentResource() throws Exception {
|
||||
Resource resource = new NonExistentResource();
|
||||
try {
|
||||
XmlValidatorFactory.createValidator(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
Assert.fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidSchemaLanguage() throws Exception {
|
||||
Resource resource = new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class);
|
||||
try {
|
||||
XmlValidatorFactory.createValidator(resource, "bla");
|
||||
Assert.fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testInvalidSchemaLanguage() throws Exception {
|
||||
Resource resource = new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class);
|
||||
try {
|
||||
XmlValidatorFactory.createValidator(resource, "bla");
|
||||
Assert.fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
private static class NonExistentResource extends AbstractResource {
|
||||
private static class NonExistentResource extends AbstractResource {
|
||||
|
||||
@Override
|
||||
public Resource createRelative(String relativePath) throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
@Override
|
||||
public Resource createRelative(String relativePath) throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getFile() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
@Override
|
||||
public File getFile() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getURL() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
@Override
|
||||
public URL getURL() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
@Override
|
||||
public URI getURI() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean isReadable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,207 +36,207 @@ import org.xml.sax.SAXException;
|
||||
|
||||
public abstract class AbstractXPathExpressionFactoryTestCase {
|
||||
|
||||
private Document noNamespacesDocument;
|
||||
private Document noNamespacesDocument;
|
||||
|
||||
private Document namespacesDocument;
|
||||
private Document namespacesDocument;
|
||||
|
||||
private Map<String, String> namespaces = new HashMap<String, String>();
|
||||
private Map<String, String> namespaces = new HashMap<String, String>();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
namespaces.put("prefix1", "namespace1");
|
||||
namespaces.put("prefix2", "namespace2");
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
InputStream inputStream = getClass().getResourceAsStream("nonamespaces.xml");
|
||||
try {
|
||||
noNamespacesDocument = documentBuilder.parse(inputStream);
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
inputStream = getClass().getResourceAsStream("namespaces.xml");
|
||||
try {
|
||||
namespacesDocument = documentBuilder.parse(inputStream);
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
namespaces.put("prefix1", "namespace1");
|
||||
namespaces.put("prefix2", "namespace2");
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
InputStream inputStream = getClass().getResourceAsStream("nonamespaces.xml");
|
||||
try {
|
||||
noNamespacesDocument = documentBuilder.parse(inputStream);
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
inputStream = getClass().getResourceAsStream("namespaces.xml");
|
||||
try {
|
||||
namespacesDocument = documentBuilder.parse(inputStream);
|
||||
}
|
||||
finally {
|
||||
inputStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsBooleanInvalidNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
|
||||
boolean result = expression.evaluateAsBoolean(namespacesDocument);
|
||||
Assert.assertFalse("Invalid result [" + result + "]", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsBooleanInvalidNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
|
||||
boolean result = expression.evaluateAsBoolean(namespacesDocument);
|
||||
Assert.assertFalse("Invalid result [" + result + "]", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsBooleanInvalidNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/otherchild");
|
||||
boolean result = expression.evaluateAsBoolean(noNamespacesDocument);
|
||||
Assert.assertFalse("Invalid result [" + result + "]", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsBooleanInvalidNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/otherchild");
|
||||
boolean result = expression.evaluateAsBoolean(noNamespacesDocument);
|
||||
Assert.assertFalse("Invalid result [" + result + "]", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsBooleanNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression =
|
||||
createXPathExpression("/prefix1:root/prefix2:child/prefix2:boolean/text()", namespaces);
|
||||
boolean result = expression.evaluateAsBoolean(namespacesDocument);
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsBooleanNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression =
|
||||
createXPathExpression("/prefix1:root/prefix2:child/prefix2:boolean/text()", namespaces);
|
||||
boolean result = expression.evaluateAsBoolean(namespacesDocument);
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsBooleanNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child/boolean/text()");
|
||||
boolean result = expression.evaluateAsBoolean(noNamespacesDocument);
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsBooleanNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child/boolean/text()");
|
||||
boolean result = expression.evaluateAsBoolean(noNamespacesDocument);
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsDoubleInvalidNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
|
||||
double result = expression.evaluateAsNumber(noNamespacesDocument);
|
||||
Assert.assertTrue("Invalid result [" + result + "]", Double.isNaN(result));
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsDoubleInvalidNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
|
||||
double result = expression.evaluateAsNumber(noNamespacesDocument);
|
||||
Assert.assertTrue("Invalid result [" + result + "]", Double.isNaN(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsDoubleInvalidNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/otherchild");
|
||||
double result = expression.evaluateAsNumber(noNamespacesDocument);
|
||||
Assert.assertTrue("Invalid result [" + result + "]", Double.isNaN(result));
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsDoubleInvalidNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/otherchild");
|
||||
double result = expression.evaluateAsNumber(noNamespacesDocument);
|
||||
Assert.assertTrue("Invalid result [" + result + "]", Double.isNaN(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsDoubleNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression =
|
||||
createXPathExpression("/prefix1:root/prefix2:child/prefix2:number/text()", namespaces);
|
||||
double result = expression.evaluateAsNumber(namespacesDocument);
|
||||
Assert.assertEquals("Invalid result", 42D, result, 0D);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsDoubleNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression =
|
||||
createXPathExpression("/prefix1:root/prefix2:child/prefix2:number/text()", namespaces);
|
||||
double result = expression.evaluateAsNumber(namespacesDocument);
|
||||
Assert.assertEquals("Invalid result", 42D, result, 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsDoubleNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child/number/text()");
|
||||
double result = expression.evaluateAsNumber(noNamespacesDocument);
|
||||
Assert.assertEquals("Invalid result", 42D, result, 0D);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsDoubleNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child/number/text()");
|
||||
double result = expression.evaluateAsNumber(noNamespacesDocument);
|
||||
Assert.assertEquals("Invalid result", 42D, result, 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNodeInvalidNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
|
||||
Node result = expression.evaluateAsNode(namespacesDocument);
|
||||
Assert.assertNull("Invalid result [" + result + "]", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNodeInvalidNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
|
||||
Node result = expression.evaluateAsNode(namespacesDocument);
|
||||
Assert.assertNull("Invalid result [" + result + "]", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNodeInvalidNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/otherchild");
|
||||
Node result = expression.evaluateAsNode(noNamespacesDocument);
|
||||
Assert.assertNull("Invalid result [" + result + "]", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNodeInvalidNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/otherchild");
|
||||
Node result = expression.evaluateAsNode(noNamespacesDocument);
|
||||
Assert.assertNull("Invalid result [" + result + "]", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNodeNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child", namespaces);
|
||||
Node result = expression.evaluateAsNode(namespacesDocument);
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result.getLocalName());
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNodeNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child", namespaces);
|
||||
Node result = expression.evaluateAsNode(namespacesDocument);
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result.getLocalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNodeNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child");
|
||||
Node result = expression.evaluateAsNode(noNamespacesDocument);
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result.getLocalName());
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNodeNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child");
|
||||
Node result = expression.evaluateAsNode(noNamespacesDocument);
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result.getLocalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNodeListNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child/*", namespaces);
|
||||
List<Node> results = expression.evaluateAsNodeList(namespacesDocument);
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNodeListNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:child/*", namespaces);
|
||||
List<Node> results = expression.evaluateAsNodeList(namespacesDocument);
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNodeListNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child/*");
|
||||
List<Node> results = expression.evaluateAsNodeList(noNamespacesDocument);
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNodeListNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child/*");
|
||||
List<Node> results = expression.evaluateAsNodeList(noNamespacesDocument);
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsStringInvalidNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
|
||||
String result = expression.evaluateAsString(namespacesDocument);
|
||||
Assert.assertFalse("Invalid result [" + result + "]", StringUtils.hasText(result));
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsStringInvalidNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
|
||||
String result = expression.evaluateAsString(namespacesDocument);
|
||||
Assert.assertFalse("Invalid result [" + result + "]", StringUtils.hasText(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsStringInvalidNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/otherchild");
|
||||
String result = expression.evaluateAsString(noNamespacesDocument);
|
||||
Assert.assertFalse("Invalid result [" + result + "]", StringUtils.hasText(result));
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsStringInvalidNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/otherchild");
|
||||
String result = expression.evaluateAsString(noNamespacesDocument);
|
||||
Assert.assertFalse("Invalid result [" + result + "]", StringUtils.hasText(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsStringNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression =
|
||||
createXPathExpression("/prefix1:root/prefix2:child/prefix2:text/text()", namespaces);
|
||||
String result = expression.evaluateAsString(namespacesDocument);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsStringNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression =
|
||||
createXPathExpression("/prefix1:root/prefix2:child/prefix2:text/text()", namespaces);
|
||||
String result = expression.evaluateAsString(namespacesDocument);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsStringNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child/text/text()");
|
||||
String result = expression.evaluateAsString(noNamespacesDocument);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsStringNoNamespaces() throws IOException, SAXException {
|
||||
XPathExpression expression = createXPathExpression("/root/child/text/text()");
|
||||
String result = expression.evaluateAsString(noNamespacesDocument);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsObject() throws Exception {
|
||||
XPathExpression expression = createXPathExpression("/root/child");
|
||||
String result = expression.evaluateAsObject(noNamespacesDocument, new NodeMapper<String>() {
|
||||
public String mapNode(Node node, int nodeNum) throws DOMException {
|
||||
return node.getLocalName();
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsObject() throws Exception {
|
||||
XPathExpression expression = createXPathExpression("/root/child");
|
||||
String result = expression.evaluateAsObject(noNamespacesDocument, new NodeMapper<String>() {
|
||||
public String mapNode(Node node, int nodeNum) throws DOMException {
|
||||
return node.getLocalName();
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluate() throws Exception {
|
||||
XPathExpression expression = createXPathExpression("/root/child/*");
|
||||
List<String> results = expression.evaluate(noNamespacesDocument, new NodeMapper<String>() {
|
||||
public String mapNode(Node node, int nodeNum) throws DOMException {
|
||||
return node.getLocalName();
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
Assert.assertEquals("Invalid first result", "text", results.get(0));
|
||||
Assert.assertEquals("Invalid first result", "number", results.get(1));
|
||||
Assert.assertEquals("Invalid first result", "boolean", results.get(2));
|
||||
}
|
||||
@Test
|
||||
public void testEvaluate() throws Exception {
|
||||
XPathExpression expression = createXPathExpression("/root/child/*");
|
||||
List<String> results = expression.evaluate(noNamespacesDocument, new NodeMapper<String>() {
|
||||
public String mapNode(Node node, int nodeNum) throws DOMException {
|
||||
return node.getLocalName();
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
Assert.assertEquals("Invalid first result", "text", results.get(0));
|
||||
Assert.assertEquals("Invalid first result", "number", results.get(1));
|
||||
Assert.assertEquals("Invalid first result", "boolean", results.get(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidExpression() {
|
||||
try {
|
||||
createXPathExpression("\\");
|
||||
Assert.fail("No XPathParseException thrown");
|
||||
}
|
||||
catch (XPathParseException ex) {
|
||||
// Expected behaviour
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testInvalidExpression() {
|
||||
try {
|
||||
createXPathExpression("\\");
|
||||
Assert.fail("No XPathParseException thrown");
|
||||
}
|
||||
catch (XPathParseException ex) {
|
||||
// Expected behaviour
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract XPathExpression createXPathExpression(String expression);
|
||||
protected abstract XPathExpression createXPathExpression(String expression);
|
||||
|
||||
protected abstract XPathExpression createXPathExpression(String expression, Map<String, String> namespaces);
|
||||
protected abstract XPathExpression createXPathExpression(String expression, Map<String, String> namespaces);
|
||||
}
|
||||
|
||||
@@ -46,163 +46,163 @@ import org.xml.sax.SAXException;
|
||||
|
||||
public abstract class AbstractXPathTemplateTestCase {
|
||||
|
||||
XPathOperations template;
|
||||
XPathOperations template;
|
||||
|
||||
private Source namespaces;
|
||||
private Source namespaces;
|
||||
|
||||
private Source nonamespaces;
|
||||
private Source nonamespaces;
|
||||
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
template = createTemplate();
|
||||
namespaces = new ResourceSource(new ClassPathResource("namespaces.xml", AbstractXPathTemplateTestCase.class));
|
||||
nonamespaces =
|
||||
new ResourceSource(new ClassPathResource("nonamespaces.xml", AbstractXPathTemplateTestCase.class));
|
||||
}
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
template = createTemplate();
|
||||
namespaces = new ResourceSource(new ClassPathResource("namespaces.xml", AbstractXPathTemplateTestCase.class));
|
||||
nonamespaces =
|
||||
new ResourceSource(new ClassPathResource("nonamespaces.xml", AbstractXPathTemplateTestCase.class));
|
||||
}
|
||||
|
||||
protected abstract XPathOperations createTemplate() throws Exception;
|
||||
protected abstract XPathOperations createTemplate() throws Exception;
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsBoolean() {
|
||||
boolean result = template.evaluateAsBoolean("/root/child/boolean", nonamespaces);
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsBoolean() {
|
||||
boolean result = template.evaluateAsBoolean("/root/child/boolean", nonamespaces);
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsBooleanNamespaces() {
|
||||
boolean result = template.evaluateAsBoolean("/prefix1:root/prefix2:child/prefix2:boolean", namespaces);
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsBooleanNamespaces() {
|
||||
boolean result = template.evaluateAsBoolean("/prefix1:root/prefix2:child/prefix2:boolean", namespaces);
|
||||
Assert.assertTrue("Invalid result", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsDouble() {
|
||||
double result = template.evaluateAsDouble("/root/child/number", nonamespaces);
|
||||
Assert.assertEquals("Invalid result", 42D, result, 0D);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsDouble() {
|
||||
double result = template.evaluateAsDouble("/root/child/number", nonamespaces);
|
||||
Assert.assertEquals("Invalid result", 42D, result, 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsDoubleNamespaces() {
|
||||
double result = template.evaluateAsDouble("/prefix1:root/prefix2:child/prefix2:number", namespaces);
|
||||
Assert.assertEquals("Invalid result", 42D, result, 0D);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsDoubleNamespaces() {
|
||||
double result = template.evaluateAsDouble("/prefix1:root/prefix2:child/prefix2:number", namespaces);
|
||||
Assert.assertEquals("Invalid result", 42D, result, 0D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNode() {
|
||||
Node result = template.evaluateAsNode("/root/child", nonamespaces);
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result.getLocalName());
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNode() {
|
||||
Node result = template.evaluateAsNode("/root/child", nonamespaces);
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result.getLocalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNodeNamespaces() {
|
||||
Node result = template.evaluateAsNode("/prefix1:root/prefix2:child", namespaces);
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result.getLocalName());
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNodeNamespaces() {
|
||||
Node result = template.evaluateAsNode("/prefix1:root/prefix2:child", namespaces);
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result.getLocalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNodes() {
|
||||
List<Node> results = template.evaluateAsNodeList("/root/child/*", nonamespaces);
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNodes() {
|
||||
List<Node> results = template.evaluateAsNodeList("/root/child/*", nonamespaces);
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsNodesNamespaces() {
|
||||
List<Node> results = template.evaluateAsNodeList("/prefix1:root/prefix2:child/*", namespaces);
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsNodesNamespaces() {
|
||||
List<Node> results = template.evaluateAsNodeList("/prefix1:root/prefix2:child/*", namespaces);
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsStringNamespaces() throws IOException, SAXException {
|
||||
String result = template.evaluateAsString("/prefix1:root/prefix2:child/prefix2:text", namespaces);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsStringNamespaces() throws IOException, SAXException {
|
||||
String result = template.evaluateAsString("/prefix1:root/prefix2:child/prefix2:text", namespaces);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsString() throws IOException, SAXException {
|
||||
String result = template.evaluateAsString("/root/child/text", nonamespaces);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsString() throws IOException, SAXException {
|
||||
String result = template.evaluateAsString("/root/child/text", nonamespaces);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateDomSource() throws IOException, SAXException, ParserConfigurationException {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(SaxUtils.createInputSource(
|
||||
new ClassPathResource("nonamespaces.xml", AbstractXPathTemplateTestCase.class)));
|
||||
@Test
|
||||
public void testEvaluateDomSource() throws IOException, SAXException, ParserConfigurationException {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(SaxUtils.createInputSource(
|
||||
new ClassPathResource("nonamespaces.xml", AbstractXPathTemplateTestCase.class)));
|
||||
|
||||
String result = template.evaluateAsString("/root/child/text", new DOMSource(document));
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
String result = template.evaluateAsString("/root/child/text", new DOMSource(document));
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateSAXSource() throws Exception {
|
||||
InputStream in = AbstractXPathTemplateTestCase.class.getResourceAsStream("nonamespaces.xml");
|
||||
SAXSource source = new SAXSource(new InputSource(in));
|
||||
String result = template.evaluateAsString("/root/child/text", source);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateSAXSource() throws Exception {
|
||||
InputStream in = AbstractXPathTemplateTestCase.class.getResourceAsStream("nonamespaces.xml");
|
||||
SAXSource source = new SAXSource(new InputSource(in));
|
||||
String result = template.evaluateAsString("/root/child/text", source);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateStaxSource() throws Exception {
|
||||
InputStream in = AbstractXPathTemplateTestCase.class.getResourceAsStream("nonamespaces.xml");
|
||||
XMLStreamReader streamReader = XMLInputFactory.newFactory().createXMLStreamReader(in);
|
||||
StAXSource source = new StAXSource(streamReader);
|
||||
String result = template.evaluateAsString("/root/child/text", source);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateStaxSource() throws Exception {
|
||||
InputStream in = AbstractXPathTemplateTestCase.class.getResourceAsStream("nonamespaces.xml");
|
||||
XMLStreamReader streamReader = XMLInputFactory.newFactory().createXMLStreamReader(in);
|
||||
StAXSource source = new StAXSource(streamReader);
|
||||
String result = template.evaluateAsString("/root/child/text", source);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateStreamSourceInputStream() throws IOException, SAXException, ParserConfigurationException {
|
||||
InputStream in = AbstractXPathTemplateTestCase.class.getResourceAsStream("nonamespaces.xml");
|
||||
StreamSource source = new StreamSource(in);
|
||||
String result = template.evaluateAsString("/root/child/text", source);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateStreamSourceInputStream() throws IOException, SAXException, ParserConfigurationException {
|
||||
InputStream in = AbstractXPathTemplateTestCase.class.getResourceAsStream("nonamespaces.xml");
|
||||
StreamSource source = new StreamSource(in);
|
||||
String result = template.evaluateAsString("/root/child/text", source);
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateStreamSourceSystemId() throws IOException, SAXException, ParserConfigurationException {
|
||||
URL url = AbstractXPathTemplateTestCase.class.getResource("nonamespaces.xml");
|
||||
String result = template.evaluateAsString("/root/child/text", new StreamSource(url.toString()));
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateStreamSourceSystemId() throws IOException, SAXException, ParserConfigurationException {
|
||||
URL url = AbstractXPathTemplateTestCase.class.getResource("nonamespaces.xml");
|
||||
String result = template.evaluateAsString("/root/child/text", new StreamSource(url.toString()));
|
||||
Assert.assertEquals("Invalid result", "text", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidExpression() {
|
||||
try {
|
||||
template.evaluateAsBoolean("\\", namespaces);
|
||||
Assert.fail("No XPathException thrown");
|
||||
}
|
||||
catch (XPathException ex) {
|
||||
// Expected behaviour
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testInvalidExpression() {
|
||||
try {
|
||||
template.evaluateAsBoolean("\\", namespaces);
|
||||
Assert.fail("No XPathException thrown");
|
||||
}
|
||||
catch (XPathException ex) {
|
||||
// Expected behaviour
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluateAsObject() throws Exception {
|
||||
String result = template.evaluateAsObject("/root/child", nonamespaces, new NodeMapper<String>() {
|
||||
public String mapNode(Node node, int nodeNum) throws DOMException {
|
||||
return node.getLocalName();
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result);
|
||||
}
|
||||
@Test
|
||||
public void testEvaluateAsObject() throws Exception {
|
||||
String result = template.evaluateAsObject("/root/child", nonamespaces, new NodeMapper<String>() {
|
||||
public String mapNode(Node node, int nodeNum) throws DOMException {
|
||||
return node.getLocalName();
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull("Invalid result", result);
|
||||
Assert.assertEquals("Invalid localname", "child", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEvaluate() throws Exception {
|
||||
List<String> results = template.evaluate("/root/child/*", nonamespaces, new NodeMapper<String>() {
|
||||
public String mapNode(Node node, int nodeNum) throws DOMException {
|
||||
return node.getLocalName();
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
Assert.assertEquals("Invalid first result", "text", results.get(0));
|
||||
Assert.assertEquals("Invalid first result", "number", results.get(1));
|
||||
Assert.assertEquals("Invalid first result", "boolean", results.get(2));
|
||||
}
|
||||
@Test
|
||||
public void testEvaluate() throws Exception {
|
||||
List<String> results = template.evaluate("/root/child/*", nonamespaces, new NodeMapper<String>() {
|
||||
public String mapNode(Node node, int nodeNum) throws DOMException {
|
||||
return node.getLocalName();
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull("Invalid result", results);
|
||||
Assert.assertEquals("Invalid amount of results", 3, results.size());
|
||||
Assert.assertEquals("Invalid first result", "text", results.get(0));
|
||||
Assert.assertEquals("Invalid first result", "number", results.get(1));
|
||||
Assert.assertEquals("Invalid first result", "boolean", results.get(2));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,24 +23,24 @@ import org.xml.sax.SAXException;
|
||||
|
||||
public class JaxenXPathExpressionFactoryTest extends AbstractXPathExpressionFactoryTestCase {
|
||||
|
||||
@Override
|
||||
protected XPathExpression createXPathExpression(String expression) {
|
||||
return JaxenXPathExpressionFactory.createXPathExpression(expression);
|
||||
}
|
||||
@Override
|
||||
protected XPathExpression createXPathExpression(String expression) {
|
||||
return JaxenXPathExpressionFactory.createXPathExpression(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) {
|
||||
return JaxenXPathExpressionFactory.createXPathExpression(expression, namespaces);
|
||||
}
|
||||
@Override
|
||||
protected XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) {
|
||||
return JaxenXPathExpressionFactory.createXPathExpression(expression, namespaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testEvaluateAsDoubleNoNamespaces() throws IOException, SAXException {
|
||||
// Currently not working on Jaxen 1.1 beta 8, hence the override here
|
||||
}
|
||||
@Override
|
||||
public void testEvaluateAsDoubleNoNamespaces() throws IOException, SAXException {
|
||||
// Currently not working on Jaxen 1.1 beta 8, hence the override here
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testEvaluateAsDoubleNamespaces() throws IOException, SAXException {
|
||||
// Currently not working on Jaxen 1.1 beta 8, hence the override here
|
||||
}
|
||||
@Override
|
||||
public void testEvaluateAsDoubleNamespaces() throws IOException, SAXException {
|
||||
// Currently not working on Jaxen 1.1 beta 8, hence the override here
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,14 +21,14 @@ import java.util.Map;
|
||||
|
||||
public class JaxenXPathTemplateTest extends AbstractXPathTemplateTestCase {
|
||||
|
||||
@Override
|
||||
protected XPathOperations createTemplate() throws Exception {
|
||||
JaxenXPathTemplate template = new JaxenXPathTemplate();
|
||||
Map<String, String> namespaces = new HashMap<String, String>();
|
||||
namespaces.put("prefix1", "namespace1");
|
||||
namespaces.put("prefix2", "namespace2");
|
||||
template.setNamespaces(namespaces);
|
||||
return template;
|
||||
}
|
||||
@Override
|
||||
protected XPathOperations createTemplate() throws Exception {
|
||||
JaxenXPathTemplate template = new JaxenXPathTemplate();
|
||||
Map<String, String> namespaces = new HashMap<String, String>();
|
||||
namespaces.put("prefix1", "namespace1");
|
||||
namespaces.put("prefix2", "namespace2");
|
||||
template.setNamespaces(namespaces);
|
||||
return template;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,13 +20,13 @@ import java.util.Map;
|
||||
|
||||
public class Jaxp13XPathExpressionFactoryTest extends AbstractXPathExpressionFactoryTestCase {
|
||||
|
||||
@Override
|
||||
protected XPathExpression createXPathExpression(String expression) {
|
||||
return Jaxp13XPathExpressionFactory.createXPathExpression(expression);
|
||||
}
|
||||
@Override
|
||||
protected XPathExpression createXPathExpression(String expression) {
|
||||
return Jaxp13XPathExpressionFactory.createXPathExpression(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) {
|
||||
return Jaxp13XPathExpressionFactory.createXPathExpression(expression, namespaces);
|
||||
}
|
||||
@Override
|
||||
protected XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) {
|
||||
return Jaxp13XPathExpressionFactory.createXPathExpression(expression, namespaces);
|
||||
}
|
||||
}
|
||||
@@ -21,14 +21,14 @@ import java.util.Map;
|
||||
|
||||
public class Jaxp13XPathTemplateTest extends AbstractXPathTemplateTestCase {
|
||||
|
||||
@Override
|
||||
protected XPathOperations createTemplate() throws Exception {
|
||||
Jaxp13XPathTemplate template = new Jaxp13XPathTemplate();
|
||||
Map<String, String> namespaces = new HashMap<String, String>();
|
||||
namespaces.put("prefix1", "namespace1");
|
||||
namespaces.put("prefix2", "namespace2");
|
||||
template.setNamespaces(namespaces);
|
||||
return template;
|
||||
}
|
||||
@Override
|
||||
protected XPathOperations createTemplate() throws Exception {
|
||||
Jaxp13XPathTemplate template = new Jaxp13XPathTemplate();
|
||||
Map<String, String> namespaces = new HashMap<String, String>();
|
||||
namespaces.put("prefix1", "namespace1");
|
||||
namespaces.put("prefix2", "namespace2");
|
||||
template.setNamespaces(namespaces);
|
||||
return template;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,21 +22,21 @@ import org.junit.Test;
|
||||
|
||||
public class XPathExpressionFactoryBeanTest {
|
||||
|
||||
private XPathExpressionFactoryBean factoryBean;
|
||||
private XPathExpressionFactoryBean factoryBean;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factoryBean = new XPathExpressionFactoryBean();
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factoryBean = new XPathExpressionFactoryBean();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactoryBean() throws Exception {
|
||||
factoryBean.setExpression("/root");
|
||||
factoryBean.afterPropertiesSet();
|
||||
Object result = factoryBean.getObject();
|
||||
Assert.assertNotNull("No result obtained", result);
|
||||
Assert.assertTrue("No XPathExpression returned", result instanceof XPathExpression);
|
||||
Assert.assertTrue("Not a singleton", factoryBean.isSingleton());
|
||||
Assert.assertEquals("Not a XPathExpresison", XPathExpression.class, factoryBean.getObjectType());
|
||||
}
|
||||
@Test
|
||||
public void testFactoryBean() throws Exception {
|
||||
factoryBean.setExpression("/root");
|
||||
factoryBean.afterPropertiesSet();
|
||||
Object result = factoryBean.getObject();
|
||||
Assert.assertNotNull("No result obtained", result);
|
||||
Assert.assertTrue("No XPathExpression returned", result instanceof XPathExpression);
|
||||
Assert.assertTrue("Not a singleton", factoryBean.isSingleton());
|
||||
Assert.assertEquals("Not a XPathExpresison", XPathExpression.class, factoryBean.getObjectType());
|
||||
}
|
||||
}
|
||||
@@ -21,20 +21,20 @@ import org.junit.Test;
|
||||
|
||||
public class XPathExpressionFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testCreateXPathExpression() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/root");
|
||||
Assert.assertNotNull("No expression returned", expression);
|
||||
}
|
||||
@Test
|
||||
public void testCreateXPathExpression() throws Exception {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/root");
|
||||
Assert.assertNotNull("No expression returned", expression);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEmptyXPathExpression() throws Exception {
|
||||
try {
|
||||
XPathExpressionFactory.createXPathExpression("");
|
||||
Assert.fail("Should have thrown an Exception");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testCreateEmptyXPathExpression() throws Exception {
|
||||
try {
|
||||
XPathExpressionFactory.createXPathExpression("");
|
||||
Assert.fail("Should have thrown an Exception");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,83 +37,83 @@ import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public abstract class AbstractXsdSchemaTestCase {
|
||||
|
||||
private DocumentBuilder documentBuilder;
|
||||
private DocumentBuilder documentBuilder;
|
||||
|
||||
protected Transformer transformer;
|
||||
protected Transformer transformer;
|
||||
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingle() throws Exception {
|
||||
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema single = createSchema(resource);
|
||||
String namespace = "http://www.springframework.org/spring-ws/single/schema";
|
||||
Assert.assertEquals("Invalid target namespace", namespace, single.getTargetNamespace());
|
||||
resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(single.getSource(), domResult);
|
||||
Document result = (Document) domResult.getNode();
|
||||
assertXMLEqual("Invalid Source returned", expected, result);
|
||||
}
|
||||
@Test
|
||||
public void testSingle() throws Exception {
|
||||
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema single = createSchema(resource);
|
||||
String namespace = "http://www.springframework.org/spring-ws/single/schema";
|
||||
Assert.assertEquals("Invalid target namespace", namespace, single.getTargetNamespace());
|
||||
resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(single.getSource(), domResult);
|
||||
Document result = (Document) domResult.getNode();
|
||||
assertXMLEqual("Invalid Source returned", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludes() throws Exception {
|
||||
Resource resource = new ClassPathResource("including.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema including = createSchema(resource);
|
||||
String namespace = "http://www.springframework.org/spring-ws/include/schema";
|
||||
Assert.assertEquals("Invalid target namespace", namespace, including.getTargetNamespace());
|
||||
resource = new ClassPathResource("including.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(including.getSource(), domResult);
|
||||
Document result = (Document) domResult.getNode();
|
||||
assertXMLEqual("Invalid Source returned", expected, result);
|
||||
}
|
||||
@Test
|
||||
public void testIncludes() throws Exception {
|
||||
Resource resource = new ClassPathResource("including.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema including = createSchema(resource);
|
||||
String namespace = "http://www.springframework.org/spring-ws/include/schema";
|
||||
Assert.assertEquals("Invalid target namespace", namespace, including.getTargetNamespace());
|
||||
resource = new ClassPathResource("including.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(including.getSource(), domResult);
|
||||
Document result = (Document) domResult.getNode();
|
||||
assertXMLEqual("Invalid Source returned", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImports() throws Exception {
|
||||
Resource resource = new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema importing = createSchema(resource);
|
||||
String namespace = "http://www.springframework.org/spring-ws/importing/schema";
|
||||
Assert.assertEquals("Invalid target namespace", namespace, importing.getTargetNamespace());
|
||||
resource = new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(importing.getSource(), domResult);
|
||||
Document result = (Document) domResult.getNode();
|
||||
assertXMLEqual("Invalid Source returned", expected, result);
|
||||
}
|
||||
@Test
|
||||
public void testImports() throws Exception {
|
||||
Resource resource = new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema importing = createSchema(resource);
|
||||
String namespace = "http://www.springframework.org/spring-ws/importing/schema";
|
||||
Assert.assertEquals("Invalid target namespace", namespace, importing.getTargetNamespace());
|
||||
resource = new ClassPathResource("importing.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(importing.getSource(), domResult);
|
||||
Document result = (Document) domResult.getNode();
|
||||
assertXMLEqual("Invalid Source returned", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlNamespace() throws Exception {
|
||||
Resource resource = new ClassPathResource("xmlNamespace.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema importing = createSchema(resource);
|
||||
String namespace = "http://www.springframework.org/spring-ws/xmlNamespace";
|
||||
Assert.assertEquals("Invalid target namespace", namespace, importing.getTargetNamespace());
|
||||
resource = new ClassPathResource("xmlNamespace.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(importing.getSource(), domResult);
|
||||
Document result = (Document) domResult.getNode();
|
||||
assertXMLEqual("Invalid Source returned", expected, result);
|
||||
}
|
||||
@Test
|
||||
public void testXmlNamespace() throws Exception {
|
||||
Resource resource = new ClassPathResource("xmlNamespace.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema importing = createSchema(resource);
|
||||
String namespace = "http://www.springframework.org/spring-ws/xmlNamespace";
|
||||
Assert.assertEquals("Invalid target namespace", namespace, importing.getTargetNamespace());
|
||||
resource = new ClassPathResource("xmlNamespace.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(resource));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(importing.getSource(), domResult);
|
||||
Document result = (Document) domResult.getNode();
|
||||
assertXMLEqual("Invalid Source returned", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateValidator() throws Exception {
|
||||
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema single = createSchema(resource);
|
||||
XmlValidator validator = single.createValidator();
|
||||
Assert.assertNotNull("No XmlValidator returned", validator);
|
||||
}
|
||||
@Test
|
||||
public void testCreateValidator() throws Exception {
|
||||
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema single = createSchema(resource);
|
||||
XmlValidator validator = single.createValidator();
|
||||
Assert.assertNotNull("No XmlValidator returned", validator);
|
||||
}
|
||||
|
||||
protected abstract XsdSchema createSchema(Resource resource) throws Exception;
|
||||
protected abstract XsdSchema createSchema(Resource resource) throws Exception;
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ import org.springframework.core.io.Resource;
|
||||
|
||||
public class SimpleXsdSchemaTest extends AbstractXsdSchemaTestCase {
|
||||
|
||||
@Override
|
||||
protected XsdSchema createSchema(Resource resource) throws Exception {
|
||||
SimpleXsdSchema schema = new SimpleXsdSchema(resource);
|
||||
schema.afterPropertiesSet();
|
||||
return schema;
|
||||
}
|
||||
@Override
|
||||
protected XsdSchema createSchema(Resource resource) throws Exception {
|
||||
SimpleXsdSchema schema = new SimpleXsdSchema(resource);
|
||||
schema.afterPropertiesSet();
|
||||
return schema;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,122 +39,122 @@ import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class CommonsXsdSchemaCollectionTest {
|
||||
|
||||
private CommonsXsdSchemaCollection collection;
|
||||
private CommonsXsdSchemaCollection collection;
|
||||
|
||||
private Transformer transformer;
|
||||
private Transformer transformer;
|
||||
|
||||
private DocumentBuilder documentBuilder;
|
||||
private DocumentBuilder documentBuilder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
collection = new CommonsXsdSchemaCollection();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
collection = new CommonsXsdSchemaCollection();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingle() throws Exception {
|
||||
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{resource});
|
||||
collection.afterPropertiesSet();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 1, collection.getXsdSchemas().length);
|
||||
}
|
||||
@Test
|
||||
public void testSingle() throws Exception {
|
||||
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{resource});
|
||||
collection.afterPropertiesSet();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 1, collection.getXsdSchemas().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInlineComplex() throws Exception {
|
||||
Resource a = new ClassPathResource("A.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{a});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
XsdSchema[] schemas = collection.getXsdSchemas();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 2, schemas.length);
|
||||
@Test
|
||||
public void testInlineComplex() throws Exception {
|
||||
Resource a = new ClassPathResource("A.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{a});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
XsdSchema[] schemas = collection.getXsdSchemas();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 2, schemas.length);
|
||||
|
||||
Assert.assertEquals("Invalid target namespace", "urn:1", schemas[0].getTargetNamespace());
|
||||
Resource abc = new ClassPathResource("ABC.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(abc));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(schemas[0].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
Assert.assertEquals("Invalid target namespace", "urn:1", schemas[0].getTargetNamespace());
|
||||
Resource abc = new ClassPathResource("ABC.xsd", AbstractXsdSchemaTestCase.class);
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(abc));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(schemas[0].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
|
||||
Assert.assertEquals("Invalid target namespace", "urn:2", schemas[1].getTargetNamespace());
|
||||
Resource cd = new ClassPathResource("CD.xsd", AbstractXsdSchemaTestCase.class);
|
||||
expected = documentBuilder.parse(SaxUtils.createInputSource(cd));
|
||||
domResult = new DOMResult();
|
||||
transformer.transform(schemas[1].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
}
|
||||
Assert.assertEquals("Invalid target namespace", "urn:2", schemas[1].getTargetNamespace());
|
||||
Resource cd = new ClassPathResource("CD.xsd", AbstractXsdSchemaTestCase.class);
|
||||
expected = documentBuilder.parse(SaxUtils.createInputSource(cd));
|
||||
domResult = new DOMResult();
|
||||
transformer.transform(schemas[1].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCircular() throws Exception {
|
||||
Resource resource = new ClassPathResource("circular-1.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{resource});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
XsdSchema[] schemas = collection.getXsdSchemas();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 1, schemas.length);
|
||||
}
|
||||
@Test
|
||||
public void testCircular() throws Exception {
|
||||
Resource resource = new ClassPathResource("circular-1.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{resource});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
XsdSchema[] schemas = collection.getXsdSchemas();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 1, schemas.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlNamespace() throws Exception {
|
||||
Resource resource = new ClassPathResource("xmlNamespace.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{resource});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
XsdSchema[] schemas = collection.getXsdSchemas();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 1, schemas.length);
|
||||
}
|
||||
@Test
|
||||
public void testXmlNamespace() throws Exception {
|
||||
Resource resource = new ClassPathResource("xmlNamespace.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{resource});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
XsdSchema[] schemas = collection.getXsdSchemas();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 1, schemas.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateValidator() throws Exception {
|
||||
Resource a = new ClassPathResource("A.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{a});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
@Test
|
||||
public void testCreateValidator() throws Exception {
|
||||
Resource a = new ClassPathResource("A.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{a});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
|
||||
XmlValidator validator = collection.createValidator();
|
||||
Assert.assertNotNull("No XmlValidator returned", validator);
|
||||
}
|
||||
XmlValidator validator = collection.createValidator();
|
||||
Assert.assertNotNull("No XmlValidator returned", validator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidSchema() throws Exception {
|
||||
Resource invalid = new ClassPathResource("invalid.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{invalid});
|
||||
try {
|
||||
collection.afterPropertiesSet();
|
||||
Assert.fail("CommonsXsdSchemaException expected");
|
||||
}
|
||||
catch (CommonsXsdSchemaException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testInvalidSchema() throws Exception {
|
||||
Resource invalid = new ClassPathResource("invalid.xsd", AbstractXsdSchemaTestCase.class);
|
||||
collection.setXsds(new Resource[]{invalid});
|
||||
try {
|
||||
collection.afterPropertiesSet();
|
||||
Assert.fail("CommonsXsdSchemaException expected");
|
||||
}
|
||||
catch (CommonsXsdSchemaException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludesAndImports() throws Exception {
|
||||
Resource hr = new ClassPathResource("hr.xsd", getClass());
|
||||
collection.setXsds(new Resource[]{hr});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
@Test
|
||||
public void testIncludesAndImports() throws Exception {
|
||||
Resource hr = new ClassPathResource("hr.xsd", getClass());
|
||||
collection.setXsds(new Resource[]{hr});
|
||||
collection.setInline(true);
|
||||
collection.afterPropertiesSet();
|
||||
|
||||
XsdSchema[] schemas = collection.getXsdSchemas();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 2, schemas.length);
|
||||
XsdSchema[] schemas = collection.getXsdSchemas();
|
||||
Assert.assertEquals("Invalid amount of XSDs loaded", 2, schemas.length);
|
||||
|
||||
Assert.assertEquals("Invalid target namespace", "http://mycompany.com/hr/schemas", schemas[0].getTargetNamespace());
|
||||
Resource hr_employee = new ClassPathResource("hr_employee.xsd", getClass());
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(hr_employee));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(schemas[0].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
Assert.assertEquals("Invalid target namespace", "http://mycompany.com/hr/schemas", schemas[0].getTargetNamespace());
|
||||
Resource hr_employee = new ClassPathResource("hr_employee.xsd", getClass());
|
||||
Document expected = documentBuilder.parse(SaxUtils.createInputSource(hr_employee));
|
||||
DOMResult domResult = new DOMResult();
|
||||
transformer.transform(schemas[0].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
|
||||
Assert.assertEquals("Invalid target namespace", "http://mycompany.com/hr/schemas/holiday", schemas[1].getTargetNamespace());
|
||||
Resource holiday = new ClassPathResource("holiday.xsd", getClass());
|
||||
expected = documentBuilder.parse(SaxUtils.createInputSource(holiday));
|
||||
domResult = new DOMResult();
|
||||
transformer.transform(schemas[1].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
Assert.assertEquals("Invalid target namespace", "http://mycompany.com/hr/schemas/holiday", schemas[1].getTargetNamespace());
|
||||
Resource holiday = new ClassPathResource("holiday.xsd", getClass());
|
||||
expected = documentBuilder.parse(SaxUtils.createInputSource(holiday));
|
||||
domResult = new DOMResult();
|
||||
transformer.transform(schemas[1].getSource(), domResult);
|
||||
assertXMLEqual("Invalid XSD generated", expected, (Document) domResult.getNode());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@@ -35,25 +35,25 @@ import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class CommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
|
||||
|
||||
@Override
|
||||
protected XsdSchema createSchema(Resource resource) throws Exception {
|
||||
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
|
||||
XmlSchema schema = schemaCollection.read(SaxUtils.createInputSource(resource));
|
||||
return new CommonsXsdSchema(schema);
|
||||
}
|
||||
@Override
|
||||
protected XsdSchema createSchema(Resource resource) throws Exception {
|
||||
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
|
||||
XmlSchema schema = schemaCollection.read(SaxUtils.createInputSource(resource));
|
||||
return new CommonsXsdSchema(schema);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmime() throws Exception {
|
||||
Resource resource = new ClassPathResource("xmime.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema schema = createSchema(resource);
|
||||
String namespace = "urn:test";
|
||||
assertEquals("Invalid target namespace", namespace, schema.getTargetNamespace());
|
||||
Document result = (Document) ((DOMSource) schema.getSource()).getNode();
|
||||
Element schemaElement = result.getDocumentElement();
|
||||
Element elementElement = (Element) schemaElement.getFirstChild();
|
||||
assertNotNull("No expectedContentTypes found",
|
||||
elementElement.getAttributeNS("http://www.w3.org/2005/05/xmlmime", "expectedContentTypes"));
|
||||
}
|
||||
@Test
|
||||
public void testXmime() throws Exception {
|
||||
Resource resource = new ClassPathResource("xmime.xsd", AbstractXsdSchemaTestCase.class);
|
||||
XsdSchema schema = createSchema(resource);
|
||||
String namespace = "urn:test";
|
||||
assertEquals("Invalid target namespace", namespace, schema.getTargetNamespace());
|
||||
Document result = (Document) ((DOMSource) schema.getSource()).getNode();
|
||||
Element schemaElement = result.getDocumentElement();
|
||||
Element elementElement = (Element) schemaElement.getFirstChild();
|
||||
assertNotNull("No expectedContentTypes found",
|
||||
elementElement.getAttributeNS("http://www.w3.org/2005/05/xmlmime", "expectedContentTypes"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user