Upgrading tests.
This commit is contained in:
@@ -38,14 +38,6 @@ import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
@@ -54,7 +46,18 @@ import org.springframework.xml.transform.StaxResult;
|
||||
import org.springframework.xml.transform.StaxSource;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
public abstract class AbstractWebServiceMessageTestCase extends XMLTestCase {
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public abstract class AbstractWebServiceMessageTestCase {
|
||||
|
||||
protected Transformer transformer;
|
||||
|
||||
@@ -68,8 +71,8 @@ public abstract class AbstractWebServiceMessageTestCase extends XMLTestCase {
|
||||
return expectedWriter.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
webServiceMessage = createWebServiceMessage();
|
||||
@@ -77,6 +80,7 @@ public abstract class AbstractWebServiceMessageTestCase extends XMLTestCase {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDomPayload() throws Exception {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
@@ -91,6 +95,8 @@ public abstract class AbstractWebServiceMessageTestCase extends XMLTestCase {
|
||||
validateMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("Since15")
|
||||
public void testEventReaderPayload() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLEventReader eventReader = inputFactory.createXMLEventReader(payload.getInputStream());
|
||||
@@ -106,6 +112,7 @@ public abstract class AbstractWebServiceMessageTestCase extends XMLTestCase {
|
||||
validateMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReaderPayload() throws Exception {
|
||||
Reader reader = new InputStreamReader(payload.getInputStream(), "UTF-8");
|
||||
StreamSource streamSource = new StreamSource(reader, payload.getURL().toString());
|
||||
@@ -116,6 +123,7 @@ public abstract class AbstractWebServiceMessageTestCase extends XMLTestCase {
|
||||
assertXMLEqual(getExpectedString(), resultWriter.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaxPayload() throws Exception {
|
||||
SAXSource saxSource = new SAXSource(SaxUtils.createInputSource(payload));
|
||||
transformer.transform(saxSource, webServiceMessage.getPayloadResult());
|
||||
@@ -125,6 +133,7 @@ public abstract class AbstractWebServiceMessageTestCase extends XMLTestCase {
|
||||
validateMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamPayload() throws Exception {
|
||||
StreamSource streamSource = new StreamSource(payload.getInputStream(), payload.getURL().toString());
|
||||
transformer.transform(streamSource, webServiceMessage.getPayloadResult());
|
||||
@@ -137,6 +146,8 @@ public abstract class AbstractWebServiceMessageTestCase extends XMLTestCase {
|
||||
validateMessage();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("Since15")
|
||||
public void testStreamReaderPayload() throws Exception {
|
||||
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
|
||||
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(payload.getInputStream());
|
||||
|
||||
@@ -25,6 +25,10 @@ import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.ws.AbstractWebServiceMessageTestCase;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractMimeMessageTestCase extends AbstractWebServiceMessageTestCase {
|
||||
|
||||
protected MimeMessage mimeMessage;
|
||||
@@ -46,16 +50,19 @@ public abstract class AbstractMimeMessageTestCase extends AbstractWebServiceMess
|
||||
|
||||
protected abstract MimeMessage createMimeMessage() throws Exception;
|
||||
|
||||
@Test
|
||||
public void testEmptyMessage() throws Exception {
|
||||
Iterator iterator = mimeMessage.getAttachments();
|
||||
Iterator<Attachment> iterator = mimeMessage.getAttachments();
|
||||
assertFalse("Empty MimeMessage has attachments", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAttachment() throws Exception {
|
||||
Attachment attachment = mimeMessage.addAttachment(contentId, picture, contentType);
|
||||
testAttachment(attachment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttachment() throws Exception {
|
||||
mimeMessage.addAttachment(contentId, picture, contentType);
|
||||
Attachment attachment = mimeMessage.getAttachment(contentId);
|
||||
@@ -63,9 +70,10 @@ public abstract class AbstractMimeMessageTestCase extends AbstractWebServiceMess
|
||||
testAttachment(attachment);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttachments() throws Exception {
|
||||
mimeMessage.addAttachment(contentId, picture, contentType);
|
||||
Iterator iterator = mimeMessage.getAttachments();
|
||||
Iterator<Attachment> iterator = mimeMessage.getAttachments();
|
||||
assertNotNull("Attachment iterator is null", iterator);
|
||||
assertTrue("Attachment iterator has no elements", iterator.hasNext());
|
||||
Attachment attachment = (Attachment) iterator.next();
|
||||
|
||||
@@ -21,8 +21,6 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.mime.AbstractMimeMessageTestCase;
|
||||
@@ -32,6 +30,11 @@ import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.xml.validation.XmlValidator;
|
||||
import org.springframework.xml.validation.XmlValidatorFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoapMessageTestCase extends AbstractMimeMessageTestCase {
|
||||
|
||||
protected SoapMessage soapMessage;
|
||||
@@ -44,6 +47,7 @@ public abstract class AbstractSoapMessageTestCase extends AbstractMimeMessageTes
|
||||
|
||||
protected abstract SoapMessage createSoapMessage() throws Exception;
|
||||
|
||||
@Test
|
||||
public void testValidate() throws Exception {
|
||||
XmlValidator validator =
|
||||
XmlValidatorFactory.createValidator(getSoapSchemas(), XmlValidatorFactory.SCHEMA_W3C_XML);
|
||||
@@ -53,17 +57,19 @@ public abstract class AbstractSoapMessageTestCase extends AbstractMimeMessageTes
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSoapAction() throws Exception {
|
||||
assertEquals("Invalid default SOAP Action", "\"\"", soapMessage.getSoapAction());
|
||||
soapMessage.setSoapAction("SoapAction");
|
||||
assertEquals("Invalid SOAP Action", "\"SoapAction\"", soapMessage.getSoapAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharsetAttribute() throws Exception {
|
||||
MockTransportOutputStream outputStream = new MockTransportOutputStream(new ByteArrayOutputStream());
|
||||
soapMessage.writeTo(outputStream);
|
||||
Map headers = outputStream.getHeaders();
|
||||
String contentType = (String) headers.get(TransportConstants.HEADER_CONTENT_TYPE);
|
||||
Map<String, String> headers = outputStream.getHeaders();
|
||||
String contentType = headers.get(TransportConstants.HEADER_CONTENT_TYPE);
|
||||
if (contentType != null) {
|
||||
Pattern charsetPattern = Pattern.compile("charset\\s*=\\s*([^;]+)");
|
||||
Matcher matcher = charsetPattern.matcher(contentType);
|
||||
@@ -76,9 +82,12 @@ public abstract class AbstractSoapMessageTestCase extends AbstractMimeMessageTes
|
||||
|
||||
protected abstract Resource[] getSoapSchemas();
|
||||
|
||||
@Test
|
||||
public abstract void testGetVersion() throws Exception;
|
||||
|
||||
@Test
|
||||
public abstract void testWriteToTransportOutputStream() throws Exception;
|
||||
|
||||
@Test
|
||||
public abstract void testWriteToTransportResponseAttachment() throws Exception;
|
||||
}
|
||||
|
||||
@@ -24,12 +24,15 @@ import org.apache.axiom.om.OMDocument;
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.OMFactory;
|
||||
import org.apache.axiom.om.OMNamespace;
|
||||
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;
|
||||
|
||||
public class AxiomHandlerTest extends XMLTestCase {
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class AxiomHandlerTest {
|
||||
|
||||
private static final String XML_1 =
|
||||
"<?xml version='1.0' encoding='UTF-8'?>" + "<?pi content?>" + "<root xmlns='namespace'>" +
|
||||
@@ -54,13 +57,14 @@ public class AxiomHandlerTest extends XMLTestCase {
|
||||
|
||||
private OMFactory factory;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
factory = OMAbstractFactory.getOMFactory();
|
||||
result = factory.createOMDocument();
|
||||
xmlReader = XMLReaderFactory.createXMLReader();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentHandlerDocumentNamespacePrefixes() throws Exception {
|
||||
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
|
||||
handler = new AxiomHandler(result, factory);
|
||||
@@ -72,6 +76,7 @@ public class AxiomHandlerTest extends XMLTestCase {
|
||||
assertXMLEqual("Invalid result", XML_1, bos.toString("UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentHandlerDocumentNoNamespacePrefixes() throws Exception {
|
||||
xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
|
||||
handler = new AxiomHandler(result, factory);
|
||||
@@ -82,6 +87,7 @@ public class AxiomHandlerTest extends XMLTestCase {
|
||||
assertXMLEqual("Invalid result", XML_1, bos.toString("UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentHandlerElement() throws Exception {
|
||||
OMNamespace namespace = factory.createOMNamespace("namespace", "");
|
||||
OMElement rootElement = factory.createOMElement("root", namespace, result);
|
||||
@@ -93,6 +99,7 @@ public class AxiomHandlerTest extends XMLTestCase {
|
||||
assertXMLEqual("Invalid result", XML_2_EXPECTED, bos.toString("UTF-8"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContentHandlerPredefinedEntityReference() throws Exception {
|
||||
handler = new AxiomHandler(result, factory);
|
||||
xmlReader.setContentHandler(handler);
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package org.springframework.ws.soap.axiom;
|
||||
|
||||
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
|
||||
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.soap11.AbstractSoap11MessageTestCase;
|
||||
|
||||
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class AxiomSoap11NonCachingMessageTest extends AbstractSoap11MessageTestCase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package org.springframework.ws.soap.axiom;
|
||||
|
||||
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
|
||||
|
||||
import org.springframework.ws.soap.SoapBody;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.soap12.AbstractSoap12MessageTestCase;
|
||||
|
||||
import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class AxiomSoap12NonCachingMessageTest extends AbstractSoap12MessageTestCase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,26 +19,31 @@ package org.springframework.ws.soap.axiom;
|
||||
import java.io.StringWriter;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
import org.springframework.xml.transform.StaxResult;
|
||||
|
||||
import org.apache.axiom.soap.SOAPBody;
|
||||
import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.xml.transform.StaxResult;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class NonCachingPayloadTest extends XMLTestCase {
|
||||
@SuppressWarnings("Since15")
|
||||
public class NonCachingPayloadTest {
|
||||
|
||||
private Payload payload;
|
||||
|
||||
private SOAPBody body;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public final void setUp() {
|
||||
SOAPFactory soapFactory = new SOAP11Factory();
|
||||
body = soapFactory.createSOAPBody();
|
||||
payload = new NonCachingPayload(body, soapFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelegatingStreamWriter() throws Exception {
|
||||
StaxResult result = (StaxResult) payload.getResult();
|
||||
XMLStreamWriter streamWriter = result.getXMLStreamWriter();
|
||||
@@ -62,6 +67,7 @@ public class NonCachingPayloadTest extends XMLTestCase {
|
||||
assertXMLEqual(expected, writer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelegatingStreamWriterWriteEndDocument() throws Exception {
|
||||
StaxResult result = (StaxResult) payload.getResult();
|
||||
XMLStreamWriter streamWriter = result.getXMLStreamWriter();
|
||||
@@ -84,6 +90,7 @@ public class NonCachingPayloadTest extends XMLTestCase {
|
||||
assertXMLEqual(expected, writer.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelegatingStreamWriterWriteEmptyElement() throws Exception {
|
||||
StaxResult result = (StaxResult) payload.getResult();
|
||||
XMLStreamWriter streamWriter = result.getXMLStreamWriter();
|
||||
|
||||
@@ -24,6 +24,11 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
import org.apache.axiom.om.OMElement;
|
||||
import org.apache.axiom.om.OMFactory;
|
||||
@@ -33,68 +38,75 @@ import org.apache.axiom.soap.SOAPEnvelope;
|
||||
import org.apache.axiom.soap.SOAPMessage;
|
||||
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
|
||||
import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
|
||||
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;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.xml.sax.SaxUtils;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class AxiomUtilsTest extends XMLTestCase {
|
||||
public class AxiomUtilsTest {
|
||||
|
||||
private OMElement element;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
OMFactory factory = OMAbstractFactory.getOMFactory();
|
||||
OMNamespace namespace = factory.createOMNamespace("http://www.springframework.org", "prefix");
|
||||
element = factory.createOMElement("element", namespace);
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToNamespaceDeclared() throws Exception {
|
||||
QName qName = new QName(element.getNamespace().getNamespaceURI(), "localPart");
|
||||
OMNamespace namespace = AxiomUtils.toNamespace(qName, element);
|
||||
assertNotNull("Invalid namespace", namespace);
|
||||
assertEquals("Invalid namespace", qName.getNamespaceURI(), namespace.getNamespaceURI());
|
||||
Assert.assertNotNull("Invalid namespace", namespace);
|
||||
Assert.assertEquals("Invalid namespace", qName.getNamespaceURI(), namespace.getNamespaceURI());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToNamespaceUndeclared() throws Exception {
|
||||
QName qName = new QName("http://www.example.com", "localPart");
|
||||
OMNamespace namespace = AxiomUtils.toNamespace(qName, element);
|
||||
assertNotNull("Invalid namespace", namespace);
|
||||
assertEquals("Invalid namespace", qName.getNamespaceURI(), namespace.getNamespaceURI());
|
||||
assertFalse("Invalid prefix", "prefix".equals(namespace.getPrefix()));
|
||||
Assert.assertNotNull("Invalid namespace", namespace);
|
||||
Assert.assertEquals("Invalid namespace", qName.getNamespaceURI(), namespace.getNamespaceURI());
|
||||
Assert.assertFalse("Invalid prefix", "prefix".equals(namespace.getPrefix()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToNamespacePrefixDeclared() throws Exception {
|
||||
QName qName = new QName(element.getNamespace().getNamespaceURI(), "localPart", "prefix");
|
||||
OMNamespace namespace = AxiomUtils.toNamespace(qName, element);
|
||||
assertNotNull("Invalid namespace", namespace);
|
||||
assertEquals("Invalid namespace", qName.getNamespaceURI(), namespace.getNamespaceURI());
|
||||
assertEquals("Invalid prefix", "prefix", namespace.getPrefix());
|
||||
Assert.assertNotNull("Invalid namespace", namespace);
|
||||
Assert.assertEquals("Invalid namespace", qName.getNamespaceURI(), namespace.getNamespaceURI());
|
||||
Assert.assertEquals("Invalid prefix", "prefix", namespace.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToNamespacePrefixUndeclared() throws Exception {
|
||||
QName qName = new QName("http://www.example.com", "localPart", "otherPrefix");
|
||||
OMNamespace namespace = AxiomUtils.toNamespace(qName, element);
|
||||
assertNotNull("Invalid namespace", namespace);
|
||||
assertEquals("Invalid namespace", qName.getNamespaceURI(), namespace.getNamespaceURI());
|
||||
assertEquals("Invalid prefix", qName.getPrefix(), namespace.getPrefix());
|
||||
Assert.assertNotNull("Invalid namespace", namespace);
|
||||
Assert.assertEquals("Invalid namespace", qName.getNamespaceURI(), namespace.getNamespaceURI());
|
||||
Assert.assertEquals("Invalid prefix", qName.getPrefix(), namespace.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToLanguage() throws Exception {
|
||||
assertEquals("Invalid conversion", "fr-CA", AxiomUtils.toLanguage(Locale.CANADA_FRENCH));
|
||||
assertEquals("Invalid conversion", "en", AxiomUtils.toLanguage(Locale.ENGLISH));
|
||||
Assert.assertEquals("Invalid conversion", "fr-CA", AxiomUtils.toLanguage(Locale.CANADA_FRENCH));
|
||||
Assert.assertEquals("Invalid conversion", "en", AxiomUtils.toLanguage(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToLocale() throws Exception {
|
||||
assertEquals("Invalid conversion", Locale.CANADA_FRENCH, AxiomUtils.toLocale("fr-CA"));
|
||||
assertEquals("Invalid conversion", Locale.ENGLISH, AxiomUtils.toLocale("en"));
|
||||
Assert.assertEquals("Invalid conversion", Locale.CANADA_FRENCH, AxiomUtils.toLocale("fr-CA"));
|
||||
Assert.assertEquals("Invalid conversion", Locale.ENGLISH, AxiomUtils.toLocale("en"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("Since15")
|
||||
public void testToDocument() throws Exception {
|
||||
Resource resource = new ClassPathResource("org/springframework/ws/soap/soap11/soap11.xml");
|
||||
|
||||
@@ -114,6 +126,7 @@ public class AxiomUtilsTest extends XMLTestCase {
|
||||
assertXMLEqual("Invalid document generated from SOAPEnvelope", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToEnvelope() throws Exception {
|
||||
Resource resource = new ClassPathResource("org/springframework/ws/soap/soap11/soap11.xml");
|
||||
|
||||
|
||||
@@ -37,12 +37,17 @@ import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
public abstract class AbstractSaajImplementationTestCase extends XMLTestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public abstract class AbstractSaajImplementationTestCase {
|
||||
|
||||
private SaajImplementation implementation;
|
||||
|
||||
@@ -54,8 +59,8 @@ public abstract class AbstractSaajImplementationTestCase extends XMLTestCase {
|
||||
|
||||
private SOAPHeader header;
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
implementation = createSaajImplementation();
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
message = messageFactory.createMessage();
|
||||
@@ -66,70 +71,80 @@ public abstract class AbstractSaajImplementationTestCase extends XMLTestCase {
|
||||
|
||||
protected abstract SaajImplementation createSaajImplementation();
|
||||
|
||||
@Test
|
||||
public void testGetName() throws Exception {
|
||||
QName name = implementation.getName(message.getSOAPPart().getEnvelope());
|
||||
assertEquals("Invalid name", SoapVersion.SOAP_11.getEnvelopeName(), name);
|
||||
Assert.assertEquals("Invalid name", SoapVersion.SOAP_11.getEnvelopeName(), name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSource() throws Exception {
|
||||
Source source = implementation.getSource(message.getSOAPPart().getEnvelope().getBody());
|
||||
assertNotNull("No source returned", source);
|
||||
Assert.assertNotNull("No source returned", source);
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
StringResult result = new StringResult();
|
||||
transformer.transform(source, result);
|
||||
assertXMLEqual("<Body xmlns='http://schemas.xmlsoap.org/soap/envelope/'/>", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetResult() throws Exception {
|
||||
Source source = new StringSource("<content xmlns='http://springframework.org/spring-ws'/>");
|
||||
Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer.transform(source, implementation.getResult(message.getSOAPPart().getEnvelope().getBody()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEnvelope() throws Exception {
|
||||
SOAPEnvelope envelope = implementation.getEnvelope(message);
|
||||
assertEquals("Invalid envelope", message.getSOAPPart().getEnvelope(), envelope);
|
||||
Assert.assertEquals("Invalid envelope", message.getSOAPPart().getEnvelope(), envelope);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetHeader() throws Exception {
|
||||
SOAPHeader header = implementation.getHeader(message.getSOAPPart().getEnvelope());
|
||||
assertEquals("Invalid header", message.getSOAPPart().getEnvelope().getHeader(), header);
|
||||
Assert.assertEquals("Invalid header", message.getSOAPPart().getEnvelope().getHeader(), header);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBody() throws Exception {
|
||||
SOAPBody body = implementation.getBody(message.getSOAPPart().getEnvelope());
|
||||
assertEquals("Invalid body", message.getSOAPPart().getEnvelope().getBody(), body);
|
||||
Assert.assertEquals("Invalid body", message.getSOAPPart().getEnvelope().getBody(), body);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExampleAllHeaderElements() throws Exception {
|
||||
Iterator iterator = implementation.examineAllHeaderElements(header);
|
||||
assertFalse("Header elements present", iterator.hasNext());
|
||||
Iterator<SOAPHeaderElement> iterator = implementation.examineAllHeaderElements(header);
|
||||
Assert.assertFalse("Header elements present", iterator.hasNext());
|
||||
createHeaderElement();
|
||||
iterator = implementation.examineAllHeaderElements(header);
|
||||
assertTrue("No header elements present", iterator.hasNext());
|
||||
Assert.assertTrue("No header elements present", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExampleMustUnderstandHeaderElements() throws Exception {
|
||||
SOAPHeaderElement headerElement = createHeaderElement();
|
||||
headerElement.setMustUnderstand(true);
|
||||
Iterator iterator = implementation.examineAllHeaderElements(header);
|
||||
assertTrue("No header elements present", iterator.hasNext());
|
||||
Iterator<SOAPHeaderElement> iterator = implementation.examineAllHeaderElements(header);
|
||||
Assert.assertTrue("No header elements present", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddHeaderElement() throws Exception {
|
||||
SOAPHeaderElement headerElement = implementation
|
||||
.addHeaderElement(header, new QName("http://springframework.org/spring-ws", "Header"));
|
||||
assertNotNull("No header element returned", headerElement);
|
||||
assertEquals("Invalid namespace", "http://springframework.org/spring-ws",
|
||||
Assert.assertNotNull("No header element returned", headerElement);
|
||||
Assert.assertEquals("Invalid namespace", "http://springframework.org/spring-ws",
|
||||
headerElement.getElementName().getURI());
|
||||
assertEquals("Invalid local name", "Header", headerElement.getElementName().getLocalName());
|
||||
Assert.assertEquals("Invalid local name", "Header", headerElement.getElementName().getLocalName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetActorOrRole() throws Exception {
|
||||
SOAPHeaderElement headerElement = createHeaderElement();
|
||||
String actor = "http://springframework.org/spring-ws/Actor";
|
||||
headerElement.setActor(actor);
|
||||
assertEquals("Invalid actor", actor, implementation.getActorOrRole(headerElement));
|
||||
Assert.assertEquals("Invalid actor", actor, implementation.getActorOrRole(headerElement));
|
||||
}
|
||||
|
||||
private SOAPHeaderElement createHeaderElement() throws SOAPException {
|
||||
@@ -137,46 +152,53 @@ public abstract class AbstractSaajImplementationTestCase extends XMLTestCase {
|
||||
return header.addHeaderElement(name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetActorOrRole() throws Exception {
|
||||
SOAPHeaderElement headerElement = createHeaderElement();
|
||||
String actor = "http://springframework.org/spring-ws/Actor";
|
||||
implementation.setActorOrRole(headerElement, actor);
|
||||
assertEquals("Invalid actor", headerElement.getActor(), actor);
|
||||
Assert.assertEquals("Invalid actor", headerElement.getActor(), actor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMustUnderstand() throws Exception {
|
||||
SOAPHeaderElement headerElement = createHeaderElement();
|
||||
headerElement.setMustUnderstand(true);
|
||||
assertTrue("Invalid mustUnderstand", implementation.getMustUnderstand(headerElement));
|
||||
Assert.assertTrue("Invalid mustUnderstand", implementation.getMustUnderstand(headerElement));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetMustUnderstand() throws Exception {
|
||||
SOAPHeaderElement headerElement = createHeaderElement();
|
||||
implementation.setMustUnderstand(headerElement, true);
|
||||
assertTrue("Invalid mustUnderstand", headerElement.getMustUnderstand());
|
||||
Assert.assertTrue("Invalid mustUnderstand", headerElement.getMustUnderstand());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasFault() throws Exception {
|
||||
assertFalse("Body has fault", implementation.hasFault(body));
|
||||
Assert.assertFalse("Body has fault", implementation.hasFault(body));
|
||||
body.addFault();
|
||||
assertTrue("Body has no fault", implementation.hasFault(body));
|
||||
Assert.assertTrue("Body has no fault", implementation.hasFault(body));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFault() throws Exception {
|
||||
assertNull("Body has fault", implementation.getFault(body));
|
||||
Assert.assertNull("Body has fault", implementation.getFault(body));
|
||||
body.addFault();
|
||||
assertNotNull("Body has no fault", implementation.getFault(body));
|
||||
Assert.assertNotNull("Body has no fault", implementation.getFault(body));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFault() throws Exception {
|
||||
implementation
|
||||
.addFault(body, new QName("http://springframework.org/spring-ws", "Fault"), "Fault", Locale.ENGLISH);
|
||||
assertTrue("No Fault added", body.hasFault());
|
||||
Assert.assertTrue("No Fault added", body.hasFault());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFaultCode() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
assertEquals("Invalid fault code", new QName("http://springframework.org/spring-ws", "Fault"),
|
||||
Assert.assertEquals("Invalid fault code", new QName("http://springframework.org/spring-ws", "Fault"),
|
||||
implementation.getFaultCode(fault));
|
||||
}
|
||||
|
||||
@@ -184,106 +206,119 @@ public abstract class AbstractSaajImplementationTestCase extends XMLTestCase {
|
||||
return body.addFault(new QName("http://springframework.org/spring-ws", "Fault"), "Fault", Locale.ENGLISH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFaultActor() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
String actor = "http://springframework.org/spring-ws/Actor";
|
||||
fault.setFaultActor(actor);
|
||||
assertEquals("Invalid actor", actor, implementation.getFaultActor(fault));
|
||||
Assert.assertEquals("Invalid actor", actor, implementation.getFaultActor(fault));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetFaultActor() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
String actor = "http://springframework.org/spring-ws/Actor";
|
||||
implementation.setFaultActor(fault, actor);
|
||||
assertEquals("Invalid actor", actor, fault.getFaultActor());
|
||||
Assert.assertEquals("Invalid actor", actor, fault.getFaultActor());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFaultString() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
String faultString = "FaultString";
|
||||
fault.setFaultString(faultString);
|
||||
assertEquals("Invalid fault string", faultString, implementation.getFaultString(fault));
|
||||
Assert.assertEquals("Invalid fault string", faultString, implementation.getFaultString(fault));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFaultStringLocale() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
assertEquals("Invalid fault string", Locale.ENGLISH, implementation.getFaultStringLocale(fault));
|
||||
Assert.assertEquals("Invalid fault string", Locale.ENGLISH, implementation.getFaultStringLocale(fault));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFaultDetail() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
assertNull("Fault Detail returned", implementation.getFaultDetail(fault));
|
||||
Assert.assertNull("Fault Detail returned", implementation.getFaultDetail(fault));
|
||||
fault.addDetail();
|
||||
assertNotNull("No Fault Detail returned", implementation.getFaultDetail(fault));
|
||||
Assert.assertNotNull("No Fault Detail returned", implementation.getFaultDetail(fault));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFaultDetail() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
Detail detail = implementation.addFaultDetail(fault);
|
||||
assertEquals("Invalid fault detail", fault.getDetail(), detail);
|
||||
Assert.assertEquals("Invalid fault detail", fault.getDetail(), detail);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddDetailEntry() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
Detail detail = fault.addDetail();
|
||||
DetailEntry detailEntry =
|
||||
implementation.addDetailEntry(detail, new QName("http://springframework.org/spring-ws", "DetailEntry"));
|
||||
assertNotNull("No detail entry", detailEntry);
|
||||
Iterator iterator = detail.getDetailEntries();
|
||||
assertTrue("No detail entried", iterator.hasNext());
|
||||
assertEquals("Invalid detail entry", detailEntry, iterator.next());
|
||||
Assert.assertNotNull("No detail entry", detailEntry);
|
||||
Iterator<?> iterator = detail.getDetailEntries();
|
||||
Assert.assertTrue("No detail entry", iterator.hasNext());
|
||||
Assert.assertEquals("Invalid detail entry", detailEntry, iterator.next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddTextNode() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
Detail detail = fault.addDetail();
|
||||
Name name = envelope.createName("DetailEntry", "", "http://springframework.org/spring-ws");
|
||||
DetailEntry detailEntry = detail.addDetailEntry(name);
|
||||
implementation.addTextNode(detailEntry, "text");
|
||||
assertEquals("Invalid text", "text", detailEntry.getValue());
|
||||
Assert.assertEquals("Invalid text", "text", detailEntry.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDetailEntries() throws Exception {
|
||||
SOAPFault fault = createFault();
|
||||
Detail detail = fault.addDetail();
|
||||
Iterator iterator = implementation.getDetailEntries(detail);
|
||||
assertFalse("Detail entries found", iterator.hasNext());
|
||||
Iterator<DetailEntry> iterator = implementation.getDetailEntries(detail);
|
||||
Assert.assertFalse("Detail entries found", iterator.hasNext());
|
||||
Name name = envelope.createName("DetailEntry", "", "http://springframework.org/spring-ws");
|
||||
DetailEntry detailEntry = detail.addDetailEntry(name);
|
||||
iterator = implementation.getDetailEntries(detail);
|
||||
assertTrue("No detail entries found", iterator.hasNext());
|
||||
assertEquals("Invalid detail entry found", detailEntry, iterator.next());
|
||||
assertFalse("Detail entries found", iterator.hasNext());
|
||||
Assert.assertTrue("No detail entries found", iterator.hasNext());
|
||||
Assert.assertEquals("Invalid detail entry found", detailEntry, iterator.next());
|
||||
Assert.assertFalse("Detail entries found", iterator.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteTo() throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
implementation.writeTo(message, os);
|
||||
assertTrue("Nothing written", os.toByteArray().length > 0);
|
||||
Assert.assertTrue("Nothing written", os.toByteArray().length > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAttachments() throws Exception {
|
||||
Iterator iterator = implementation.getAttachments(message);
|
||||
assertFalse("Message has attachments", iterator.hasNext());
|
||||
Iterator<AttachmentPart> iterator = implementation.getAttachments(message);
|
||||
Assert.assertFalse("Message has attachments", iterator.hasNext());
|
||||
AttachmentPart attachmentPart = message.createAttachmentPart();
|
||||
message.addAttachmentPart(attachmentPart);
|
||||
iterator = implementation.getAttachments(message);
|
||||
assertTrue("Message has no attachments", iterator.hasNext());
|
||||
assertEquals("Invalid attachment part", attachmentPart, iterator.next());
|
||||
Assert.assertTrue("Message has no attachments", iterator.hasNext());
|
||||
Assert.assertEquals("Invalid attachment part", attachmentPart, iterator.next());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAttachmentPart() throws Exception {
|
||||
DataHandler dataHandler = new DataHandler("data", "text/plain");
|
||||
AttachmentPart attachmentPart = implementation.addAttachmentPart(message, dataHandler);
|
||||
assertNotNull("No attachment part", attachmentPart);
|
||||
Assert.assertNotNull("No attachment part", attachmentPart);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveContents() throws Exception {
|
||||
body.addBodyElement(new QName("foo", "bar"));
|
||||
|
||||
assertTrue("Body has child nodes", body.hasChildNodes());
|
||||
Assert.assertTrue("Body has child nodes", body.hasChildNodes());
|
||||
implementation.removeContents(message.getSOAPBody());
|
||||
assertFalse("Body has child nodes", body.hasChildNodes());
|
||||
Assert.assertFalse("Body has child nodes", body.hasChildNodes());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,6 +30,12 @@ import org.springframework.ws.soap.soap11.AbstractSoap11MessageTestCase;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SaajSoap11MessageTest extends AbstractSoap11MessageTestCase {
|
||||
|
||||
private SOAPMessage saajMessage;
|
||||
@@ -42,6 +48,7 @@ public class SaajSoap11MessageTest extends AbstractSoap11MessageTestCase {
|
||||
return new SaajSoapMessage(saajMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPayloadSource() throws Exception {
|
||||
saajMessage.getSOAPPart().getEnvelope().getBody().addChildElement("child");
|
||||
Source source = soapMessage.getPayloadSource();
|
||||
@@ -50,6 +57,7 @@ public class SaajSoap11MessageTest extends AbstractSoap11MessageTestCase {
|
||||
assertXMLEqual("Invalid source", "<child/>", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPayloadSourceText() throws Exception {
|
||||
SOAPBody body = saajMessage.getSOAPPart().getEnvelope().getBody();
|
||||
body.addTextNode(" ");
|
||||
@@ -60,12 +68,13 @@ public class SaajSoap11MessageTest extends AbstractSoap11MessageTestCase {
|
||||
assertXMLEqual("Invalid source", "<child/>", result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPayloadResult() throws Exception {
|
||||
StringSource source = new StringSource("<child/>");
|
||||
Result result = soapMessage.getPayloadResult();
|
||||
transformer.transform(source, result);
|
||||
SOAPBody body = saajMessage.getSOAPPart().getEnvelope().getBody();
|
||||
Iterator iterator = body.getChildElements();
|
||||
Iterator<?> iterator = body.getChildElements();
|
||||
assertTrue("No child nodes created", iterator.hasNext());
|
||||
SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next();
|
||||
assertEquals("Invalid child node created", "child", bodyElement.getElementName().getLocalName());
|
||||
|
||||
@@ -27,6 +27,10 @@ import org.springframework.ws.soap.soap12.AbstractSoap12MessageTestCase;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class SaajSoap12MessageTest extends AbstractSoap12MessageTestCase {
|
||||
|
||||
private SOAPMessage saajMessage;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.ws.soap.saaj.support;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
@@ -27,87 +26,98 @@ import javax.xml.soap.Name;
|
||||
import javax.xml.soap.SOAPEnvelope;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessageException;
|
||||
|
||||
public class SaajUtilsTest extends XMLTestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class SaajUtilsTest {
|
||||
|
||||
private MessageFactory messageFactory;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
messageFactory = MessageFactory.newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToName() throws Exception {
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
QName qName = new QName("localPart");
|
||||
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
|
||||
Name name = SaajUtils.toName(qName, envelope);
|
||||
assertNotNull("Invalid name", name);
|
||||
assertEquals("Invalid local part", qName.getLocalPart(), name.getLocalName());
|
||||
assertFalse("Invalid prefix", StringUtils.hasLength(name.getPrefix()));
|
||||
assertFalse("Invalid namespace", StringUtils.hasLength(name.getURI()));
|
||||
Assert.assertNotNull("Invalid name", name);
|
||||
Assert.assertEquals("Invalid local part", qName.getLocalPart(), name.getLocalName());
|
||||
Assert.assertFalse("Invalid prefix", StringUtils.hasLength(name.getPrefix()));
|
||||
Assert.assertFalse("Invalid namespace", StringUtils.hasLength(name.getURI()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToNameNamespace() throws Exception {
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
QName qName = new QName("namespace", "localPart");
|
||||
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
|
||||
envelope.addNamespaceDeclaration("prefix", "namespace");
|
||||
Name name = SaajUtils.toName(qName, envelope);
|
||||
assertNotNull("Invalid name", name);
|
||||
assertEquals("Invalid namespace", qName.getNamespaceURI(), name.getURI());
|
||||
assertEquals("Invalid local part", qName.getLocalPart(), name.getLocalName());
|
||||
assertEquals("Invalid prefix", "prefix", name.getPrefix());
|
||||
Assert.assertNotNull("Invalid name", name);
|
||||
Assert.assertEquals("Invalid namespace", qName.getNamespaceURI(), name.getURI());
|
||||
Assert.assertEquals("Invalid local part", qName.getLocalPart(), name.getLocalName());
|
||||
Assert.assertEquals("Invalid prefix", "prefix", name.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToNameNamespacePrefix() throws Exception {
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
QName qName = new QName("namespace", "localPart", "prefix");
|
||||
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
|
||||
Name name = SaajUtils.toName(qName, envelope);
|
||||
assertNotNull("Invalid name", name);
|
||||
assertEquals("Invalid namespace", qName.getNamespaceURI(), name.getURI());
|
||||
assertEquals("Invalid local part", qName.getLocalPart(), name.getLocalName());
|
||||
assertEquals("Invalid prefix", qName.getPrefix(), name.getPrefix());
|
||||
Assert.assertNotNull("Invalid name", name);
|
||||
Assert.assertEquals("Invalid namespace", qName.getNamespaceURI(), name.getURI());
|
||||
Assert.assertEquals("Invalid local part", qName.getLocalPart(), name.getLocalName());
|
||||
Assert.assertEquals("Invalid prefix", qName.getPrefix(), name.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToQName() throws Exception {
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
Name name = message.getSOAPPart().getEnvelope().createName("localPart", null, null);
|
||||
QName qName = SaajUtils.toQName(name);
|
||||
assertNotNull("Invalid qName", qName);
|
||||
assertEquals("Invalid namespace", name.getURI(), qName.getNamespaceURI());
|
||||
assertFalse("Invalid prefix", StringUtils.hasLength(qName.getPrefix()));
|
||||
assertFalse("Invalid namespace", StringUtils.hasLength(qName.getNamespaceURI()));
|
||||
Assert.assertNotNull("Invalid qName", qName);
|
||||
Assert.assertEquals("Invalid namespace", name.getURI(), qName.getNamespaceURI());
|
||||
Assert.assertFalse("Invalid prefix", StringUtils.hasLength(qName.getPrefix()));
|
||||
Assert.assertFalse("Invalid namespace", StringUtils.hasLength(qName.getNamespaceURI()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToQNameNamespace() throws Exception {
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
Name name = message.getSOAPPart().getEnvelope().createName("localPart", null, "namespace");
|
||||
QName qName = SaajUtils.toQName(name);
|
||||
assertNotNull("Invalid qName", qName);
|
||||
assertEquals("Invalid namespace", name.getURI(), qName.getNamespaceURI());
|
||||
assertEquals("Invalid local part", name.getLocalName(), qName.getLocalPart());
|
||||
assertFalse("Invalid prefix", StringUtils.hasLength(qName.getPrefix()));
|
||||
Assert.assertNotNull("Invalid qName", qName);
|
||||
Assert.assertEquals("Invalid namespace", name.getURI(), qName.getNamespaceURI());
|
||||
Assert.assertEquals("Invalid local part", name.getLocalName(), qName.getLocalPart());
|
||||
Assert.assertFalse("Invalid prefix", StringUtils.hasLength(qName.getPrefix()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToQNamePrefixNamespace() throws Exception {
|
||||
SOAPMessage message = messageFactory.createMessage();
|
||||
Name name = message.getSOAPPart().getEnvelope().createName("localPart", "prefix", "namespace");
|
||||
QName qName = SaajUtils.toQName(name);
|
||||
assertNotNull("Invalid qName", qName);
|
||||
assertEquals("Invalid namespace", name.getURI(), qName.getNamespaceURI());
|
||||
assertEquals("Invalid local part", name.getLocalName(), qName.getLocalPart());
|
||||
assertEquals("Invalid prefix", name.getPrefix(), qName.getPrefix());
|
||||
Assert.assertNotNull("Invalid qName", qName);
|
||||
Assert.assertEquals("Invalid namespace", name.getURI(), qName.getNamespaceURI());
|
||||
Assert.assertEquals("Invalid local part", name.getLocalName(), qName.getLocalPart());
|
||||
Assert.assertEquals("Invalid prefix", name.getPrefix(), qName.getPrefix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadMessage() throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
@@ -118,10 +128,12 @@ public class SaajUtilsTest extends XMLTestCase {
|
||||
assertXMLEqual(soapMessage.getSOAPPart(), document);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSaajVersion() throws Exception {
|
||||
assertEquals("Invalid SAAJ version", SaajUtils.SAAJ_13, SaajUtils.getSaajVersion());
|
||||
Assert.assertEquals("Invalid SAAJ version", SaajUtils.SAAJ_13, SaajUtils.getSaajVersion());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSaajVersionInvalidEnvelope() throws Exception {
|
||||
Resource resource = new ClassPathResource("invalidNamespaceReferenceSoapMessage.xml", getClass());
|
||||
InputStream in = null;
|
||||
@@ -130,7 +142,8 @@ public class SaajUtilsTest extends XMLTestCase {
|
||||
MimeHeaders headers = new MimeHeaders();
|
||||
SOAPMessage soapMessage = messageFactory.createMessage(headers, in);
|
||||
SaajUtils.getSaajVersion(soapMessage);
|
||||
fail("Should have thrown SaajSoapMessageException as message envelope is invalid and cannot be accessed.");
|
||||
Assert.fail(
|
||||
"Should have thrown SaajSoapMessageException as message envelope is invalid and cannot be accessed.");
|
||||
}
|
||||
catch (SaajSoapMessageException e) {
|
||||
// expected
|
||||
|
||||
@@ -26,11 +26,14 @@ import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
public class SaajXmlReaderTest extends XMLTestCase {
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class SaajXmlReaderTest {
|
||||
|
||||
private SaajXmlReader saajReader;
|
||||
|
||||
@@ -38,8 +41,8 @@ public class SaajXmlReaderTest extends XMLTestCase {
|
||||
|
||||
private Transformer transformer;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
message = messageFactory.createMessage();
|
||||
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
|
||||
@@ -47,6 +50,7 @@ public class SaajXmlReaderTest extends XMLTestCase {
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamespacesPrefixes() throws Exception {
|
||||
saajReader.setFeature("http://xml.org/sax/features/namespaces", true);
|
||||
saajReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
|
||||
@@ -58,6 +62,7 @@ public class SaajXmlReaderTest extends XMLTestCase {
|
||||
assertXMLEqual((Document) expected.getNode(), (Document) result.getNode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamespacesNoPrefixes() throws Exception {
|
||||
saajReader.setFeature("http://xml.org/sax/features/namespaces", true);
|
||||
saajReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
|
||||
|
||||
@@ -23,7 +23,6 @@ import javax.xml.soap.MessageFactory;
|
||||
import javax.xml.soap.SOAPConstants;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.springframework.ws.context.DefaultMessageContext;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
@@ -35,23 +34,29 @@ import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.ws.soap.soap11.Soap11Fault;
|
||||
import org.springframework.ws.soap.soap12.Soap12Fault;
|
||||
|
||||
public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class SoapFaultMappingExceptionResolverTest {
|
||||
|
||||
private SoapFaultMappingExceptionResolver resolver;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
resolver = new SoapFaultMappingExceptionResolver();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDepth() throws Exception {
|
||||
assertEquals("Invalid depth for Exception", 0, resolver.getDepth("java.lang.Exception", new Exception()));
|
||||
assertEquals("Invalid depth for IllegalArgumentException", 2,
|
||||
Assert.assertEquals("Invalid depth for Exception", 0, resolver.getDepth("java.lang.Exception", new Exception()));
|
||||
Assert.assertEquals("Invalid depth for IllegalArgumentException", 2,
|
||||
resolver.getDepth("java.lang.Exception", new IllegalArgumentException()));
|
||||
assertEquals("Invalid depth for IllegalStateException", -1,
|
||||
Assert.assertEquals("Invalid depth for IllegalStateException", -1,
|
||||
resolver.getDepth("IllegalArgumentException", new IllegalStateException()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionClientSoap11() throws Exception {
|
||||
Properties mappings = new Properties();
|
||||
mappings.setProperty(Exception.class.getName(), "SERVER, Server error");
|
||||
@@ -64,17 +69,18 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Client error", fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Client error", fault.getFaultStringOrReason());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionSenderSoap12() throws Exception {
|
||||
Properties mappings = new Properties();
|
||||
mappings.setProperty(Exception.class.getName(), "RECEIVER, Receiver error, en");
|
||||
@@ -87,17 +93,18 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Sender error", fault.getFaultReasonText(Locale.ENGLISH));
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Sender error", fault.getFaultReasonText(Locale.ENGLISH));
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionServerSoap11() throws Exception {
|
||||
Properties mappings = new Properties();
|
||||
mappings.setProperty(Exception.class.getName(), "CLIENT, Client error");
|
||||
@@ -110,17 +117,18 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Server error", fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Server error", fault.getFaultStringOrReason());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionReceiverSoap12() throws Exception {
|
||||
Properties mappings = new Properties();
|
||||
mappings.setProperty(Exception.class.getName(), "SENDER, Sender error");
|
||||
@@ -133,17 +141,18 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getServerOrReceiverFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getServerOrReceiverFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "Receiver error", fault.getFaultReasonText(Locale.ENGLISH));
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "Receiver error", fault.getFaultReasonText(Locale.ENGLISH));
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveExceptionDefault() throws Exception {
|
||||
Properties mappings = new Properties();
|
||||
mappings.setProperty(SoapMessageException.class.getName(), "SERVER,Server error");
|
||||
@@ -157,30 +166,31 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IllegalArgumentException("bla"));
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "bla", fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "bla", fault.getFaultStringOrReason());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
|
||||
// SWS-226
|
||||
result = resolver.resolveException(context, null, new IllegalArgumentException());
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "java.lang.IllegalArgumentException",
|
||||
Assert.assertEquals("Invalid fault string on fault", "java.lang.IllegalArgumentException",
|
||||
fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveNoMessageException() throws Exception {
|
||||
Properties mappings = new Properties();
|
||||
mappings.setProperty(IOException.class.getName(), "SERVER");
|
||||
@@ -192,15 +202,15 @@ public class SoapFaultMappingExceptionResolverTest extends XMLTestCase {
|
||||
MessageContext context = new DefaultMessageContext(new SaajSoapMessage(message), factory);
|
||||
|
||||
boolean result = resolver.resolveException(context, null, new IOException());
|
||||
assertTrue("resolveException returns false", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertTrue("resolveException returns false", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getServerOrReceiverFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", "java.io.IOException", fault.getFaultStringOrReason());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", "java.io.IOException", fault.getFaultStringOrReason());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -27,10 +27,6 @@ import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.LocatorImpl;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.MockWebServiceMessage;
|
||||
@@ -50,7 +46,15 @@ import org.springframework.ws.transport.MockTransportInputStream;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
|
||||
public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.LocatorImpl;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class PayloadValidatingInterceptorTest {
|
||||
|
||||
private PayloadValidatingInterceptor interceptor;
|
||||
|
||||
@@ -76,8 +80,8 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
|
||||
private static final String SCHEMA2 = "schema2.xsd";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
interceptor = new PayloadValidatingInterceptor();
|
||||
interceptor.setSchema(new ClassPathResource(SCHEMA, getClass()));
|
||||
interceptor.setValidateRequest(true);
|
||||
@@ -89,6 +93,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleInvalidRequestSoap11() throws Exception {
|
||||
SoapMessage invalidMessage = (SoapMessage) soap11Factory.createWebServiceMessage();
|
||||
InputStream inputStream = getClass().getResourceAsStream(INVALID_MESSAGE);
|
||||
@@ -96,18 +101,19 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
context = new DefaultMessageContext(invalidMessage, soap11Factory);
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertFalse("Invalid response from interceptor", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", PayloadValidatingInterceptor.DEFAULT_FAULTSTRING_OR_REASON,
|
||||
Assert.assertEquals("Invalid fault string on fault", PayloadValidatingInterceptor.DEFAULT_FAULTSTRING_OR_REASON,
|
||||
fault.getFaultStringOrReason());
|
||||
assertNotNull("No Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertNotNull("No Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleInvalidRequestSoap12() throws Exception {
|
||||
SoapMessage invalidMessage = (SoapMessage) soap12Factory.createWebServiceMessage();
|
||||
InputStream inputStream = getClass().getResourceAsStream(INVALID_MESSAGE);
|
||||
@@ -115,18 +121,19 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
context = new DefaultMessageContext(invalidMessage, soap12Factory);
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertFalse("Invalid response from interceptor", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Soap12Fault fault = (Soap12Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_12.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", PayloadValidatingInterceptor.DEFAULT_FAULTSTRING_OR_REASON,
|
||||
Assert.assertEquals("Invalid fault string on fault", PayloadValidatingInterceptor.DEFAULT_FAULTSTRING_OR_REASON,
|
||||
fault.getFaultReasonText(Locale.ENGLISH));
|
||||
assertNotNull("No Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertNotNull("No Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleInvalidRequestOverridenProperties() throws Exception {
|
||||
String faultString = "fout";
|
||||
Locale locale = new Locale("nl");
|
||||
@@ -140,53 +147,58 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
context = new DefaultMessageContext(invalidMessage, soap11Factory);
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
assertTrue("Context has no response", context.hasResponse());
|
||||
Assert.assertFalse("Invalid response from interceptor", result);
|
||||
Assert.assertTrue("Context has no response", context.hasResponse());
|
||||
SoapMessage response = (SoapMessage) context.getResponse();
|
||||
assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Assert.assertTrue("Response has no fault", response.getSoapBody().hasFault());
|
||||
Soap11Fault fault = (Soap11Fault) response.getSoapBody().getFault();
|
||||
assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
Assert.assertEquals("Invalid fault code on fault", SoapVersion.SOAP_11.getClientOrSenderFaultName(),
|
||||
fault.getFaultCode());
|
||||
assertEquals("Invalid fault string on fault", faultString, fault.getFaultStringOrReason());
|
||||
assertEquals("Invalid fault string locale on fault", locale, fault.getFaultStringLocale());
|
||||
assertNull("Detail on fault", fault.getFaultDetail());
|
||||
Assert.assertEquals("Invalid fault string on fault", faultString, fault.getFaultStringOrReason());
|
||||
Assert.assertEquals("Invalid fault string locale on fault", locale, fault.getFaultStringLocale());
|
||||
Assert.assertNull("Detail on fault", fault.getFaultDetail());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlerInvalidRequest() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
request.setPayload(new ClassPathResource(INVALID_MESSAGE, getClass()));
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
Assert.assertFalse("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleValidRequest() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
request.setPayload(new ClassPathResource(VALID_MESSAGE, getClass()));
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
assertFalse("Response set", context.hasResponse());
|
||||
Assert.assertTrue("Invalid response from interceptor", result);
|
||||
Assert.assertFalse("Response set", context.hasResponse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleInvalidResponse() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(new ClassPathResource(INVALID_MESSAGE, getClass()));
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
Assert.assertFalse("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleValidResponse() throws Exception {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage();
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(new ClassPathResource(VALID_MESSAGE, getClass()));
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
Assert.assertTrue("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamespacesInType() throws Exception {
|
||||
// Make sure we use Xerces for this testcase: the JAXP implementation used internally by JDK 1.5 has a bug
|
||||
// See http://opensource.atlassian.com/projects/spring/browse/SWS-35
|
||||
@@ -205,8 +217,8 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
new SaajSoapMessageFactory(messageFactory));
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
assertFalse("Response set", context.hasResponse());
|
||||
Assert.assertTrue("Invalid response from interceptor", result);
|
||||
Assert.assertFalse("Response set", context.hasResponse());
|
||||
}
|
||||
finally {
|
||||
// Reset the property
|
||||
@@ -215,17 +227,19 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistingSchema() throws Exception {
|
||||
try {
|
||||
interceptor.setSchema(new ClassPathResource("invalid"));
|
||||
interceptor.afterPropertiesSet();
|
||||
fail("IllegalArgumentException expected");
|
||||
Assert.fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlerInvalidRequestMultipleSchemas() throws Exception {
|
||||
interceptor.setSchemas(new Resource[]{new ClassPathResource(PRODUCT_SCHEMA, getClass()),
|
||||
new ClassPathResource(SIZE_SCHEMA, getClass())});
|
||||
@@ -233,9 +247,10 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
MockWebServiceMessage request = new MockWebServiceMessage(new ClassPathResource(INVALID_MESSAGE, getClass()));
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
Assert.assertFalse("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleValidRequestMultipleSchemas() throws Exception {
|
||||
interceptor.setSchemas(new Resource[]{new ClassPathResource(PRODUCT_SCHEMA, getClass()),
|
||||
new ClassPathResource(SIZE_SCHEMA, getClass())});
|
||||
@@ -244,10 +259,11 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
assertFalse("Response set", context.hasResponse());
|
||||
Assert.assertTrue("Invalid response from interceptor", result);
|
||||
Assert.assertFalse("Response set", context.hasResponse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleInvalidResponseMultipleSchemas() throws Exception {
|
||||
interceptor.setSchemas(new Resource[]{new ClassPathResource(PRODUCT_SCHEMA, getClass()),
|
||||
new ClassPathResource(SIZE_SCHEMA, getClass())});
|
||||
@@ -257,9 +273,10 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(new ClassPathResource(INVALID_MESSAGE, getClass()));
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertFalse("Invalid response from interceptor", result);
|
||||
Assert.assertFalse("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleValidResponseMultipleSchemas() throws Exception {
|
||||
interceptor.setSchemas(new Resource[]{new ClassPathResource(PRODUCT_SCHEMA, getClass()),
|
||||
new ClassPathResource(SIZE_SCHEMA, getClass())});
|
||||
@@ -269,9 +286,10 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
MockWebServiceMessage response = (MockWebServiceMessage) context.getResponse();
|
||||
response.setPayload(new ClassPathResource(VALID_MESSAGE, getClass()));
|
||||
boolean result = interceptor.handleResponse(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
Assert.assertTrue("Invalid response from interceptor", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRequestValidationFaultAxiom() throws Exception {
|
||||
LocatorImpl locator = new LocatorImpl();
|
||||
locator.setLineNumber(0);
|
||||
@@ -292,6 +310,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXsdSchema() throws Exception {
|
||||
PayloadValidatingInterceptor interceptor = new PayloadValidatingInterceptor();
|
||||
SimpleXsdSchema schema = new SimpleXsdSchema(new ClassPathResource(SCHEMA, getClass()));
|
||||
@@ -304,10 +323,11 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
request.setPayload(new ClassPathResource(VALID_MESSAGE, getClass()));
|
||||
context = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
assertFalse("Response set", context.hasResponse());
|
||||
Assert.assertTrue("Invalid response from interceptor", result);
|
||||
Assert.assertFalse("Response set", context.hasResponse());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAxiom() throws Exception {
|
||||
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
|
||||
messageFactory.setPayloadCaching(true);
|
||||
@@ -322,10 +342,11 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
|
||||
MessageContext context = new DefaultMessageContext(message, messageFactory);
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
Assert.assertTrue("Invalid response from interceptor", result);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleNamespacesAxiom() throws Exception {
|
||||
AxiomSoapMessageFactory messageFactory = new AxiomSoapMessageFactory();
|
||||
messageFactory.setPayloadCaching(true);
|
||||
@@ -340,7 +361,7 @@ public class PayloadValidatingInterceptorTest extends XMLTestCase {
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
|
||||
MessageContext context = new DefaultMessageContext(message, messageFactory);
|
||||
boolean result = interceptor.handleRequest(context, null);
|
||||
assertTrue("Invalid response from interceptor", result);
|
||||
Assert.assertTrue("Invalid response from interceptor", result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.ws.soap.soap11;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
@@ -30,6 +28,11 @@ import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.MockTransportOutputStream;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageTestCase {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.ws.soap.soap12;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.InputStreamSource;
|
||||
@@ -31,6 +29,11 @@ import org.springframework.ws.transport.MockTransportOutputStream;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageTestCase {
|
||||
|
||||
@Override
|
||||
@@ -59,12 +62,12 @@ public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageT
|
||||
assertXMLEqual(
|
||||
"<Envelope xmlns='http://www.w3.org/2003/05/soap-envelope'><Body><payload xmlns='http://www.springframework.org' /></Body></Envelope>",
|
||||
result);
|
||||
String contentType = (String) tos.getHeaders().get(TransportConstants.HEADER_CONTENT_TYPE);
|
||||
String contentType = tos.getHeaders().get(TransportConstants.HEADER_CONTENT_TYPE);
|
||||
assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_12.getContentType()) != -1);
|
||||
assertNull(TransportConstants.HEADER_SOAP_ACTION + " header must not be found",
|
||||
tos.getHeaders().get(TransportConstants.HEADER_SOAP_ACTION));
|
||||
assertTrue("Invalid Content-Type set", contentType.indexOf(soapAction) != -1);
|
||||
String resultAccept = (String) tos.getHeaders().get("Accept");
|
||||
String resultAccept = tos.getHeaders().get("Accept");
|
||||
assertNotNull("Invalid accept header", resultAccept);
|
||||
}
|
||||
|
||||
@@ -75,7 +78,7 @@ public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageT
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
MockTransportOutputStream tos = new MockTransportOutputStream(bos);
|
||||
soapMessage.writeTo(tos);
|
||||
String contentType = (String) tos.getHeaders().get("Content-Type");
|
||||
String contentType = tos.getHeaders().get("Content-Type");
|
||||
assertTrue("Content-Type for attachment message does not contains multipart/related",
|
||||
contentType.indexOf("multipart/related") != -1);
|
||||
assertTrue("Content-Type for attachment message does not contains type=\"application/soap+xml\"",
|
||||
|
||||
@@ -47,13 +47,19 @@ import org.springframework.ws.transport.WebServiceConnection;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.servlet.Context;
|
||||
import org.mortbay.jetty.servlet.ServletHolder;
|
||||
|
||||
public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase extends XMLTestCase {
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase {
|
||||
|
||||
private Server jettyServer;
|
||||
|
||||
@@ -89,8 +95,8 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
|
||||
|
||||
private URI connectionUri;
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
connectionUri = new URI("http://localhost:8888/");
|
||||
jettyServer = new Server(8888);
|
||||
jettyContext = new Context(jettyServer, "/");
|
||||
@@ -106,33 +112,38 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
|
||||
|
||||
protected abstract AbstractHttpWebServiceMessageSender createMessageSender();
|
||||
|
||||
@Override
|
||||
protected final void tearDown() throws Exception {
|
||||
@After
|
||||
public final void tearDown() throws Exception {
|
||||
if (jettyServer.isRunning()) {
|
||||
jettyServer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupports() throws URISyntaxException {
|
||||
assertTrue("Message sender does not support HTTP url", messageSender.supports(connectionUri));
|
||||
Assert.assertTrue("Message sender does not support HTTP url", messageSender.supports(connectionUri));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveResponse() throws Exception {
|
||||
MyServlet servlet = new MyServlet();
|
||||
servlet.setResponse(true);
|
||||
validateResponse(servlet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveNoResponse() throws Exception {
|
||||
validateNonResponse(new MyServlet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveNoResponseAccepted() throws Exception {
|
||||
MyServlet servlet = new MyServlet();
|
||||
servlet.setResponseStatus(HttpServletResponse.SC_ACCEPTED);
|
||||
validateNonResponse(servlet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveCompressed() throws Exception {
|
||||
MyServlet servlet = new MyServlet();
|
||||
servlet.setResponse(true);
|
||||
@@ -140,6 +151,7 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
|
||||
validateResponse(servlet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveInvalidContentSize() throws Exception {
|
||||
MyServlet servlet = new MyServlet();
|
||||
servlet.setResponse(true);
|
||||
@@ -147,6 +159,7 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
|
||||
validateResponse(servlet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveCompressedInvalidContentSize() throws Exception {
|
||||
MyServlet servlet = new MyServlet();
|
||||
servlet.setResponse(true);
|
||||
@@ -155,6 +168,7 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
|
||||
validateResponse(servlet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceiveFault() throws Exception {
|
||||
MyServlet servlet = new MyServlet();
|
||||
servlet.setResponseStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
@@ -167,17 +181,13 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
|
||||
try {
|
||||
connection.send(new SaajSoapMessage(request));
|
||||
connection.receive(messageFactory);
|
||||
assertTrue("Response has no fault", connection.hasFault());
|
||||
Assert.assertTrue("Response has no fault", connection.hasFault());
|
||||
}
|
||||
finally {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testReuseClosedConnection() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
private void validateResponse(Servlet servlet) throws Exception {
|
||||
jettyContext.addServlet(new ServletHolder(servlet), "/");
|
||||
jettyServer.start();
|
||||
@@ -187,13 +197,13 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
|
||||
try {
|
||||
connection.send(new SaajSoapMessage(request));
|
||||
SaajSoapMessage response = (SaajSoapMessage) connection.receive(messageFactory);
|
||||
assertNotNull("No response", response);
|
||||
assertFalse("Response has fault", connection.hasFault());
|
||||
Assert.assertNotNull("No response", response);
|
||||
Assert.assertFalse("Response has fault", connection.hasFault());
|
||||
SOAPMessage saajResponse = response.getSaajMessage();
|
||||
String[] headerValues = saajResponse.getMimeHeaders().getHeader(RESPONSE_HEADER_NAME);
|
||||
assertNotNull("Response has no header", headerValues);
|
||||
assertEquals("Response has invalid header", 1, headerValues.length);
|
||||
assertEquals("Response has invalid header values", RESPONSE_HEADER_VALUE, headerValues[0]);
|
||||
Assert.assertNotNull("Response has no header", headerValues);
|
||||
Assert.assertEquals("Response has invalid header", 1, headerValues.length);
|
||||
Assert.assertEquals("Response has invalid header values", RESPONSE_HEADER_VALUE, headerValues[0]);
|
||||
StringResult result = new StringResult();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
transformer.transform(response.getPayloadSource(), result);
|
||||
@@ -213,7 +223,7 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
|
||||
try {
|
||||
connection.send(new SaajSoapMessage(request));
|
||||
WebServiceMessage response = connection.receive(messageFactory);
|
||||
assertNull("Response", response);
|
||||
Assert.assertNull("Response", response);
|
||||
}
|
||||
finally {
|
||||
connection.close();
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.ws.transport.WebServiceConnection;
|
||||
|
||||
import org.apache.commons.httpclient.ConnectTimeoutException;
|
||||
import org.apache.commons.httpclient.URIException;
|
||||
import org.junit.Test;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.servlet.Context;
|
||||
import org.mortbay.jetty.servlet.ServletHolder;
|
||||
@@ -48,20 +49,16 @@ public class CommonsHttpMessageSenderIntegrationTest extends AbstractHttpWebServ
|
||||
return new CommonsHttpMessageSender();
|
||||
}
|
||||
|
||||
@Test(expected = ConnectTimeoutException.class)
|
||||
public void testConnectionTimeout() throws Exception {
|
||||
CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender();
|
||||
messageSender.setConnectionTimeout(1);
|
||||
WebServiceConnection connection = messageSender.createConnection(new URI("http://example.com/"));
|
||||
WebServiceMessage message = new MockWebServiceMessage();
|
||||
try {
|
||||
connection.send(message);
|
||||
fail("ConnectTimeoutException expected");
|
||||
}
|
||||
catch (ConnectTimeoutException ex) {
|
||||
// expected
|
||||
}
|
||||
connection.send(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxConnections() throws URISyntaxException, URIException {
|
||||
CommonsHttpMessageSender messageSender = new CommonsHttpMessageSender();
|
||||
messageSender.setMaxTotalConnections(2);
|
||||
@@ -73,6 +70,7 @@ public class CommonsHttpMessageSenderIntegrationTest extends AbstractHttpWebServ
|
||||
messageSender.setMaxConnectionsPerHost(maxConnectionsPerHost);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContextClose() throws Exception {
|
||||
MessageFactory messageFactory = MessageFactory.newInstance();
|
||||
Server jettyServer = new Server(8888);
|
||||
@@ -86,7 +84,7 @@ public class CommonsHttpMessageSenderIntegrationTest extends AbstractHttpWebServ
|
||||
appContext.registerSingleton("messageSender", CommonsHttpMessageSender.class);
|
||||
appContext.refresh();
|
||||
|
||||
CommonsHttpMessageSender messageSender = (CommonsHttpMessageSender) appContext
|
||||
CommonsHttpMessageSender messageSender = appContext
|
||||
.getBean("messageSender", CommonsHttpMessageSender.class);
|
||||
connection = messageSender.createConnection(new URI("http://localhost:8888/"));
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ import javax.xml.soap.SOAPMessage;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
@@ -31,7 +30,13 @@ import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
public class HttpServletConnectionTest extends XMLTestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class HttpServletConnectionTest {
|
||||
|
||||
private HttpServletConnection connection;
|
||||
|
||||
@@ -53,8 +58,8 @@ public class HttpServletConnectionTest extends XMLTestCase {
|
||||
|
||||
private TransformerFactory transformerFactory;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
httpServletRequest = new MockHttpServletRequest();
|
||||
httpServletResponse = new MockHttpServletResponse();
|
||||
connection = new HttpServletConnection(httpServletRequest, httpServletResponse);
|
||||
@@ -63,25 +68,27 @@ public class HttpServletConnectionTest extends XMLTestCase {
|
||||
transformerFactory = TransformerFactory.newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceive() throws Exception {
|
||||
byte[] bytes = SOAP_CONTENT.getBytes("UTF-8");
|
||||
httpServletRequest.addHeader("Content-Type", "text/xml");
|
||||
httpServletRequest.addHeader("Content-Length", new Integer(bytes.length).toString());
|
||||
httpServletRequest.addHeader("Content-Length", Integer.toString(bytes.length));
|
||||
httpServletRequest.addHeader(HEADER_NAME, HEADER_VALUE);
|
||||
httpServletRequest.setContent(bytes);
|
||||
SaajSoapMessage message = (SaajSoapMessage) connection.receive(messageFactory);
|
||||
assertNotNull("No message received", message);
|
||||
Assert.assertNotNull("No message received", message);
|
||||
StringResult result = new StringResult();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
transformer.transform(message.getPayloadSource(), result);
|
||||
assertXMLEqual("Invalid message", CONTENT, result.toString());
|
||||
SOAPMessage saajMessage = message.getSaajMessage();
|
||||
String[] headerValues = saajMessage.getMimeHeaders().getHeader(HEADER_NAME);
|
||||
assertNotNull("Response has no header", headerValues);
|
||||
assertEquals("Response has invalid header", 1, headerValues.length);
|
||||
assertEquals("Response has invalid header values", HEADER_VALUE, headerValues[0]);
|
||||
Assert.assertNotNull("Response has no header", headerValues);
|
||||
Assert.assertEquals("Response has invalid header", 1, headerValues.length);
|
||||
Assert.assertEquals("Response has invalid header values", HEADER_VALUE, headerValues[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSend() throws Exception {
|
||||
SaajSoapMessage message = (SaajSoapMessage) messageFactory.createWebServiceMessage();
|
||||
SOAPMessage saajMessage = message.getSaajMessage();
|
||||
@@ -92,7 +99,7 @@ public class HttpServletConnectionTest extends XMLTestCase {
|
||||
|
||||
connection.send(message);
|
||||
|
||||
assertEquals("Invalid header", HEADER_VALUE, httpServletResponse.getHeader(HEADER_NAME));
|
||||
Assert.assertEquals("Invalid header", HEADER_VALUE, httpServletResponse.getHeader(HEADER_NAME));
|
||||
assertXMLEqual("Invalid content", SOAP_CONTENT, httpServletResponse.getContentAsString());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,6 @@ import javax.servlet.ServletException;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -41,41 +37,52 @@ import org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMa
|
||||
import org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver;
|
||||
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
|
||||
|
||||
public class MessageDispatcherServletTest extends XMLTestCase {
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class MessageDispatcherServletTest {
|
||||
|
||||
private ServletConfig config;
|
||||
|
||||
private MessageDispatcherServlet servlet;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
config = new MockServletConfig(new MockServletContext(), "spring-ws");
|
||||
servlet = new MessageDispatcherServlet();
|
||||
}
|
||||
|
||||
private void assertStrategies(Class expectedClass, List actual) {
|
||||
assertEquals("Invalid amount of strategies", 1, actual.size());
|
||||
private void assertStrategies(Class<?> expectedClass, List<?> actual) {
|
||||
Assert.assertEquals("Invalid amount of strategies", 1, actual.size());
|
||||
Object strategy = actual.get(0);
|
||||
assertTrue("Invalid strategy", expectedClass.isAssignableFrom(strategy.getClass()));
|
||||
Assert.assertTrue("Invalid strategy", expectedClass.isAssignableFrom(strategy.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultStrategies() throws ServletException {
|
||||
servlet.setContextClass(StaticWebApplicationContext.class);
|
||||
servlet.init(config);
|
||||
MessageDispatcher messageDispatcher = (MessageDispatcher) servlet.getMessageReceiver();
|
||||
assertNotNull("No messageDispatcher created", messageDispatcher);
|
||||
Assert.assertNotNull("No messageDispatcher created", messageDispatcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectedStrategies() throws ServletException {
|
||||
servlet.setContextClass(DetectWebApplicationContext.class);
|
||||
servlet.init(config);
|
||||
MessageDispatcher messageDispatcher = (MessageDispatcher) servlet.getMessageReceiver();
|
||||
assertNotNull("No messageDispatcher created", messageDispatcher);
|
||||
Assert.assertNotNull("No messageDispatcher created", messageDispatcher);
|
||||
assertStrategies(PayloadRootQNameEndpointMapping.class, messageDispatcher.getEndpointMappings());
|
||||
assertStrategies(PayloadEndpointAdapter.class, messageDispatcher.getEndpointAdapters());
|
||||
assertStrategies(SimpleSoapExceptionResolver.class, messageDispatcher.getEndpointExceptionResolvers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectWsdlDefinitions() throws Exception {
|
||||
servlet.setContextClass(WsdlDefinitionWebApplicationContext.class);
|
||||
servlet.init(config);
|
||||
|
||||
@@ -26,11 +26,6 @@ import javax.wsdl.xml.WSDLReader;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
@@ -38,47 +33,62 @@ import org.springframework.ws.wsdl.WsdlDefinition;
|
||||
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
import static org.easymock.EasyMock.*;
|
||||
|
||||
public class WsdlDefinitionHandlerAdapterTest {
|
||||
|
||||
private WsdlDefinitionHandlerAdapter adapter;
|
||||
|
||||
private MockControl definitionControl;
|
||||
|
||||
private WsdlDefinition definitionMock;
|
||||
|
||||
private MockHttpServletRequest request;
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
adapter = new WsdlDefinitionHandlerAdapter();
|
||||
definitionControl = MockControl.createControl(WsdlDefinition.class);
|
||||
definitionMock = (WsdlDefinition) definitionControl.getMock();
|
||||
definitionMock = createMock(WsdlDefinition.class);
|
||||
adapter.afterPropertiesSet();
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleGet() throws Exception {
|
||||
request.setMethod(HttpTransportConstants.METHOD_GET);
|
||||
String definition = "<definition xmlns='http://schemas.xmlsoap.org/wsdl/'/>";
|
||||
definitionControl.expectAndReturn(definitionMock.getSource(), new StringSource(definition));
|
||||
definitionControl.replay();
|
||||
expect(definitionMock.getSource()).andReturn(new StringSource(definition));
|
||||
|
||||
replay(definitionMock);
|
||||
|
||||
adapter.handle(request, response, definitionMock);
|
||||
assertXMLEqual(definition, response.getContentAsString());
|
||||
definitionControl.verify();
|
||||
|
||||
verify(definitionMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleNonGet() throws Exception {
|
||||
request.setMethod(HttpTransportConstants.METHOD_POST);
|
||||
definitionControl.replay();
|
||||
adapter.handle(request, response, definitionMock);
|
||||
definitionControl.verify();
|
||||
assertEquals("METHOD_NOT_ALLOWED expected", HttpServletResponse.SC_METHOD_NOT_ALLOWED, response.getStatus());
|
||||
|
||||
replay(definitionMock);
|
||||
|
||||
adapter.handle(request, response, definitionMock);
|
||||
Assert.assertEquals("METHOD_NOT_ALLOWED expected", HttpServletResponse.SC_METHOD_NOT_ALLOWED,
|
||||
response.getStatus());
|
||||
|
||||
verify(definitionMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformLocations() throws Exception {
|
||||
adapter.setTransformLocations(true);
|
||||
request.setMethod(HttpTransportConstants.METHOD_GET);
|
||||
@@ -89,7 +99,8 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
request.setServletPath("/service.wsdl");
|
||||
request.setPathInfo(null);
|
||||
request.setRequestURI("/context/service.wsdl");
|
||||
definitionControl.replay();
|
||||
|
||||
replay(definitionMock);
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
documentBuilderFactory.setNamespaceAware(true);
|
||||
@@ -99,9 +110,10 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
Document expectedDocument = documentBuilder.parse(getClass().getResourceAsStream("wsdl11-expected.wsdl"));
|
||||
assertXMLEqual("Invalid result", expectedDocument, result);
|
||||
|
||||
definitionControl.verify();
|
||||
verify(definitionMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformLocationFullUrl() throws Exception {
|
||||
request.setScheme("http");
|
||||
request.setServerName("example.com");
|
||||
@@ -112,10 +124,11 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
String oldLocation = "http://localhost:8080/context/service";
|
||||
|
||||
String result = adapter.transformLocation(oldLocation, request);
|
||||
assertNotNull("No result", result);
|
||||
assertEquals("Invalid result", new URI("http://example.com:8080/context/service"), new URI(result));
|
||||
Assert.assertNotNull("No result", result);
|
||||
Assert.assertEquals("Invalid result", new URI("http://example.com:8080/context/service"), new URI(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformLocationEmptyContextFullUrl() throws Exception {
|
||||
request.setScheme("http");
|
||||
request.setServerName("example.com");
|
||||
@@ -125,10 +138,11 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
String oldLocation = "http://localhost:8080/service";
|
||||
|
||||
String result = adapter.transformLocation(oldLocation, request);
|
||||
assertNotNull("No result", result);
|
||||
assertEquals("Invalid result", new URI("http://example.com:8080/service"), new URI(result));
|
||||
Assert.assertNotNull("No result", result);
|
||||
Assert.assertEquals("Invalid result", new URI("http://example.com:8080/service"), new URI(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformLocationRelativeUrl() throws Exception {
|
||||
request.setScheme("http");
|
||||
request.setServerName("example.com");
|
||||
@@ -139,10 +153,11 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
String oldLocation = "/service";
|
||||
|
||||
String result = adapter.transformLocation(oldLocation, request);
|
||||
assertNotNull("No result", result);
|
||||
assertEquals("Invalid result", new URI("http://example.com:8080/context/service"), new URI(result));
|
||||
Assert.assertNotNull("No result", result);
|
||||
Assert.assertEquals("Invalid result", new URI("http://example.com:8080/context/service"), new URI(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransformLocationEmptyContextRelativeUrl() throws Exception {
|
||||
request.setScheme("http");
|
||||
request.setServerName("example.com");
|
||||
@@ -152,10 +167,11 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
String oldLocation = "/service";
|
||||
|
||||
String result = adapter.transformLocation(oldLocation, request);
|
||||
assertNotNull("No result", result);
|
||||
assertEquals("Invalid result", new URI("http://example.com:8080/service"), new URI(result));
|
||||
Assert.assertNotNull("No result", result);
|
||||
Assert.assertEquals("Invalid result", new URI("http://example.com:8080/service"), new URI(result));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleSimpleWsdl11DefinitionWithoutTransformLocations() throws Exception {
|
||||
adapter.setTransformLocations(false);
|
||||
request.setMethod(HttpTransportConstants.METHOD_GET);
|
||||
@@ -176,7 +192,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
WSDLReader reader = factory.newWSDLReader();
|
||||
Definition wsdl4jDefinition = reader.readWSDL(null, new InputSource(inputStream));
|
||||
assertNotNull("No definition read", wsdl4jDefinition);
|
||||
Assert.assertNotNull("No definition read", wsdl4jDefinition);
|
||||
|
||||
inputStream = new ByteArrayInputStream(response.getContentAsByteArray());
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
@@ -189,6 +205,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
assertXMLEqual("Invalid WSDL returned", expectedDocument, resultingDocument);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleSimpleWsdl11DefinitionWithTransformLocation() throws Exception {
|
||||
adapter.setTransformLocations(true);
|
||||
request.setMethod(HttpTransportConstants.METHOD_GET);
|
||||
@@ -209,7 +226,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
WSDLReader reader = factory.newWSDLReader();
|
||||
Definition wsdl4jDefinition = reader.readWSDL(null, new InputSource(inputStream));
|
||||
assertNotNull("No definition read", wsdl4jDefinition);
|
||||
Assert.assertNotNull("No definition read", wsdl4jDefinition);
|
||||
|
||||
inputStream = new ByteArrayInputStream(response.getContentAsByteArray());
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.ws.transport.http;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -27,7 +25,13 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
|
||||
public class XsdSchemaHandlerAdapterTest extends XMLTestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class XsdSchemaHandlerAdapterTest {
|
||||
|
||||
private XsdSchemaHandlerAdapter adapter;
|
||||
|
||||
@@ -35,21 +39,23 @@ public class XsdSchemaHandlerAdapterTest extends XMLTestCase {
|
||||
|
||||
private MockHttpServletResponse response;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
adapter = new XsdSchemaHandlerAdapter();
|
||||
request = new MockHttpServletRequest();
|
||||
response = new MockHttpServletResponse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLastModified() throws Exception {
|
||||
Resource single = new ClassPathResource("single.xsd", getClass());
|
||||
SimpleXsdSchema schema = new SimpleXsdSchema(single);
|
||||
schema.afterPropertiesSet();
|
||||
long lastModified = single.getFile().lastModified();
|
||||
assertEquals("Invalid last modified", lastModified, adapter.getLastModified(null, schema));
|
||||
Assert.assertEquals("Invalid last modified", lastModified, adapter.getLastModified(null, schema));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleGet() throws Exception {
|
||||
request.setMethod(HttpTransportConstants.METHOD_GET);
|
||||
Resource single = new ClassPathResource("single.xsd", getClass());
|
||||
@@ -60,9 +66,11 @@ public class XsdSchemaHandlerAdapterTest extends XMLTestCase {
|
||||
assertXMLEqual(expected, response.getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandleNonGet() throws Exception {
|
||||
request.setMethod(HttpTransportConstants.METHOD_POST);
|
||||
adapter.handle(request, response, null);
|
||||
assertEquals("METHOD_NOT_ALLOWED expected", HttpServletResponse.SC_METHOD_NOT_ALLOWED, response.getStatus());
|
||||
Assert.assertEquals("METHOD_NOT_ALLOWED expected", HttpServletResponse.SC_METHOD_NOT_ALLOWED,
|
||||
response.getStatus());
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,19 @@ 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.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.xml.xsd.SimpleXsdSchema;
|
||||
import org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection;
|
||||
|
||||
public class DefaultWsdl11DefinitionTest extends XMLTestCase {
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class DefaultWsdl11DefinitionTest {
|
||||
|
||||
private DefaultWsdl11Definition definition;
|
||||
|
||||
@@ -39,8 +42,8 @@ public class DefaultWsdl11DefinitionTest extends XMLTestCase {
|
||||
|
||||
private DocumentBuilder documentBuilder;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
definition = new DefaultWsdl11Definition();
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
transformer = transformerFactory.newTransformer();
|
||||
@@ -50,6 +53,7 @@ public class DefaultWsdl11DefinitionTest extends XMLTestCase {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingle() throws Exception {
|
||||
Resource resource = new ClassPathResource("single.xsd", getClass());
|
||||
SimpleXsdSchema schema = new SimpleXsdSchema(resource);
|
||||
@@ -72,6 +76,7 @@ public class DefaultWsdl11DefinitionTest extends XMLTestCase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInclude() throws Exception {
|
||||
ClassPathResource resource = new ClassPathResource("including.xsd", getClass());
|
||||
CommonsXsdSchemaCollection schemaCollection = new CommonsXsdSchemaCollection(new Resource[]{resource});
|
||||
@@ -92,6 +97,7 @@ public class DefaultWsdl11DefinitionTest extends XMLTestCase {
|
||||
assertXMLEqual("Invalid WSDL built", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImport() throws Exception {
|
||||
ClassPathResource resource = new ClassPathResource("importing.xsd", getClass());
|
||||
CommonsXsdSchemaCollection schemaCollection = new CommonsXsdSchemaCollection(new Resource[]{resource});
|
||||
@@ -112,6 +118,7 @@ public class DefaultWsdl11DefinitionTest extends XMLTestCase {
|
||||
assertXMLEqual("Invalid WSDL built", expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSoap11And12() throws Exception {
|
||||
Resource resource = new ClassPathResource("single.xsd", getClass());
|
||||
SimpleXsdSchema schema = new SimpleXsdSchema(resource);
|
||||
|
||||
@@ -27,19 +27,23 @@ 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.xml.sax.InputSource;
|
||||
|
||||
public class Wsdl4jDefinitionTest extends XMLTestCase {
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
public class Wsdl4jDefinitionTest {
|
||||
|
||||
private Wsdl4jDefinition definition;
|
||||
|
||||
private Transformer transformer;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
XMLUnit.setIgnoreWhitespace(true);
|
||||
WSDLFactory factory = WSDLFactory.newInstance();
|
||||
WSDLReader reader = factory.newWSDLReader();
|
||||
@@ -54,9 +58,10 @@ public class Wsdl4jDefinitionTest extends XMLTestCase {
|
||||
transformer = TransformerFactory.newInstance().newTransformer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSource() throws Exception {
|
||||
Source source = definition.getSource();
|
||||
assertNotNull("Source is null", source);
|
||||
Assert.assertNotNull("Source is null", source);
|
||||
DOMResult result = new DOMResult();
|
||||
transformer.transform(source, result);
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
|
||||
@@ -25,29 +25,32 @@ import javax.xml.soap.MimeHeaders;
|
||||
import javax.xml.soap.SOAPException;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import org.custommonkey.xmlunit.XMLTestCase;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.xml.xpath.XPathExpression;
|
||||
import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
|
||||
public abstract class AbstractXwssMessageInterceptorTestCase extends XMLTestCase {
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public abstract class AbstractXwssMessageInterceptorTestCase {
|
||||
|
||||
protected XwsSecurityInterceptor interceptor;
|
||||
|
||||
private MessageFactory messageFactory;
|
||||
|
||||
private Map namespaces;
|
||||
private Map<String, String> namespaces;
|
||||
|
||||
@Override
|
||||
protected final void setUp() throws Exception {
|
||||
@Before
|
||||
public final void setUp() throws Exception {
|
||||
interceptor = new XwsSecurityInterceptor();
|
||||
messageFactory = MessageFactory.newInstance();
|
||||
namespaces = new HashMap();
|
||||
namespaces = new HashMap<String, String>(4);
|
||||
namespaces.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
|
||||
namespaces.put("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
|
||||
namespaces.put("ds", "http://www.w3.org/2000/09/xmldsig#");
|
||||
@@ -62,21 +65,21 @@ public abstract class AbstractXwssMessageInterceptorTestCase extends XMLTestCase
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression(xpathExpression, namespaces);
|
||||
Document document = soapMessage.getSOAPPart();
|
||||
String actualValue = expression.evaluateAsString(document);
|
||||
assertEquals(message, expectedValue, actualValue);
|
||||
Assert.assertEquals(message, expectedValue, actualValue);
|
||||
}
|
||||
|
||||
protected void assertXpathExists(String message, String xpathExpression, SOAPMessage soapMessage) {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression(xpathExpression, namespaces);
|
||||
Document document = soapMessage.getSOAPPart();
|
||||
Node node = expression.evaluateAsNode(document);
|
||||
assertNotNull(message, node);
|
||||
Assert.assertNotNull(message, node);
|
||||
}
|
||||
|
||||
protected void assertXpathNotExists(String message, String xpathExpression, SOAPMessage soapMessage) {
|
||||
XPathExpression expression = XPathExpressionFactory.createXPathExpression(xpathExpression, namespaces);
|
||||
Document document = soapMessage.getSOAPPart();
|
||||
Node node = expression.evaluateAsNode(document);
|
||||
assertNull(message, node);
|
||||
Assert.assertNull(message, node);
|
||||
}
|
||||
|
||||
protected SaajSoapMessage loadSaajMessage(String fileName) throws SOAPException, IOException {
|
||||
|
||||
@@ -20,15 +20,19 @@ import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.DecryptionKeyCallback;
|
||||
import com.sun.xml.wss.impl.callback.EncryptionKeyCallback;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.DecryptionKeyCallback;
|
||||
import com.sun.xml.wss.impl.callback.EncryptionKeyCallback;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class XwssMessageInterceptorEncryptTest extends AbstractXwssMessageInterceptorKeyStoreTestCase {
|
||||
|
||||
@Test
|
||||
public void testEncryptDefaultCertificate() throws Exception {
|
||||
interceptor.setPolicyConfiguration(new ClassPathResource("encrypt-config.xml", getClass()));
|
||||
CallbackHandler handler = new AbstractCallbackHandler() {
|
||||
@@ -64,6 +68,7 @@ public class XwssMessageInterceptorEncryptTest extends AbstractXwssMessageInterc
|
||||
"/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/xenc:EncryptedKey", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptAlias() throws Exception {
|
||||
interceptor.setPolicyConfiguration(new ClassPathResource("encrypt-alias-config.xml", getClass()));
|
||||
CallbackHandler handler = new AbstractCallbackHandler() {
|
||||
@@ -99,6 +104,7 @@ public class XwssMessageInterceptorEncryptTest extends AbstractXwssMessageInterc
|
||||
"/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security/xenc:EncryptedKey", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrypt() throws Exception {
|
||||
interceptor.setPolicyConfiguration(new ClassPathResource("decrypt-config.xml", getClass()));
|
||||
CallbackHandler handler = new AbstractCallbackHandler() {
|
||||
|
||||
@@ -21,15 +21,19 @@ import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
|
||||
import com.sun.xml.wss.impl.callback.SignatureKeyCallback;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
|
||||
import com.sun.xml.wss.impl.callback.SignatureKeyCallback;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class XwssMessageInterceptorSignTest extends AbstractXwssMessageInterceptorKeyStoreTestCase {
|
||||
|
||||
@Test
|
||||
public void testSignDefaultCertificate() throws Exception {
|
||||
interceptor.setPolicyConfiguration(new ClassPathResource("sign-config.xml", getClass()));
|
||||
CallbackHandler handler = new AbstractCallbackHandler() {
|
||||
@@ -65,6 +69,7 @@ public class XwssMessageInterceptorSignTest extends AbstractXwssMessageIntercept
|
||||
result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignAlias() throws Exception {
|
||||
interceptor.setPolicyConfiguration(new ClassPathResource("sign-alias-config.xml", getClass()));
|
||||
CallbackHandler handler = new AbstractCallbackHandler() {
|
||||
@@ -101,6 +106,7 @@ public class XwssMessageInterceptorSignTest extends AbstractXwssMessageIntercept
|
||||
result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateCertificate() throws Exception {
|
||||
interceptor.setPolicyConfiguration(new ClassPathResource("requireSignature-config.xml", getClass()));
|
||||
CallbackHandler handler = new AbstractCallbackHandler() {
|
||||
|
||||
@@ -20,18 +20,23 @@ import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.xml.soap.SOAPMessage;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.PasswordCallback;
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import com.sun.xml.wss.impl.callback.TimestampValidationCallback;
|
||||
import com.sun.xml.wss.impl.callback.UsernameCallback;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.ws.soap.saaj.SaajSoapMessage;
|
||||
import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
|
||||
|
||||
import com.sun.xml.wss.impl.callback.PasswordCallback;
|
||||
import com.sun.xml.wss.impl.callback.PasswordValidationCallback;
|
||||
import com.sun.xml.wss.impl.callback.TimestampValidationCallback;
|
||||
import com.sun.xml.wss.impl.callback.UsernameCallback;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class XwssMessageInterceptorUsernameTokenTest extends AbstractXwssMessageInterceptorTestCase {
|
||||
|
||||
public void testAddUsernameTokenDigest() throws Exception {
|
||||
|
||||
@Test
|
||||
public void testAddUsernameTokenDigest() throws Exception {
|
||||
interceptor.setPolicyConfiguration(new ClassPathResource("usernameToken-digest-config.xml", getClass()));
|
||||
CallbackHandler handler = new AbstractCallbackHandler() {
|
||||
|
||||
@@ -62,6 +67,7 @@ public class XwssMessageInterceptorUsernameTokenTest extends AbstractXwssMessage
|
||||
result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddUsernameTokenPlainText() throws Exception {
|
||||
interceptor.setPolicyConfiguration(new ClassPathResource("usernameToken-plainText-config.xml", getClass()));
|
||||
CallbackHandler handler = new AbstractCallbackHandler() {
|
||||
@@ -93,6 +99,7 @@ public class XwssMessageInterceptorUsernameTokenTest extends AbstractXwssMessage
|
||||
result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUsernameTokenPlainText() throws Exception {
|
||||
interceptor
|
||||
.setPolicyConfiguration(new ClassPathResource("requireUsernameToken-plainText-config.xml", getClass()));
|
||||
@@ -132,6 +139,7 @@ public class XwssMessageInterceptorUsernameTokenTest extends AbstractXwssMessage
|
||||
assertXpathNotExists("Security Header not removed", "/SOAP-ENV:Envelope/SOAP-ENV:Header/wsse:Security", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidateUsernameTokenDigest() throws Exception {
|
||||
interceptor.setPolicyConfiguration(new ClassPathResource("requireUsernameToken-digest-config.xml", getClass()));
|
||||
CallbackHandler handler = new AbstractCallbackHandler() {
|
||||
|
||||
Reference in New Issue
Block a user