diff --git a/core/src/main/java/org/springframework/ws/client/support/destination/Wsdl11DestinationProvider.java b/core/src/main/java/org/springframework/ws/client/support/destination/Wsdl11DestinationProvider.java
index 1d807ce7..a74c0c67 100644
--- a/core/src/main/java/org/springframework/ws/client/support/destination/Wsdl11DestinationProvider.java
+++ b/core/src/main/java/org/springframework/ws/client/support/destination/Wsdl11DestinationProvider.java
@@ -18,7 +18,8 @@ package org.springframework.ws.client.support.destination;
import java.io.IOException;
import java.net.URI;
-import java.util.Properties;
+import java.util.HashMap;
+import java.util.Map;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
@@ -38,7 +39,7 @@ import org.springframework.xml.xpath.XPathExpressionFactory;
* Implementation of the {@link DestinationProvider} that resolves a destination URI from a WSDL file.
*
* The extraction relies on an XPath expression to locate the URI. By default, the {@link
- * #DEFAULT_WSDL_LOCATION_EXPRESSION} will be used, but this expression can be overriden by setting the {@link
+ * #DEFAULT_WSDL_LOCATION_EXPRESSION} will be used, but this expression can be overridden by setting the {@link
* #setLocationExpression(String) locationExpression} property.
*
* @author Tareq Abed Rabbo
@@ -53,16 +54,16 @@ public class Wsdl11DestinationProvider extends AbstractCachingDestinationProvide
private static TransformerFactory transformerFactory = TransformerFactory.newInstance();
- private Properties expressionNamespaces = new Properties();
+ private Map expressionNamespaces = new HashMap();
private XPathExpression locationXPathExpression;
private Resource wsdlResource;
public Wsdl11DestinationProvider() {
- expressionNamespaces.setProperty("wsdl", "http://schemas.xmlsoap.org/wsdl/");
- expressionNamespaces.setProperty("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
- expressionNamespaces.setProperty("soap12", "http://schemas.xmlsoap.org/wsdl/soap12/");
+ expressionNamespaces.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
+ expressionNamespaces.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
+ expressionNamespaces.put("soap12", "http://schemas.xmlsoap.org/wsdl/soap12/");
locationXPathExpression = XPathExpressionFactory
.createXPathExpression(DEFAULT_WSDL_LOCATION_EXPRESSION, expressionNamespaces);
diff --git a/xml/src/test/java/org/springframework/xml/dom/DomContentHandlerTest.java b/xml/src/test/java/org/springframework/xml/dom/DomContentHandlerTest.java
index ded8e101..07e18f2f 100644
--- a/xml/src/test/java/org/springframework/xml/dom/DomContentHandlerTest.java
+++ b/xml/src/test/java/org/springframework/xml/dom/DomContentHandlerTest.java
@@ -20,14 +20,19 @@ import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Before;
+import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
-public class DomContentHandlerTest extends XMLTestCase {
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
+
+public class DomContentHandlerTest {
private static final String XML_1 = "" + "" +
"" +
@@ -50,8 +55,8 @@ public class DomContentHandlerTest extends XMLTestCase {
private DocumentBuilder documentBuilder;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilder = documentBuilderFactory.newDocumentBuilder();
@@ -59,6 +64,7 @@ public class DomContentHandlerTest extends XMLTestCase {
xmlReader = XMLReaderFactory.createXMLReader();
}
+ @Test
public void testContentHandlerDocumentNamespacePrefixes() throws Exception {
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
handler = new DomContentHandler(result);
@@ -68,6 +74,7 @@ public class DomContentHandlerTest extends XMLTestCase {
assertXMLEqual("Invalid result", expected, result);
}
+ @Test
public void testContentHandlerDocumentNoNamespacePrefixes() throws Exception {
handler = new DomContentHandler(result);
expected = documentBuilder.parse(new InputSource(new StringReader(XML_1)));
@@ -76,6 +83,7 @@ public class DomContentHandlerTest extends XMLTestCase {
assertXMLEqual("Invalid result", expected, result);
}
+ @Test
public void testContentHandlerElement() throws Exception {
Element rootElement = result.createElementNS("namespace", "root");
result.appendChild(rootElement);
diff --git a/xml/src/test/java/org/springframework/xml/namespace/QNameEditorTest.java b/xml/src/test/java/org/springframework/xml/namespace/QNameEditorTest.java
index 9a1a398e..60cbd452 100644
--- a/xml/src/test/java/org/springframework/xml/namespace/QNameEditorTest.java
+++ b/xml/src/test/java/org/springframework/xml/namespace/QNameEditorTest.java
@@ -19,26 +19,32 @@ package org.springframework.xml.namespace;
import javax.xml.namespace.QName;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class QNameEditorTest extends TestCase {
+public class QNameEditorTest {
private QNameEditor editor;
- @Override
- protected void setUp() throws Exception {
+ @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 testNamespaceLocalPart() throws Exception {
QName qname = new QName("namespace", "localpart");
doTest(qname);
}
+ @Test
public void testLocalPart() throws Exception {
QName qname = new QName("localpart");
doTest(qname);
@@ -47,13 +53,13 @@ public class QNameEditorTest extends TestCase {
private void doTest(QName qname) {
editor.setValue(qname);
String text = editor.getAsText();
- assertNotNull("getAsText returns null", text);
+ Assert.assertNotNull("getAsText returns null", text);
editor.setAsText(text);
QName result = (QName) editor.getValue();
- assertNotNull("getValue returns null", result);
- assertEquals("Parsed QName local part is not equal to original", qname.getLocalPart(), result.getLocalPart());
- assertEquals("Parsed QName prefix is not equal to original", qname.getPrefix(), result.getPrefix());
- assertEquals("Parsed QName namespace is not equal to original", qname.getNamespaceURI(),
+ 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());
}
}
\ No newline at end of file
diff --git a/xml/src/test/java/org/springframework/xml/namespace/QNameUtilsTest.java b/xml/src/test/java/org/springframework/xml/namespace/QNameUtilsTest.java
index cffdafe3..784da4c2 100644
--- a/xml/src/test/java/org/springframework/xml/namespace/QNameUtilsTest.java
+++ b/xml/src/test/java/org/springframework/xml/namespace/QNameUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,85 +21,96 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import org.springframework.util.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-public class QNameUtilsTest extends TestCase {
+public class QNameUtilsTest {
+ @Test
public void testValidQNames() {
- assertTrue("Namespace QName not validated", QNameUtils.validateQName("{namespace}local"));
- assertTrue("No Namespace QName not validated", QNameUtils.validateQName("local"));
+ Assert.assertTrue("Namespace QName not validated", QNameUtils.validateQName("{namespace}local"));
+ Assert.assertTrue("No Namespace QName not validated", QNameUtils.validateQName("local"));
}
+ @Test
public void testInvalidQNames() {
- assertFalse("Null QName validated", QNameUtils.validateQName(null));
- assertFalse("Empty QName validated", QNameUtils.validateQName(""));
- assertFalse("Invalid QName validated", QNameUtils.validateQName("{namespace}"));
- assertFalse("Invalid QName validated", QNameUtils.validateQName("{namespace"));
+ 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);
- assertNotNull("getQNameForNode returns null", qName);
- assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
- assertFalse("Qname has invalid namespace", StringUtils.hasLength(qName.getNamespaceURI()));
- assertFalse("Qname has invalid prefix", StringUtils.hasLength(qName.getPrefix()));
+ 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);
- assertNotNull("getQNameForNode returns null", qName);
- assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
- assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
- assertFalse("Qname has invalid prefix", StringUtils.hasLength(qName.getPrefix()));
+ 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);
- assertNotNull("getQNameForNode returns null", qName);
- assertEquals("QName has invalid localname", "localname", qName.getLocalPart());
- assertEquals("Qname has invalid namespace", "namespace", qName.getNamespaceURI());
- assertEquals("Qname has invalid prefix", "prefix", qName.getPrefix());
+ 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);
- assertEquals("Invalid result", "prefix:localName", result);
+ Assert.assertEquals("Invalid result", "prefix:localName", result);
}
+ @Test
public void testToQualifiedNameNoPrefix() throws Exception {
QName qName = new QName("localName");
String result = QNameUtils.toQualifiedName(qName);
- assertEquals("Invalid result", "localName", result);
+ Assert.assertEquals("Invalid result", "localName", result);
}
+ @Test
public void testToQNamePrefix() throws Exception {
QName result = QNameUtils.toQName("namespace", "prefix:localName");
- assertEquals("invalid namespace", "namespace", result.getNamespaceURI());
- assertEquals("invalid prefix", "prefix", result.getPrefix());
- assertEquals("invalid localname", "localName", result.getLocalPart());
+ 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");
- assertEquals("invalid namespace", "namespace", result.getNamespaceURI());
- assertEquals("invalid prefix", "", result.getPrefix());
- assertEquals("invalid localname", "localName", result.getLocalPart());
+ Assert.assertEquals("invalid namespace", "namespace", result.getNamespaceURI());
+ Assert.assertEquals("invalid prefix", "", result.getPrefix());
+ Assert.assertEquals("invalid localname", "localName", result.getLocalPart());
}
diff --git a/xml/src/test/java/org/springframework/xml/namespace/SimpleNamespaceContextTest.java b/xml/src/test/java/org/springframework/xml/namespace/SimpleNamespaceContextTest.java
index 9b2188df..ca85abe8 100644
--- a/xml/src/test/java/org/springframework/xml/namespace/SimpleNamespaceContextTest.java
+++ b/xml/src/test/java/org/springframework/xml/namespace/SimpleNamespaceContextTest.java
@@ -22,90 +22,100 @@ import java.util.Iterator;
import javax.xml.XMLConstants;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class SimpleNamespaceContextTest extends TestCase {
+public class SimpleNamespaceContextTest {
private SimpleNamespaceContext context;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
context = new SimpleNamespaceContext();
context.bindNamespaceUri("prefix", "namespaceURI");
}
+ @Test
public void testGetNamespaceURI() {
- assertEquals("Invalid namespaceURI for default namespace", "", context
+ Assert.assertEquals("Invalid namespaceURI for default namespace", "", context
.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
String defaultNamespaceUri = "defaultNamespace";
context.bindNamespaceUri(XMLConstants.DEFAULT_NS_PREFIX, defaultNamespaceUri);
- assertEquals("Invalid namespaceURI for default namespace", defaultNamespaceUri, context
+ Assert.assertEquals("Invalid namespaceURI for default namespace", defaultNamespaceUri, context
.getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX));
- assertEquals("Invalid namespaceURI for bound prefix", "namespaceURI", context.getNamespaceURI("prefix"));
- assertEquals("Invalid namespaceURI for unbound prefix", "", context.getNamespaceURI("unbound"));
- assertEquals("Invalid namespaceURI for namespace prefix", XMLConstants.XML_NS_URI, context
+ 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));
- assertEquals("Invalid namespaceURI for attribute prefix", XMLConstants.XMLNS_ATTRIBUTE_NS_URI, context
+ Assert.assertEquals("Invalid namespaceURI for attribute prefix", XMLConstants.XMLNS_ATTRIBUTE_NS_URI, context
.getNamespaceURI(XMLConstants.XMLNS_ATTRIBUTE));
}
+ @Test
public void testGetPrefix() {
context.bindDefaultNamespaceUri("defaultNamespaceURI");
- assertEquals("Invalid prefix for default namespace", XMLConstants.DEFAULT_NS_PREFIX, context.getPrefix("defaultNamespaceURI"));
- assertEquals("Invalid prefix for bound namespace", "prefix", context.getPrefix("namespaceURI"));
- assertNull("Invalid prefix for unbound namespace", context.getPrefix("unbound"));
- assertEquals("Invalid prefix for namespace", XMLConstants.XML_NS_PREFIX, context
+ 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));
- assertEquals("Invalid prefix for attribute namespace", XMLConstants.XMLNS_ATTRIBUTE, context
+ 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");
- assertFalse("Invalid prefix for unbound namespace", context.getPrefixes("unbound").hasNext());
+ 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
public void testMultiplePrefixes() {
context.bindNamespaceUri("prefix1", "namespace");
context.bindNamespaceUri("prefix2", "namespace");
Iterator iterator = context.getPrefixes("namespace");
- assertNotNull("getPrefixes returns null", iterator);
- assertTrue("iterator is empty", iterator.hasNext());
+ Assert.assertNotNull("getPrefixes returns null", iterator);
+ Assert.assertTrue("iterator is empty", iterator.hasNext());
String result = (String) iterator.next();
- assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
- assertTrue("iterator is empty", iterator.hasNext());
+ Assert.assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
+ Assert.assertTrue("iterator is empty", iterator.hasNext());
result = (String) iterator.next();
- assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
- assertFalse("iterator contains more than two values", iterator.hasNext());
+ Assert.assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2"));
+ Assert.assertFalse("iterator contains more than two values", iterator.hasNext());
}
private void assertPrefixes(String namespaceUri, String prefix) {
Iterator iterator = context.getPrefixes(namespaceUri);
- assertNotNull("getPrefixes returns null", iterator);
- assertTrue("iterator is empty", iterator.hasNext());
+ Assert.assertNotNull("getPrefixes returns null", iterator);
+ Assert.assertTrue("iterator is empty", iterator.hasNext());
String result = (String) iterator.next();
- assertEquals("Invalid prefix", prefix, result);
- assertFalse("iterator contains multiple values", iterator.hasNext());
+ Assert.assertEquals("Invalid prefix", prefix, result);
+ Assert.assertFalse("iterator contains multiple values", iterator.hasNext());
}
+ @Test
public void testGetBoundPrefixes() throws Exception {
Iterator iterator = context.getBoundPrefixes();
- assertNotNull("getPrefixes returns null", iterator);
- assertTrue("iterator is empty", iterator.hasNext());
+ Assert.assertNotNull("getPrefixes returns null", iterator);
+ Assert.assertTrue("iterator is empty", iterator.hasNext());
String result = (String) iterator.next();
- assertEquals("Invalid prefix", "prefix", result);
- assertFalse("iterator contains multiple values", iterator.hasNext());
+ 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"));
- assertEquals("Invalid namespace uri", "namespace", context.getNamespaceURI("prefix"));
+ Assert.assertEquals("Invalid namespace uri", "namespace", context.getNamespaceURI("prefix"));
}
+ @Test
public void testRemoveBinding() {
context.clear();
String prefix1 = "prefix1";
@@ -114,48 +124,50 @@ public class SimpleNamespaceContextTest extends TestCase {
context.bindNamespaceUri(prefix1, namespaceUri);
context.bindNamespaceUri(prefix2, namespaceUri);
Iterator iter = context.getPrefixes(namespaceUri);
- assertTrue("iterator is empty", iter.hasNext());
- assertEquals(prefix1, iter.next());
- assertTrue("iterator is empty", iter.hasNext());
- assertEquals(prefix2, iter.next());
- assertFalse("iterator not empty", iter.hasNext());
+ 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());
context.removeBinding(prefix1);
iter = context.getPrefixes(namespaceUri);
- assertTrue("iterator is empty", iter.hasNext());
- assertEquals(prefix2, iter.next());
- assertFalse("iterator not empty", iter.hasNext());
+ Assert.assertTrue("iterator is empty", iter.hasNext());
+ Assert.assertEquals(prefix2, iter.next());
+ Assert.assertFalse("iterator not empty", iter.hasNext());
context.removeBinding(prefix2);
iter = context.getPrefixes(namespaceUri);
- assertFalse("iterator not empty", iter.hasNext());
+ Assert.assertFalse("iterator not empty", iter.hasNext());
}
+ @Test
public void testHasBinding() {
context.clear();
String prefix = "prefix";
- assertFalse("Context has binding", context.hasBinding(prefix));
+ Assert.assertFalse("Context has binding", context.hasBinding(prefix));
String namespaceUri = "namespaceUri";
context.bindNamespaceUri(prefix, namespaceUri);
- assertTrue("Context has no binding", context.hasBinding(prefix));
+ 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);
- assertEquals("Invalid prefix", XMLConstants.DEFAULT_NS_PREFIX, context.getPrefix(defaultNamespace));
+ Assert.assertEquals("Invalid prefix", XMLConstants.DEFAULT_NS_PREFIX, context.getPrefix(defaultNamespace));
Iterator iterator = context.getPrefixes(defaultNamespace);
- assertNotNull("getPrefixes returns null", iterator);
- assertTrue("iterator is empty", iterator.hasNext());
+ Assert.assertNotNull("getPrefixes returns null", iterator);
+ Assert.assertTrue("iterator is empty", iterator.hasNext());
String result = (String) iterator.next();
- assertTrue("Invalid prefix", result.equals(XMLConstants.DEFAULT_NS_PREFIX) || result.equals("prefix"));
- assertTrue("iterator is empty", iterator.hasNext());
+ Assert.assertTrue("Invalid prefix", result.equals(XMLConstants.DEFAULT_NS_PREFIX) || result.equals("prefix"));
+ Assert.assertTrue("iterator is empty", iterator.hasNext());
result = (String) iterator.next();
- assertTrue("Invalid prefix", result.equals(XMLConstants.DEFAULT_NS_PREFIX) || result.equals("prefix"));
- assertFalse("iterator contains more than two values", iterator.hasNext());
+ Assert.assertTrue("Invalid prefix", result.equals(XMLConstants.DEFAULT_NS_PREFIX) || result.equals("prefix"));
+ Assert.assertFalse("iterator contains more than two values", iterator.hasNext());
}
}
diff --git a/xml/src/test/java/org/springframework/xml/sax/SaxUtilsTest.java b/xml/src/test/java/org/springframework/xml/sax/SaxUtilsTest.java
index 43f8a1fe..b5a39903 100644
--- a/xml/src/test/java/org/springframework/xml/sax/SaxUtilsTest.java
+++ b/xml/src/test/java/org/springframework/xml/sax/SaxUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright ${YEAR} the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,15 +18,18 @@ package org.springframework.xml.sax;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
-public class SaxUtilsTest extends TestCase {
+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);
- assertNotNull("No systemId returned", systemId);
- assertTrue("Invalid system id", systemId.endsWith("path%20with%20spaces/file%20with%20spaces.txt"));
+ Assert.assertNotNull("No systemId returned", systemId);
+ Assert.assertTrue("Invalid system id", systemId.endsWith("path%20with%20spaces/file%20with%20spaces.txt"));
}
}
\ No newline at end of file
diff --git a/xml/src/test/java/org/springframework/xml/stream/AbstractStaxContentHandlerTestCase.java b/xml/src/test/java/org/springframework/xml/stream/AbstractStaxContentHandlerTestCase.java
index becdfc3b..02152d9c 100644
--- a/xml/src/test/java/org/springframework/xml/stream/AbstractStaxContentHandlerTestCase.java
+++ b/xml/src/test/java/org/springframework/xml/stream/AbstractStaxContentHandlerTestCase.java
@@ -21,24 +21,30 @@ import java.io.StringWriter;
import java.io.Writer;
import javax.xml.stream.XMLStreamException;
+import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Before;
+import org.junit.Test;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.XMLReaderFactory;
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
+
@SuppressWarnings("Since15")
-public abstract class AbstractStaxContentHandlerTestCase extends XMLTestCase {
+public abstract class AbstractStaxContentHandlerTestCase {
private static final String XML_CONTENT_HANDLER =
"content";
private XMLReader xmlReader;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
xmlReader = XMLReaderFactory.createXMLReader();
}
+ @Test
public void testContentHandler() throws Exception {
StringWriter stringWriter = new StringWriter();
AbstractStaxContentHandler handler = createStaxContentHandler(stringWriter);
@@ -48,6 +54,7 @@ public abstract class AbstractStaxContentHandlerTestCase extends XMLTestCase {
assertXMLEqual("Invalid result", XML_CONTENT_HANDLER, stringWriter.toString());
}
+ @Test
public void testContentHandlerNamespacePrefixes() throws Exception {
StringWriter stringWriter = new StringWriter();
AbstractStaxContentHandler handler = createStaxContentHandler(stringWriter);
diff --git a/xml/src/test/java/org/springframework/xml/stream/AbstractStaxXmlReaderTestCase.java b/xml/src/test/java/org/springframework/xml/stream/AbstractStaxXmlReaderTestCase.java
index 17171d67..d3860330 100644
--- a/xml/src/test/java/org/springframework/xml/stream/AbstractStaxXmlReaderTestCase.java
+++ b/xml/src/test/java/org/springframework/xml/stream/AbstractStaxXmlReaderTestCase.java
@@ -25,6 +25,8 @@ import javax.xml.stream.XMLStreamException;
import junit.framework.TestCase;
import org.easymock.AbstractMatcher;
import org.easymock.MockControl;
+import org.junit.Before;
+import org.junit.Test;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -40,7 +42,7 @@ import org.springframework.core.io.Resource;
import org.springframework.xml.sax.SaxUtils;
@SuppressWarnings("Since15")
-public abstract class AbstractStaxXmlReaderTestCase extends TestCase {
+public abstract class AbstractStaxXmlReaderTestCase {
protected static XMLInputFactory inputFactory;
@@ -52,8 +54,8 @@ public abstract class AbstractStaxXmlReaderTestCase extends TestCase {
private ContentHandler contentHandler;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
inputFactory = XMLInputFactory.newInstance();
standardReader = XMLReaderFactory.createXMLReader();
contentHandlerControl = MockControl.createStrictControl(ContentHandler.class);
@@ -65,6 +67,7 @@ public abstract class AbstractStaxXmlReaderTestCase extends TestCase {
testContentHandler = new ClassPathResource("testContentHandler.xml", getClass());
}
+ @Test
public void testContentHandlerNamespacesNoPrefixes() throws SAXException, IOException, XMLStreamException {
standardReader.setFeature("http://xml.org/sax/features/namespaces", true);
standardReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
@@ -81,6 +84,7 @@ public abstract class AbstractStaxXmlReaderTestCase extends TestCase {
contentHandlerControl.verify();
}
+ @Test
public void testContentHandlerNamespacesPrefixes() throws SAXException, IOException, XMLStreamException {
standardReader.setFeature("http://xml.org/sax/features/namespaces", true);
standardReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
@@ -97,6 +101,7 @@ public abstract class AbstractStaxXmlReaderTestCase extends TestCase {
contentHandlerControl.verify();
}
+ @Test
public void testContentHandlerNoNamespacesPrefixes() throws SAXException, IOException, XMLStreamException {
standardReader.setFeature("http://xml.org/sax/features/namespaces", false);
standardReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
@@ -113,6 +118,7 @@ public abstract class AbstractStaxXmlReaderTestCase extends TestCase {
contentHandlerControl.verify();
}
+ @Test
public void testLexicalHandler() throws SAXException, IOException, XMLStreamException {
MockControl lexicalHandlerControl = MockControl.createStrictControl(LexicalHandler.class);
diff --git a/xml/src/test/java/org/springframework/xml/stream/StaxEventXmlReaderTest.java b/xml/src/test/java/org/springframework/xml/stream/StaxEventXmlReaderTest.java
index 2f09029b..39f4df98 100644
--- a/xml/src/test/java/org/springframework/xml/stream/StaxEventXmlReaderTest.java
+++ b/xml/src/test/java/org/springframework/xml/stream/StaxEventXmlReaderTest.java
@@ -23,6 +23,7 @@ import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import org.easymock.MockControl;
+import org.junit.Test;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.AttributesImpl;
@@ -37,6 +38,7 @@ public class StaxEventXmlReaderTest extends AbstractStaxXmlReaderTestCase {
return new StaxEventXmlReader(inputFactory.createXMLEventReader(inputStream));
}
+ @Test
public void testPartial() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(CONTENT));
diff --git a/xml/src/test/java/org/springframework/xml/stream/StaxStreamXmlReaderTest.java b/xml/src/test/java/org/springframework/xml/stream/StaxStreamXmlReaderTest.java
index 79efa167..2db017df 100644
--- a/xml/src/test/java/org/springframework/xml/stream/StaxStreamXmlReaderTest.java
+++ b/xml/src/test/java/org/springframework/xml/stream/StaxStreamXmlReaderTest.java
@@ -24,10 +24,13 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.easymock.MockControl;
+import org.junit.Test;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.AttributesImpl;
+import static org.junit.Assert.assertEquals;
+
@SuppressWarnings("Since15")
public class StaxStreamXmlReaderTest extends AbstractStaxXmlReaderTestCase {
@@ -38,6 +41,7 @@ public class StaxStreamXmlReaderTest extends AbstractStaxXmlReaderTestCase {
return new StaxStreamXmlReader(inputFactory.createXMLStreamReader(inputStream));
}
+ @Test
public void testPartial() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(CONTENT));
diff --git a/xml/src/test/java/org/springframework/xml/stream/XmlEventStreamReaderTest.java b/xml/src/test/java/org/springframework/xml/stream/XmlEventStreamReaderTest.java
index aa6a0710..6d0b04fd 100644
--- a/xml/src/test/java/org/springframework/xml/stream/XmlEventStreamReaderTest.java
+++ b/xml/src/test/java/org/springframework/xml/stream/XmlEventStreamReaderTest.java
@@ -22,12 +22,15 @@ import javax.xml.stream.XMLInputFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
+import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLTestCase;
import org.springframework.xml.transform.StaxSource;
import org.springframework.xml.transform.StringResult;
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
+
@SuppressWarnings("Since15")
-public class XmlEventStreamReaderTest extends XMLTestCase {
+public class XmlEventStreamReaderTest extends TestCase {
private static final String XML =
"content";
diff --git a/xml/src/test/java/org/springframework/xml/transform/ResourceSourceTest.java b/xml/src/test/java/org/springframework/xml/transform/ResourceSourceTest.java
index c4209aba..57ced5d8 100644
--- a/xml/src/test/java/org/springframework/xml/transform/ResourceSourceTest.java
+++ b/xml/src/test/java/org/springframework/xml/transform/ResourceSourceTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,21 +20,25 @@ import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
+import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Assert;
+import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.w3c.dom.Element;
-public class ResourceSourceTest extends XMLTestCase {
+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();
- assertEquals("Invalid local name", "content", rootElement.getLocalName());
- assertEquals("Invalid prefix", "prefix", rootElement.getPrefix());
- assertEquals("Invalid namespace", "namespace", rootElement.getNamespaceURI());
+ Assert.assertEquals("Invalid local name", "content", rootElement.getLocalName());
+ Assert.assertEquals("Invalid prefix", "prefix", rootElement.getPrefix());
+ Assert.assertEquals("Invalid namespace", "namespace", rootElement.getNamespaceURI());
}
}
\ No newline at end of file
diff --git a/xml/src/test/java/org/springframework/xml/transform/StaxResultTest.java b/xml/src/test/java/org/springframework/xml/transform/StaxResultTest.java
index 655fbd8a..5b8cacf6 100644
--- a/xml/src/test/java/org/springframework/xml/transform/StaxResultTest.java
+++ b/xml/src/test/java/org/springframework/xml/transform/StaxResultTest.java
@@ -24,10 +24,16 @@ import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
+import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
@SuppressWarnings("Since15")
-public class StaxResultTest extends XMLTestCase {
+public class StaxResultTest {
private static final String XML = "";
@@ -35,31 +41,33 @@ public class StaxResultTest extends XMLTestCase {
private XMLOutputFactory inputFactory;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
inputFactory = XMLOutputFactory.newInstance();
}
+ @Test
public void testStreamWriterSource() throws Exception {
StringWriter stringWriter = new StringWriter();
XMLStreamWriter streamWriter = inputFactory.createXMLStreamWriter(stringWriter);
Source source = new StringSource(XML);
StaxResult result = new StaxResult(streamWriter);
- assertEquals("Invalid streamWriter returned", streamWriter, result.getXMLStreamWriter());
- assertNull("EventWriter returned", result.getXMLEventWriter());
+ Assert.assertEquals("Invalid streamWriter returned", streamWriter, result.getXMLStreamWriter());
+ Assert.assertNull("EventWriter returned", result.getXMLEventWriter());
transformer.transform(source, result);
assertXMLEqual("Invalid result", XML, stringWriter.toString());
}
+ @Test
public void testEventWriterSource() throws Exception {
StringWriter stringWriter = new StringWriter();
XMLEventWriter eventWriter = inputFactory.createXMLEventWriter(stringWriter);
Source source = new StringSource(XML);
StaxResult result = new StaxResult(eventWriter);
- assertEquals("Invalid eventWriter returned", eventWriter, result.getXMLEventWriter());
- assertNull("StreamWriter returned", result.getXMLStreamWriter());
+ Assert.assertEquals("Invalid eventWriter returned", eventWriter, result.getXMLEventWriter());
+ Assert.assertNull("StreamWriter returned", result.getXMLStreamWriter());
transformer.transform(source, result);
assertXMLEqual("Invalid result", XML, stringWriter.toString());
}
diff --git a/xml/src/test/java/org/springframework/xml/transform/StaxSourceTest.java b/xml/src/test/java/org/springframework/xml/transform/StaxSourceTest.java
index 63647fc5..455114d2 100644
--- a/xml/src/test/java/org/springframework/xml/transform/StaxSourceTest.java
+++ b/xml/src/test/java/org/springframework/xml/transform/StaxSourceTest.java
@@ -24,10 +24,16 @@ import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
+import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
@SuppressWarnings("Since15")
-public class StaxSourceTest extends XMLTestCase {
+public class StaxSourceTest {
private static final String XML = "";
@@ -35,28 +41,30 @@ public class StaxSourceTest extends XMLTestCase {
private XMLInputFactory inputFactory;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
inputFactory = XMLInputFactory.newInstance();
}
+ @Test
public void testStreamReaderSource() throws Exception {
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(XML));
StaxSource source = new StaxSource(streamReader);
- assertEquals("Invalid streamReader returned", streamReader, source.getXMLStreamReader());
- assertNull("EventReader returned", source.getXMLEventReader());
+ Assert.assertEquals("Invalid streamReader returned", streamReader, source.getXMLStreamReader());
+ Assert.assertNull("EventReader returned", source.getXMLEventReader());
Result result = new StringResult();
transformer.transform(source, result);
assertXMLEqual("Invalid result", XML, result.toString());
}
+ @Test
public void testEventReaderSource() throws Exception {
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(XML));
StaxSource source = new StaxSource(eventReader);
- assertEquals("Invalid eventReader returned", eventReader, source.getXMLEventReader());
- assertNull("StreamReader returned", source.getXMLStreamReader());
+ Assert.assertEquals("Invalid eventReader returned", eventReader, source.getXMLEventReader());
+ Assert.assertNull("StreamReader returned", source.getXMLStreamReader());
Result result = new StringResult();
transformer.transform(source, result);
assertXMLEqual("Invalid result", XML, result.toString());
diff --git a/xml/src/test/java/org/springframework/xml/transform/StringResultTest.java b/xml/src/test/java/org/springframework/xml/transform/StringResultTest.java
index 23604b6a..054adeaa 100644
--- a/xml/src/test/java/org/springframework/xml/transform/StringResultTest.java
+++ b/xml/src/test/java/org/springframework/xml/transform/StringResultTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,12 +21,17 @@ import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
+import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLTestCase;
+import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-public class StringResultTest extends XMLTestCase {
+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");
diff --git a/xml/src/test/java/org/springframework/xml/transform/StringSourceTest.java b/xml/src/test/java/org/springframework/xml/transform/StringSourceTest.java
index bd32fcc5..778acccd 100644
--- a/xml/src/test/java/org/springframework/xml/transform/StringSourceTest.java
+++ b/xml/src/test/java/org/springframework/xml/transform/StringSourceTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,18 +22,21 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import org.w3c.dom.Element;
-public class StringSourceTest extends TestCase {
+public class StringSourceTest {
+ @Test
public void testStringSource() throws TransformerException {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
String content = "";
DOMResult result = new DOMResult();
transformer.transform(new StringSource(content), result);
Element rootElement = (Element) result.getNode().getFirstChild();
- assertEquals("Invalid local name", "content", rootElement.getLocalName());
- assertEquals("Invalid prefix", "prefix", rootElement.getPrefix());
- assertEquals("Invalid namespace", "namespace", rootElement.getNamespaceURI());
+ Assert.assertEquals("Invalid local name", "content", rootElement.getLocalName());
+ Assert.assertEquals("Invalid prefix", "prefix", rootElement.getPrefix());
+ Assert.assertEquals("Invalid namespace", "namespace", rootElement.getNamespaceURI());
}
}
\ No newline at end of file
diff --git a/xml/src/test/java/org/springframework/xml/transform/TraxUtilsTest.java b/xml/src/test/java/org/springframework/xml/transform/TraxUtilsTest.java
index cb8e9c86..e5e0a652 100644
--- a/xml/src/test/java/org/springframework/xml/transform/TraxUtilsTest.java
+++ b/xml/src/test/java/org/springframework/xml/transform/TraxUtilsTest.java
@@ -45,8 +45,11 @@ import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
+import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLTestCase;
import org.easymock.MockControl;
+import org.junit.Assert;
+import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.ContentHandler;
@@ -57,55 +60,64 @@ import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
-@SuppressWarnings("Since15")
-public class TraxUtilsTest extends XMLTestCase {
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
+@SuppressWarnings("Since15")
+public class TraxUtilsTest {
+
+ @Test
public void testIsStaxSourceInvalid() throws Exception {
- assertFalse("A StAX Source", TraxUtils.isStaxSource(new DOMSource()));
- assertFalse("A StAX Source", TraxUtils.isStaxSource(new SAXSource()));
- assertFalse("A StAX Source", TraxUtils.isStaxSource(new StreamSource()));
+ Assert.assertFalse("A StAX Source", TraxUtils.isStaxSource(new DOMSource()));
+ Assert.assertFalse("A StAX Source", TraxUtils.isStaxSource(new SAXSource()));
+ Assert.assertFalse("A StAX Source", TraxUtils.isStaxSource(new StreamSource()));
}
+ @Test
public void testIsStaxSource() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
String expected = "";
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(expected));
StaxSource source = new StaxSource(streamReader);
- assertTrue("Not a StAX Source", TraxUtils.isStaxSource(source));
+ Assert.assertTrue("Not a StAX Source", TraxUtils.isStaxSource(source));
}
+ @Test
public void testIsStaxSourceJaxp14() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
String expected = "";
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(expected));
StAXSource source = new StAXSource(streamReader);
- assertTrue("Not a StAX Source", TraxUtils.isStaxSource(source));
+ Assert.assertTrue("Not a StAX Source", TraxUtils.isStaxSource(source));
}
+ @Test
public void testIsStaxResultInvalid() throws Exception {
- assertFalse("A StAX Result", TraxUtils.isStaxResult(new DOMResult()));
- assertFalse("A StAX Result", TraxUtils.isStaxResult(new SAXResult()));
- assertFalse("A StAX Result", TraxUtils.isStaxResult(new StreamResult()));
+ Assert.assertFalse("A StAX Result", TraxUtils.isStaxResult(new DOMResult()));
+ Assert.assertFalse("A StAX Result", TraxUtils.isStaxResult(new SAXResult()));
+ Assert.assertFalse("A StAX Result", TraxUtils.isStaxResult(new StreamResult()));
}
+ @Test
public void testIsStaxResult() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
StaxResult result = new StaxResult(streamWriter);
- assertTrue("Not a StAX Result", TraxUtils.isStaxResult(result));
+ Assert.assertTrue("Not a StAX Result", TraxUtils.isStaxResult(result));
}
+ @Test
public void testIsStaxResultJaxp14() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
StAXResult result = new StAXResult(streamWriter);
- assertTrue("Not a StAX Result", TraxUtils.isStaxResult(result));
+ Assert.assertTrue("Not a StAX Result", TraxUtils.isStaxResult(result));
}
+ @Test
public void testCreateStaxSourceStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
String expected = "";
@@ -120,6 +132,7 @@ public class TraxUtilsTest extends XMLTestCase {
assertXMLEqual(expected, result.toString());
}
+ @Test
public void testCreateStaxSourceEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
String expected = "";
@@ -134,6 +147,7 @@ public class TraxUtilsTest extends XMLTestCase {
assertXMLEqual(expected, result.toString());
}
+ @Test
public void testGetXMLStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
String expected = "";
@@ -141,9 +155,10 @@ public class TraxUtilsTest extends XMLTestCase {
StaxSource source = new StaxSource(streamReader);
- assertEquals("Invalid XMLStreamReader", streamReader, TraxUtils.getXMLStreamReader(source));
+ Assert.assertEquals("Invalid XMLStreamReader", streamReader, TraxUtils.getXMLStreamReader(source));
}
+ @Test
public void testGetXMLStreamReaderJaxp14() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
String expected = "";
@@ -151,9 +166,10 @@ public class TraxUtilsTest extends XMLTestCase {
StAXSource source = new StAXSource(streamReader);
- assertEquals("Invalid XMLStreamReader", streamReader, TraxUtils.getXMLStreamReader(source));
+ Assert.assertEquals("Invalid XMLStreamReader", streamReader, TraxUtils.getXMLStreamReader(source));
}
+ @Test
public void testGetXMLEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
String expected = "";
@@ -161,9 +177,10 @@ public class TraxUtilsTest extends XMLTestCase {
StaxSource source = new StaxSource(eventReader);
- assertEquals("Invalid XMLEventReader", eventReader, TraxUtils.getXMLEventReader(source));
+ Assert.assertEquals("Invalid XMLEventReader", eventReader, TraxUtils.getXMLEventReader(source));
}
+ @Test
public void testGetXMLEventReaderJaxp14() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
String expected = "";
@@ -171,56 +188,62 @@ public class TraxUtilsTest extends XMLTestCase {
StAXSource source = new StAXSource(eventReader);
- assertEquals("Invalid XMLEventReader", eventReader, TraxUtils.getXMLEventReader(source));
+ Assert.assertEquals("Invalid XMLEventReader", eventReader, TraxUtils.getXMLEventReader(source));
}
+ @Test
public void testGetXMLStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
StaxResult result = new StaxResult(streamWriter);
- assertEquals("Invalid XMLStreamWriter", streamWriter, TraxUtils.getXMLStreamWriter(result));
+ Assert.assertEquals("Invalid XMLStreamWriter", streamWriter, TraxUtils.getXMLStreamWriter(result));
}
+ @Test
public void testGetXMLStreamWriterJaxp14() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
StAXResult result = new StAXResult(streamWriter);
- assertEquals("Invalid XMLStreamWriter", streamWriter, TraxUtils.getXMLStreamWriter(result));
+ Assert.assertEquals("Invalid XMLStreamWriter", streamWriter, TraxUtils.getXMLStreamWriter(result));
}
+ @Test
public void testGetXMLEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new StringWriter());
StaxResult result = new StaxResult(eventWriter);
- assertEquals("Invalid XMLStreamWriter", eventWriter, TraxUtils.getXMLEventWriter(result));
+ Assert.assertEquals("Invalid XMLStreamWriter", eventWriter, TraxUtils.getXMLEventWriter(result));
}
+ @Test
public void testGetXMLEventWriterJaxp14() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new StringWriter());
StAXResult result = new StAXResult(eventWriter);
- assertEquals("Invalid XMLEventWriter", eventWriter, TraxUtils.getXMLEventWriter(result));
+ Assert.assertEquals("Invalid XMLEventWriter", eventWriter, TraxUtils.getXMLEventWriter(result));
}
+ @Test
public void testGetDocument() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
- assertSame("Invalid document", document, TraxUtils.getDocument(new DOMSource(document)));
+ Assert.assertSame("Invalid document", document, TraxUtils.getDocument(new DOMSource(document)));
Element element = document.createElement("element");
document.appendChild(element);
- assertSame("Invalid document", document, TraxUtils.getDocument(new DOMSource(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();
@@ -236,6 +259,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithDomResult() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
@@ -251,6 +275,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithSaxSource() throws Exception {
XMLReader reader = XMLReaderFactory.createXMLReader();
InputSource inputSource = new InputSource();
@@ -265,6 +290,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithSaxResult() throws Exception {
ContentHandler contentHandler = new DefaultHandler();
LexicalHandler lexicalHandler = new DefaultHandler2();
@@ -281,6 +307,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithStaxSourceEventReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(""));
@@ -295,6 +322,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithStaxResultEventWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new StringWriter());
@@ -309,6 +337,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithStaxSourceStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(""));
@@ -323,6 +352,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithStaxResultStreamWriter() throws Exception {
XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
@@ -337,6 +367,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithStreamSourceInputStream() throws Exception {
byte[] xml = "".getBytes("UTF-8");
InputStream inputStream = new ByteArrayInputStream(xml);
@@ -351,6 +382,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithStreamResultOutputStream() throws Exception {
OutputStream outputStream = new ByteArrayOutputStream();
@@ -364,6 +396,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithStreamSourceReader() throws Exception {
String xml = "";
Reader reader = new StringReader(xml);
@@ -378,6 +411,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithStreamResultWriter() throws Exception {
Writer writer = new StringWriter();
@@ -391,6 +425,7 @@ public class TraxUtilsTest extends XMLTestCase {
control.verify();
}
+ @Test
public void testDoWithInvalidSource() throws Exception {
Source source = new Source() {
@@ -404,13 +439,14 @@ public class TraxUtilsTest extends XMLTestCase {
try {
TraxUtils.doWithSource(source, null);
- fail("IllegalArgumentException expected");
+ Assert.fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException ex) {
// expected
}
}
+ @Test
public void testDoWithInvalidResult() throws Exception {
Result result = new Result() {
@@ -424,7 +460,7 @@ public class TraxUtilsTest extends XMLTestCase {
try {
TraxUtils.doWithResult(result, null);
- fail("IllegalArgumentException expected");
+ Assert.fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException ex) {
// expected
diff --git a/xml/src/test/java/org/springframework/xml/validation/AbstractValidatorFactoryTestCase.java b/xml/src/test/java/org/springframework/xml/validation/AbstractValidatorFactoryTestCase.java
index 4c72347c..d0fc84d4 100644
--- a/xml/src/test/java/org/springframework/xml/validation/AbstractValidatorFactoryTestCase.java
+++ b/xml/src/test/java/org/springframework/xml/validation/AbstractValidatorFactoryTestCase.java
@@ -24,6 +24,10 @@ import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.xml.transform.ResourceSource;
@@ -31,7 +35,7 @@ import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
-public abstract class AbstractValidatorFactoryTestCase extends TestCase {
+public abstract class AbstractValidatorFactoryTestCase {
private XmlValidator validator;
@@ -39,8 +43,8 @@ public abstract class AbstractValidatorFactoryTestCase extends TestCase {
private InputStream invalidInputStream;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
Resource[] schemaResource =
new Resource[]{new ClassPathResource("schema.xsd", AbstractValidatorFactoryTestCase.class)};
validator = createValidator(schemaResource, XmlValidatorFactory.SCHEMA_W3C_XML);
@@ -48,64 +52,72 @@ public abstract class AbstractValidatorFactoryTestCase extends TestCase {
invalidInputStream = AbstractValidatorFactoryTestCase.class.getResourceAsStream("invalidDocument.xml");
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
validInputStream.close();
invalidInputStream.close();
}
protected abstract XmlValidator createValidator(Resource[] schemaResources, String schemaLanguage) throws Exception;
+ @Test
public void testHandleValidMessageStream() throws Exception {
SAXParseException[] errors = validator.validate(new StreamSource(validInputStream));
- assertNotNull("Null returned for errors", errors);
- assertEquals("ValidationErrors returned", 0, errors.length);
+ 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 testHandleInvalidMessageStream() throws Exception {
SAXParseException[] errors = validator.validate(new StreamSource(invalidInputStream));
- assertNotNull("Null returned for errors", errors);
- assertEquals("ValidationErrors returned", 3, errors.length);
+ 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)));
- assertNotNull("Null returned for errors", errors);
- assertEquals("ValidationErrors returned", 0, errors.length);
+ 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)));
- assertNotNull("Null returned for errors", errors);
- assertEquals("ValidationErrors returned", 3, errors.length);
+ 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));
- assertNotNull("Null returned for errors", errors);
- assertEquals("ValidationErrors returned", 0, errors.length);
+ 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));
- assertNotNull("Null returned for errors", errors);
- assertEquals("ValidationErrors returned", 3, errors.length);
+ 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),
@@ -115,12 +127,12 @@ public abstract class AbstractValidatorFactoryTestCase extends TestCase {
Source document = new ResourceSource(
new ClassPathResource("multipleSchemas1.xml", AbstractValidatorFactoryTestCase.class));
SAXParseException[] errors = validator.validate(document);
- assertEquals("ValidationErrors returned", 0, errors.length);
+ 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);
- assertEquals("ValidationErrors returned", 0, errors.length);
+ Assert.assertEquals("ValidationErrors returned", 0, errors.length);
}
}
diff --git a/xml/src/test/java/org/springframework/xml/validation/SchemaLoaderUtilsTest.java b/xml/src/test/java/org/springframework/xml/validation/SchemaLoaderUtilsTest.java
index 1312524c..1d04903d 100644
--- a/xml/src/test/java/org/springframework/xml/validation/SchemaLoaderUtilsTest.java
+++ b/xml/src/test/java/org/springframework/xml/validation/SchemaLoaderUtilsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,46 +20,52 @@ import javax.xml.XMLConstants;
import javax.xml.validation.Schema;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
-public class SchemaLoaderUtilsTest extends TestCase {
+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);
- assertNotNull("No schema returned", schema);
- assertFalse("Resource not closed", resource.isOpen());
+ 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);
- fail("Should have thrown an IllegalArgumentException");
+ 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);
- fail("Should have thrown an IllegalArgumentException");
+ 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);
- assertNotNull("No schema returned", schema);
- assertFalse("Resource not closed", envelope.isOpen());
- assertFalse("Resource not closed", encoding.isOpen());
+ Assert.assertNotNull("No schema returned", schema);
+ Assert.assertFalse("Resource not closed", envelope.isOpen());
+ Assert.assertFalse("Resource not closed", encoding.isOpen());
}
}
\ No newline at end of file
diff --git a/xml/src/test/java/org/springframework/xml/validation/XmlValidatorFactoryTest.java b/xml/src/test/java/org/springframework/xml/validation/XmlValidatorFactoryTest.java
index 3903ddfa..99064b1a 100644
--- a/xml/src/test/java/org/springframework/xml/validation/XmlValidatorFactoryTest.java
+++ b/xml/src/test/java/org/springframework/xml/validation/XmlValidatorFactoryTest.java
@@ -24,34 +24,39 @@ import java.net.URL;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.AbstractResource;
-public class XmlValidatorFactoryTest extends TestCase {
+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);
- assertNotNull("No validator returned", validator);
+ Assert.assertNotNull("No validator returned", validator);
}
+ @Test
public void testNonExistentResource() throws Exception {
Resource resource = new NonExistentResource();
try {
XmlValidatorFactory.createValidator(resource, XmlValidatorFactory.SCHEMA_W3C_XML);
- fail("IllegalArgumentException expected");
+ 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");
- fail("IllegalArgumentException expected");
+ Assert.fail("IllegalArgumentException expected");
}
catch (IllegalArgumentException ex) {
// expected
diff --git a/xml/src/test/java/org/springframework/xml/xpath/AbstractXPathExpressionFactoryTestCase.java b/xml/src/test/java/org/springframework/xml/xpath/AbstractXPathExpressionFactoryTestCase.java
index e4517bb0..b32232f4 100644
--- a/xml/src/test/java/org/springframework/xml/xpath/AbstractXPathExpressionFactoryTestCase.java
+++ b/xml/src/test/java/org/springframework/xml/xpath/AbstractXPathExpressionFactoryTestCase.java
@@ -25,13 +25,16 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import org.springframework.util.StringUtils;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
-public abstract class AbstractXPathExpressionFactoryTestCase extends TestCase {
+public abstract class AbstractXPathExpressionFactoryTestCase {
private Document noNamespacesDocument;
@@ -39,8 +42,8 @@ public abstract class AbstractXPathExpressionFactoryTestCase extends TestCase {
private Map namespaces = new HashMap();
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
namespaces.put("prefix1", "namespace1");
namespaces.put("prefix2", "namespace2");
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
@@ -62,121 +65,140 @@ public abstract class AbstractXPathExpressionFactoryTestCase extends TestCase {
}
}
+ @Test
public void testEvaluateAsBooleanInvalidNamespaces() throws IOException, SAXException {
XPathExpression expression = createXPathExpression("/prefix1:root/prefix2:otherchild", namespaces);
boolean result = expression.evaluateAsBoolean(namespacesDocument);
- assertFalse("Invalid result [" + result + "]", result);
+ Assert.assertFalse("Invalid result [" + result + "]", result);
}
+ @Test
public void testEvaluateAsBooleanInvalidNoNamespaces() throws IOException, SAXException {
XPathExpression expression = createXPathExpression("/root/otherchild");
boolean result = expression.evaluateAsBoolean(noNamespacesDocument);
- assertFalse("Invalid result [" + result + "]", result);
+ 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);
- assertTrue("Invalid result", result);
+ Assert.assertTrue("Invalid result", result);
}
+ @Test
public void testEvaluateAsBooleanNoNamespaces() throws IOException, SAXException {
XPathExpression expression = createXPathExpression("/root/child/boolean/text()");
boolean result = expression.evaluateAsBoolean(noNamespacesDocument);
- assertTrue("Invalid result", result);
+ 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);
- assertTrue("Invalid result [" + result + "]", Double.isNaN(result));
+ 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);
- assertTrue("Invalid result [" + result + "]", Double.isNaN(result));
+ 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);
- assertEquals("Invalid result", 42D, result, 0D);
+ 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);
- assertEquals("Invalid result", 42D, result, 0D);
+ 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);
- assertNull("Invalid result [" + result + "]", result);
+ Assert.assertNull("Invalid result [" + result + "]", result);
}
+ @Test
public void testEvaluateAsNodeInvalidNoNamespaces() throws IOException, SAXException {
XPathExpression expression = createXPathExpression("/root/otherchild");
Node result = expression.evaluateAsNode(noNamespacesDocument);
- assertNull("Invalid result [" + result + "]", result);
+ 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);
- assertNotNull("Invalid result", result);
- assertEquals("Invalid localname", "child", result.getLocalName());
+ 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);
- assertNotNull("Invalid result", result);
- assertEquals("Invalid localname", "child", result.getLocalName());
+ 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 results = expression.evaluateAsNodeList(namespacesDocument);
- assertNotNull("Invalid result", results);
- assertEquals("Invalid amount of results", 3, results.size());
+ 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 results = expression.evaluateAsNodeList(noNamespacesDocument);
- assertNotNull("Invalid result", results);
- assertEquals("Invalid amount of results", 3, results.size());
+ 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);
- assertFalse("Invalid result [" + result + "]", StringUtils.hasText(result));
+ 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);
- assertFalse("Invalid result [" + result + "]", StringUtils.hasText(result));
+ 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);
- assertEquals("Invalid result", "text", result);
+ 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);
- assertEquals("Invalid result", "text", result);
+ Assert.assertEquals("Invalid result", "text", result);
}
+ @Test
public void testEvaluateAsObject() throws Exception {
XPathExpression expression = createXPathExpression("/root/child");
String result = expression.evaluateAsObject(noNamespacesDocument, new NodeMapper() {
@@ -184,10 +206,11 @@ public abstract class AbstractXPathExpressionFactoryTestCase extends TestCase {
return node.getLocalName();
}
});
- assertNotNull("Invalid result", result);
- assertEquals("Invalid localname", "child", result);
+ Assert.assertNotNull("Invalid result", result);
+ Assert.assertEquals("Invalid localname", "child", result);
}
+ @Test
public void testEvaluate() throws Exception {
XPathExpression expression = createXPathExpression("/root/child/*");
List results = expression.evaluate(noNamespacesDocument, new NodeMapper() {
@@ -195,17 +218,18 @@ public abstract class AbstractXPathExpressionFactoryTestCase extends TestCase {
return node.getLocalName();
}
});
- assertNotNull("Invalid result", results);
- assertEquals("Invalid amount of results", 3, results.size());
- assertEquals("Invalid first result", "text", results.get(0));
- assertEquals("Invalid first result", "number", results.get(1));
- assertEquals("Invalid first result", "boolean", results.get(2));
+ 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("\\");
- fail("No XPathParseException thrown");
+ Assert.fail("No XPathParseException thrown");
}
catch (XPathParseException ex) {
// Expected behaviour
diff --git a/xml/src/test/java/org/springframework/xml/xpath/AbstractXPathTemplateTestCase.java b/xml/src/test/java/org/springframework/xml/xpath/AbstractXPathTemplateTestCase.java
index efca7923..687cfc5e 100644
--- a/xml/src/test/java/org/springframework/xml/xpath/AbstractXPathTemplateTestCase.java
+++ b/xml/src/test/java/org/springframework/xml/xpath/AbstractXPathTemplateTestCase.java
@@ -27,6 +27,9 @@ import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.xml.sax.SaxUtils;
import org.springframework.xml.transform.ResourceSource;
@@ -35,7 +38,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
-public abstract class AbstractXPathTemplateTestCase extends TestCase {
+public abstract class AbstractXPathTemplateTestCase {
XPathOperations template;
@@ -43,8 +46,8 @@ public abstract class AbstractXPathTemplateTestCase extends TestCase {
private Source nonamespaces;
- @Override
- protected final void setUp() throws Exception {
+ @Before
+ public final void setUp() throws Exception {
template = createTemplate();
namespaces = new ResourceSource(new ClassPathResource("namespaces.xml", AbstractXPathTemplateTestCase.class));
nonamespaces =
@@ -53,60 +56,71 @@ public abstract class AbstractXPathTemplateTestCase extends TestCase {
protected abstract XPathOperations createTemplate() throws Exception;
+ @Test
public void testEvaluateAsBoolean() {
boolean result = template.evaluateAsBoolean("/root/child/boolean", nonamespaces);
- assertTrue("Invalid result", result);
+ Assert.assertTrue("Invalid result", result);
}
+ @Test
public void testEvaluateAsBooleanNamespaces() {
boolean result = template.evaluateAsBoolean("/prefix1:root/prefix2:child/prefix2:boolean", namespaces);
- assertTrue("Invalid result", result);
+ Assert.assertTrue("Invalid result", result);
}
+ @Test
public void testEvaluateAsDouble() {
double result = template.evaluateAsDouble("/root/child/number", nonamespaces);
- assertEquals("Invalid result", 42D, result, 0D);
+ Assert.assertEquals("Invalid result", 42D, result, 0D);
}
+ @Test
public void testEvaluateAsDoubleNamespaces() {
double result = template.evaluateAsDouble("/prefix1:root/prefix2:child/prefix2:number", namespaces);
- assertEquals("Invalid result", 42D, result, 0D);
+ Assert.assertEquals("Invalid result", 42D, result, 0D);
}
+ @Test
public void testEvaluateAsNode() {
Node result = template.evaluateAsNode("/root/child", nonamespaces);
- assertNotNull("Invalid result", result);
- assertEquals("Invalid localname", "child", result.getLocalName());
+ 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);
- assertNotNull("Invalid result", result);
- assertEquals("Invalid localname", "child", result.getLocalName());
+ Assert.assertNotNull("Invalid result", result);
+ Assert.assertEquals("Invalid localname", "child", result.getLocalName());
}
+ @Test
public void testEvaluateAsNodes() {
List results = template.evaluateAsNodeList("/root/child/*", nonamespaces);
- assertNotNull("Invalid result", results);
- assertEquals("Invalid amount of results", 3, results.size());
+ Assert.assertNotNull("Invalid result", results);
+ Assert.assertEquals("Invalid amount of results", 3, results.size());
}
+ @Test
public void testEvaluateAsNodesNamespaces() {
List results = template.evaluateAsNodeList("/prefix1:root/prefix2:child/*", namespaces);
- assertNotNull("Invalid result", results);
- assertEquals("Invalid amount of results", 3, results.size());
+ 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);
- assertEquals("Invalid result", "text", result);
+ Assert.assertEquals("Invalid result", "text", result);
}
+ @Test
public void testEvaluateAsString() throws IOException, SAXException {
String result = template.evaluateAsString("/root/child/text", nonamespaces);
- assertEquals("Invalid result", "text", result);
+ Assert.assertEquals("Invalid result", "text", result);
}
+ @Test
public void testEvaluateDomSource() throws IOException, SAXException, ParserConfigurationException {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
@@ -115,45 +129,49 @@ public abstract class AbstractXPathTemplateTestCase extends TestCase {
new ClassPathResource("nonamespaces.xml", AbstractXPathTemplateTestCase.class)));
String result = template.evaluateAsString("/root/child/text", new DOMSource(document));
- assertEquals("Invalid result", "text", result);
+ Assert.assertEquals("Invalid result", "text", result);
}
+ @Test
public void testEvaluateStreamSource() throws IOException, SAXException, ParserConfigurationException {
InputStream in = AbstractXPathTemplateTestCase.class.getResourceAsStream("nonamespaces.xml");
String result = template.evaluateAsString("/root/child/text", new StreamSource(in));
- assertEquals("Invalid result", "text", result);
+ Assert.assertEquals("Invalid result", "text", result);
}
+ @Test
public void testInvalidExpression() {
try {
template.evaluateAsBoolean("\\", namespaces);
- fail("No XPathException thrown");
+ Assert.fail("No XPathException thrown");
}
catch (XPathException ex) {
// Expected behaviour
}
}
+ @Test
public void testEvaluateAsObject() throws Exception {
String result = (String) template.evaluateAsObject("/root/child", nonamespaces, new NodeMapper() {
public String mapNode(Node node, int nodeNum) throws DOMException {
return node.getLocalName();
}
});
- assertNotNull("Invalid result", result);
- assertEquals("Invalid localname", "child", result);
+ Assert.assertNotNull("Invalid result", result);
+ Assert.assertEquals("Invalid localname", "child", result);
}
+ @Test
public void testEvaluate() throws Exception {
List results = template.evaluate("/root/child/*", nonamespaces, new NodeMapper() {
public String mapNode(Node node, int nodeNum) throws DOMException {
return node.getLocalName();
}
});
- assertNotNull("Invalid result", results);
- assertEquals("Invalid amount of results", 3, results.size());
- assertEquals("Invalid first result", "text", results.get(0));
- assertEquals("Invalid first result", "number", results.get(1));
- assertEquals("Invalid first result", "boolean", results.get(2));
+ 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));
}
}
diff --git a/xml/src/test/java/org/springframework/xml/xpath/JaxenXPathTemplateTest.java b/xml/src/test/java/org/springframework/xml/xpath/JaxenXPathTemplateTest.java
index 717b3490..6e419b02 100644
--- a/xml/src/test/java/org/springframework/xml/xpath/JaxenXPathTemplateTest.java
+++ b/xml/src/test/java/org/springframework/xml/xpath/JaxenXPathTemplateTest.java
@@ -18,7 +18,6 @@ package org.springframework.xml.xpath;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
public class JaxenXPathTemplateTest extends AbstractXPathTemplateTestCase {
diff --git a/xml/src/test/java/org/springframework/xml/xpath/XPathExpressionFactoryBeanTest.java b/xml/src/test/java/org/springframework/xml/xpath/XPathExpressionFactoryBeanTest.java
index b783298d..eaa2a43d 100644
--- a/xml/src/test/java/org/springframework/xml/xpath/XPathExpressionFactoryBeanTest.java
+++ b/xml/src/test/java/org/springframework/xml/xpath/XPathExpressionFactoryBeanTest.java
@@ -17,23 +17,27 @@
package org.springframework.xml.xpath;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-public class XPathExpressionFactoryBeanTest extends TestCase {
+public class XPathExpressionFactoryBeanTest {
private XPathExpressionFactoryBean factoryBean;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
factoryBean = new XPathExpressionFactoryBean();
}
+ @Test
public void testFactoryBean() throws Exception {
factoryBean.setExpression("/root");
factoryBean.afterPropertiesSet();
Object result = factoryBean.getObject();
- assertNotNull("No result obtained", result);
- assertTrue("No XPathExpression returned", result instanceof XPathExpression);
- assertTrue("Not a singleton", factoryBean.isSingleton());
- assertEquals("Not a XPathExpresison", XPathExpression.class, factoryBean.getObjectType());
+ 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());
}
}
\ No newline at end of file
diff --git a/xml/src/test/java/org/springframework/xml/xpath/XPathExpressionFactoryTest.java b/xml/src/test/java/org/springframework/xml/xpath/XPathExpressionFactoryTest.java
index f8bd51e7..ef56d1b8 100644
--- a/xml/src/test/java/org/springframework/xml/xpath/XPathExpressionFactoryTest.java
+++ b/xml/src/test/java/org/springframework/xml/xpath/XPathExpressionFactoryTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 the original author or authors.
+ * Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,18 +17,22 @@
package org.springframework.xml.xpath;
import junit.framework.TestCase;
+import org.junit.Assert;
+import org.junit.Test;
-public class XPathExpressionFactoryTest extends TestCase {
+public class XPathExpressionFactoryTest {
+ @Test
public void testCreateXPathExpression() throws Exception {
XPathExpression expression = XPathExpressionFactory.createXPathExpression("/root");
- assertNotNull("No expression returned", expression);
+ Assert.assertNotNull("No expression returned", expression);
}
+ @Test
public void testCreateEmptyXPathExpression() throws Exception {
try {
XPathExpressionFactory.createXPathExpression("");
- fail("Should have thrown an Exception");
+ Assert.fail("Should have thrown an Exception");
}
catch (IllegalArgumentException ex) {
// expected
diff --git a/xml/src/test/java/org/springframework/xml/xsd/AbstractXsdSchemaTestCase.java b/xml/src/test/java/org/springframework/xml/xsd/AbstractXsdSchemaTestCase.java
index 05571ce5..54205930 100644
--- a/xml/src/test/java/org/springframework/xml/xsd/AbstractXsdSchemaTestCase.java
+++ b/xml/src/test/java/org/springframework/xml/xsd/AbstractXsdSchemaTestCase.java
@@ -22,8 +22,12 @@ import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
+import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import org.w3c.dom.Document;
import org.springframework.core.io.ClassPathResource;
@@ -31,14 +35,16 @@ import org.springframework.core.io.Resource;
import org.springframework.xml.sax.SaxUtils;
import org.springframework.xml.validation.XmlValidator;
-public abstract class AbstractXsdSchemaTestCase extends XMLTestCase {
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
+
+public abstract class AbstractXsdSchemaTestCase {
private DocumentBuilder documentBuilder;
protected Transformer transformer;
- @Override
- protected final void setUp() throws Exception {
+ @Before
+ public final void setUp() throws Exception {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilder = documentBuilderFactory.newDocumentBuilder();
@@ -47,11 +53,12 @@ public abstract class AbstractXsdSchemaTestCase extends XMLTestCase {
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";
- assertEquals("Invalid target namespace", namespace, single.getTargetNamespace());
+ 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();
@@ -60,11 +67,12 @@ public abstract class AbstractXsdSchemaTestCase extends XMLTestCase {
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";
- assertEquals("Invalid target namespace", namespace, including.getTargetNamespace());
+ 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();
@@ -73,11 +81,12 @@ public abstract class AbstractXsdSchemaTestCase extends XMLTestCase {
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";
- assertEquals("Invalid target namespace", namespace, importing.getTargetNamespace());
+ 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();
@@ -86,11 +95,12 @@ public abstract class AbstractXsdSchemaTestCase extends XMLTestCase {
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";
- assertEquals("Invalid target namespace", namespace, importing.getTargetNamespace());
+ 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();
@@ -99,11 +109,12 @@ public abstract class AbstractXsdSchemaTestCase extends XMLTestCase {
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();
- assertNotNull("No XmlValidator returned", validator);
+ Assert.assertNotNull("No XmlValidator returned", validator);
}
protected abstract XsdSchema createSchema(Resource resource) throws Exception;
diff --git a/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollectionTest.java b/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollectionTest.java
index 324d38b5..d099f714 100644
--- a/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollectionTest.java
+++ b/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaCollectionTest.java
@@ -22,8 +22,10 @@ import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
-import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
import org.w3c.dom.Document;
import org.springframework.core.io.ClassPathResource;
@@ -33,7 +35,9 @@ import org.springframework.xml.validation.XmlValidator;
import org.springframework.xml.xsd.AbstractXsdSchemaTestCase;
import org.springframework.xml.xsd.XsdSchema;
-public class CommonsXsdSchemaCollectionTest extends XMLTestCase {
+import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
+
+public class CommonsXsdSchemaCollectionTest {
private CommonsXsdSchemaCollection collection;
@@ -41,8 +45,8 @@ public class CommonsXsdSchemaCollectionTest extends XMLTestCase {
private DocumentBuilder documentBuilder;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
collection = new CommonsXsdSchemaCollection();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformer = transformerFactory.newTransformer();
@@ -52,29 +56,31 @@ public class CommonsXsdSchemaCollectionTest extends XMLTestCase {
XMLUnit.setIgnoreWhitespace(true);
}
+ @Test
public void testSingle() throws Exception {
Resource resource = new ClassPathResource("single.xsd", AbstractXsdSchemaTestCase.class);
collection.setXsds(new Resource[]{resource});
collection.afterPropertiesSet();
- assertEquals("Invalid amount of XSDs loaded", 1, collection.getXsdSchemas().length);
+ 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();
- assertEquals("Invalid amount of XSDs loaded", 2, schemas.length);
+ Assert.assertEquals("Invalid amount of XSDs loaded", 2, schemas.length);
- assertEquals("Invalid target namespace", "urn:1", schemas[0].getTargetNamespace());
+ 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());
- assertEquals("Invalid target namespace", "urn:2", schemas[1].getTargetNamespace());
+ 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();
@@ -82,24 +88,27 @@ public class CommonsXsdSchemaCollectionTest extends XMLTestCase {
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();
- assertEquals("Invalid amount of XSDs loaded", 1, schemas.length);
+ 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();
- assertEquals("Invalid amount of XSDs loaded", 1, schemas.length);
+ 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});
@@ -107,21 +116,23 @@ public class CommonsXsdSchemaCollectionTest extends XMLTestCase {
collection.afterPropertiesSet();
XmlValidator validator = collection.createValidator();
- assertNotNull("No XmlValidator returned", validator);
+ 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();
- fail("CommonsXsdSchemaException expected");
+ 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});
@@ -129,16 +140,16 @@ public class CommonsXsdSchemaCollectionTest extends XMLTestCase {
collection.afterPropertiesSet();
XsdSchema[] schemas = collection.getXsdSchemas();
- assertEquals("Invalid amount of XSDs loaded", 2, schemas.length);
+ Assert.assertEquals("Invalid amount of XSDs loaded", 2, schemas.length);
- assertEquals("Invalid target namespace", "http://mycompany.com/hr/schemas", schemas[0].getTargetNamespace());
+ 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());
- assertEquals("Invalid target namespace", "http://mycompany.com/hr/schemas/holiday", schemas[1].getTargetNamespace());
+ 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();
diff --git a/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaTest.java b/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaTest.java
index bf0d4127..575f38a6 100644
--- a/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaTest.java
+++ b/xml/src/test/java/org/springframework/xml/xsd/commons/CommonsXsdSchemaTest.java
@@ -20,6 +20,7 @@ import javax.xml.transform.dom.DOMSource;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -29,6 +30,9 @@ import org.springframework.xml.sax.SaxUtils;
import org.springframework.xml.xsd.AbstractXsdSchemaTestCase;
import org.springframework.xml.xsd.XsdSchema;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
public class CommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
@Override
@@ -38,6 +42,7 @@ public class CommonsXsdSchemaTest extends AbstractXsdSchemaTestCase {
return new CommonsXsdSchema(schema);
}
+ @Test
public void testXmime() throws Exception {
Resource resource = new ClassPathResource("xmime.xsd", AbstractXsdSchemaTestCase.class);
XsdSchema schema = createSchema(resource);