From 78a2d7e0681a7afb62d6707d980b90b3d782b60f Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 2 Jan 2007 14:15:20 +0000 Subject: [PATCH] Improved testing of SAAJ. --- .../ws/soap/SoapFaultDetail.java | 2 +- .../springframework/ws/soap/SoapHeader.java | 10 + .../ws/soap/axiom/AxiomSoapHeader.java | 6 + .../ws/soap/saaj/Saaj12Implementation.java | 4 +- .../ws/soap/saaj/Saaj13Implementation.java | 4 +- .../ws/soap/saaj/SaajImplementation.java | 109 ++++--- .../ws/soap/saaj/SaajSoap12Body.java | 2 +- .../ws/soap/saaj/SaajSoap12Header.java | 2 +- .../ws/soap/saaj/SaajSoapBody.java | 2 +- .../ws/soap/saaj/SaajSoapFaultDetail.java | 2 +- .../ws/soap/saaj/SaajSoapHeader.java | 7 +- .../ws/soap/AbstractSoapHeaderTestCase.java | 15 +- .../ws/soap/axiom/AxiomSoap11HeaderTest.java | 2 + .../ws/soap/axiom/AxiomSoap12HeaderTest.java | 2 + .../AbstractSaajImplementationTestCase.java | 272 ++++++++++++++++++ .../soap/saaj/Saaj12ImplementationTest.java | 25 ++ .../soap/saaj/Saaj13ImplementationTest.java | 25 ++ 17 files changed, 435 insertions(+), 56 deletions(-) create mode 100644 core/src/test/java/org/springframework/ws/soap/saaj/AbstractSaajImplementationTestCase.java create mode 100644 core/src/test/java/org/springframework/ws/soap/saaj/Saaj12ImplementationTest.java create mode 100644 core/src/test/java/org/springframework/ws/soap/saaj/Saaj13ImplementationTest.java diff --git a/core/src/main/java/org/springframework/ws/soap/SoapFaultDetail.java b/core/src/main/java/org/springframework/ws/soap/SoapFaultDetail.java index 4fb077dd..a21a72e0 100644 --- a/core/src/main/java/org/springframework/ws/soap/SoapFaultDetail.java +++ b/core/src/main/java/org/springframework/ws/soap/SoapFaultDetail.java @@ -38,7 +38,7 @@ public interface SoapFaultDetail extends SoapElement { SoapFaultDetailElement addFaultDetailElement(QName name); /** - * Returns the Source of this element. This result does not include the element itself. + * Returns a Result that represents the concents of the detail. *

* The result can be used for marshalling. * diff --git a/core/src/main/java/org/springframework/ws/soap/SoapHeader.java b/core/src/main/java/org/springframework/ws/soap/SoapHeader.java index 6a9e3a63..1ff102de 100644 --- a/core/src/main/java/org/springframework/ws/soap/SoapHeader.java +++ b/core/src/main/java/org/springframework/ws/soap/SoapHeader.java @@ -18,6 +18,7 @@ package org.springframework.ws.soap; import java.util.Iterator; import javax.xml.namespace.QName; +import javax.xml.transform.Result; /** * Represents the Header element in a SOAP message. A SOAP header contains SoapHeaderElements, @@ -29,6 +30,15 @@ import javax.xml.namespace.QName; */ public interface SoapHeader extends SoapElement { + /** + * Returns a Result that represents the concents of the header. + *

+ * The result can be used for marshalling. + * + * @return the Result of this element + */ + Result getResult(); + /** * Adds a new SoapHeaderElement with the specified qualified name to this header. * diff --git a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeader.java b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeader.java index b7d2f09a..73a596fe 100644 --- a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeader.java +++ b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeader.java @@ -18,7 +18,9 @@ package org.springframework.ws.soap.axiom; import java.util.Iterator; import javax.xml.namespace.QName; +import javax.xml.transform.Result; import javax.xml.transform.Source; +import javax.xml.transform.sax.SAXResult; import org.apache.axiom.om.OMException; import org.apache.axiom.om.OMNamespace; @@ -57,6 +59,10 @@ class AxiomSoapHeader implements SoapHeader { return new StaxSource(axiomHeader.getXMLStreamReader()); } + public Result getResult() { + return new SAXResult(new AxiomContentHandler(axiomHeader)); + } + public SoapHeaderElement addHeaderElement(QName name) { try { OMNamespace namespace = axiomFactory.createOMNamespace(name.getNamespaceURI(), QNameUtils.getPrefix(name)); diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/Saaj12Implementation.java b/core/src/main/java/org/springframework/ws/soap/saaj/Saaj12Implementation.java index 185ba4ec..26757aff 100644 --- a/core/src/main/java/org/springframework/ws/soap/saaj/Saaj12Implementation.java +++ b/core/src/main/java/org/springframework/ws/soap/saaj/Saaj12Implementation.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ import org.springframework.ws.soap.saaj.support.SaajUtils; * * @author Arjen Poutsma */ -public class Saaj12Implementation extends SaajImplementation { +class Saaj12Implementation extends SaajImplementation { private static final Saaj12Implementation INSTANCE = new Saaj12Implementation(); diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/Saaj13Implementation.java b/core/src/main/java/org/springframework/ws/soap/saaj/Saaj13Implementation.java index 2bd0396c..ea764467 100644 --- a/core/src/main/java/org/springframework/ws/soap/saaj/Saaj13Implementation.java +++ b/core/src/main/java/org/springframework/ws/soap/saaj/Saaj13Implementation.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ import javax.xml.soap.SOAPHeaderElement; * * @author Arjen Poutsma */ -public class Saaj13Implementation extends SaajImplementation { +class Saaj13Implementation extends SaajImplementation { private static final Saaj13Implementation INSTANCE = new Saaj13Implementation(); diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/SaajImplementation.java b/core/src/main/java/org/springframework/ws/soap/saaj/SaajImplementation.java index f1d935b9..1b1f4dc0 100644 --- a/core/src/main/java/org/springframework/ws/soap/saaj/SaajImplementation.java +++ b/core/src/main/java/org/springframework/ws/soap/saaj/SaajImplementation.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,12 +55,11 @@ import org.springframework.ws.transport.TransportOutputStream; */ abstract class SaajImplementation { + /** Protected constructor to prevent instantiation. */ protected SaajImplementation() { } - /** - * Returns the singleton instance for the version of SAAJ in use. - */ + /** Returns the singleton instance for the version of SAAJ in use. */ public static SaajImplementation getImplementation() { if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_12) { return Saaj12Implementation.getInstance(); @@ -73,58 +72,121 @@ abstract class SaajImplementation { } } + /** Returns the name of the given element. */ public abstract QName getName(SOAPElement element); + /** Returns the readable Source of the given element. */ public Source getSource(SOAPElement element) { return new DOMSource(element); } + /** Returns the writable Result of the given element. */ public Result getResult(SOAPElement element) { return new DOMResult(element); } + /** Returns the envelope of the given message. */ public SOAPEnvelope getEnvelope(SOAPMessage message) throws SOAPException { return message.getSOAPPart().getEnvelope(); } + /** Returns the header of the given envelope. */ public SOAPHeader getHeader(SOAPEnvelope envelope) throws SOAPException { return envelope.getHeader(); } + /** Returns the body of the given envelope. */ public SOAPBody getBody(SOAPEnvelope envelope) throws SOAPException { return envelope.getBody(); } + /** Returns all header elements. */ + public Iterator examineAllHeaderElements(SOAPHeader header) { + return header.examineAllHeaderElements(); + } + + /** Returns all header elements for which the must understand attribute is true, given the actor or role. */ + public Iterator examineMustUnderstandHeaderElements(SOAPHeader header, String actorOrRole) { + return header.examineMustUnderstandHeaderElements(actorOrRole); + } + + public abstract SOAPHeaderElement addHeaderElement(SOAPHeader header, QName name) throws SOAPException; + + /** Returns the SOAP 1.1 actor or SOAP 1.2 role attribute for the given header element. */ public String getActorOrRole(SOAPHeaderElement headerElement) { return headerElement.getActor(); } + /** Sets the SOAP 1.1 actor or SOAP 1.2 role attribute for the given header element. */ public void setActorOrRole(SOAPHeaderElement headerElement, String actorOrRole) { headerElement.setActor(actorOrRole); } + /** Gets the must understand attribute for the given header element. */ public boolean getMustUnderstand(SOAPHeaderElement headerElement) { return headerElement.getMustUnderstand(); } + /** Sets the must understand attribute for the given header element. */ public void setMustUnderstand(SOAPHeaderElement headerElement, boolean mustUnderstand) { headerElement.setMustUnderstand(mustUnderstand); } + /** Returns true if the body has a fault, false otherwise. */ + public boolean hasFault(SOAPBody body) { + return body.hasFault(); + } + + /** Returns the fault for the given body, if any. */ + public SOAPFault getFault(SOAPBody body) { + return body.getFault(); + } + + /** Adds a fault to the given body. */ + public abstract SOAPFault addFault(SOAPBody body, QName faultCode, String faultString, Locale locale) + throws SOAPException; + + /** Returns the fault code for the given fault. */ public abstract QName getFaultCode(SOAPFault fault); + /** Returns the actor for the given fault. */ public String getFaultActor(SOAPFault fault) { return fault.getFaultActor(); } + /** Sets the actor for the given fault. */ public void setFaultActor(SOAPFault fault, String actorOrRole) throws SOAPException { fault.setFaultActor(actorOrRole); } + /** Returns the fault string for the given fault. */ + public String getFaultString(SOAPFault fault) { + return fault.getFaultString(); + } + + /** Returns the fault string language for the given fault. */ + public Locale getFaultStringLocale(SOAPFault fault) { + return fault.getFaultStringLocale(); + } + + /** Returns the fault detail for the given fault. */ + public Detail getFaultDetail(SOAPFault fault) { + return fault.getDetail(); + } + + /** Adds a fault detail for the given fault. */ + public Detail addFaultDetail(SOAPFault fault) throws SOAPException { + return fault.addDetail(); + } + + /** Adds a detail entry to the given detail. */ + public abstract DetailEntry addDetailEntry(Detail detail, QName name) throws SOAPException; + public void addTextNode(DetailEntry detailEntry, String text) throws SOAPException { detailEntry.addTextNode(text); } + /** Returns an iteration over all detail entries. */ public Iterator getDetailEntries(Detail detail) { return detail.getDetailEntries(); } @@ -139,32 +201,12 @@ abstract class SaajImplementation { return null; } - public boolean hasFault(SOAPBody body) { - return body.hasFault(); - } - - public SOAPFault getFault(SOAPBody body) { - return body.getFault(); - } - public abstract boolean isSoap11(SOAPElement element); public void removeContents(SOAPElement element) { element.removeContents(); } - public abstract DetailEntry addDetailEntry(Detail detail, QName name) throws SOAPException; - - public Iterator examineAllHeaderElements(SOAPHeader header) { - return header.examineAllHeaderElements(); - } - - public Iterator examineMustUnderstandHeaderElements(SOAPHeader header, String actorOrRole) { - return header.examineMustUnderstandHeaderElements(actorOrRole); - } - - public abstract SOAPHeaderElement addHeaderElement(SOAPHeader header, QName name) throws SOAPException; - public abstract String getFaultRole(SOAPFault fault); public abstract void setFaultRole(SOAPFault fault, String role) throws SOAPException; @@ -174,22 +216,6 @@ abstract class SaajImplementation { public abstract SOAPHeaderElement addUpgradeHeaderElement(SOAPHeader header, String[] supportedSoapUris) throws SOAPException; - public Detail getFaultDetail(SOAPFault fault) { - return fault.getDetail(); - } - - public Detail addFaultDetail(SOAPFault fault) throws SOAPException { - return fault.addDetail(); - } - - public String getFaultString(SOAPFault fault) { - return fault.getFaultString(); - } - - public Locale getFaultStringLocale(SOAPFault fault) { - return fault.getFaultStringLocale(); - } - public abstract Iterator getFaultSubcodes(SOAPFault fault); public abstract void appendFaultSubcode(SOAPFault fault, QName subcode) throws SOAPException; @@ -202,9 +228,6 @@ abstract class SaajImplementation { public abstract void setFaultReasonText(SOAPFault fault, Locale locale, String text) throws SOAPException; - public abstract SOAPFault addFault(SOAPBody body, QName faultCode, String faultString, Locale locale) - throws SOAPException; - public void writeTo(SOAPMessage message, OutputStream outputStream) throws SOAPException, IOException { if (message.saveRequired()) { message.saveChanges(); diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoap12Body.java b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoap12Body.java index 96eec751..8d938d56 100644 --- a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoap12Body.java +++ b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoap12Body.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoap12Header.java b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoap12Header.java index 493f7b9e..3aefdbdb 100644 --- a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoap12Header.java +++ b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoap12Header.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapBody.java b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapBody.java index 596bbbed..65e058ac 100644 --- a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapBody.java +++ b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapBody.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapFaultDetail.java b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapFaultDetail.java index 5ad966c2..3b9d351d 100644 --- a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapFaultDetail.java +++ b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapFaultDetail.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapHeader.java b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapHeader.java index cbe6fd01..620358f1 100644 --- a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapHeader.java +++ b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapHeader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import javax.xml.namespace.QName; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPHeader; import javax.xml.soap.SOAPHeaderElement; +import javax.xml.transform.Result; import org.springframework.util.Assert; import org.springframework.ws.soap.SoapHeader; @@ -62,6 +63,10 @@ class SaajSoapHeader extends SaajSoapElement implements SoapHeader { return (SOAPHeader) getSaajElement(); } + public Result getResult() { + return getImplementation().getResult(getSaajHeader()); + } + private static class SaajSoapHeaderElementIterator implements Iterator { private final Iterator iterator; diff --git a/core/src/test/java/org/springframework/ws/soap/AbstractSoapHeaderTestCase.java b/core/src/test/java/org/springframework/ws/soap/AbstractSoapHeaderTestCase.java index 070fc323..9ba3a509 100644 --- a/core/src/test/java/org/springframework/ws/soap/AbstractSoapHeaderTestCase.java +++ b/core/src/test/java/org/springframework/ws/soap/AbstractSoapHeaderTestCase.java @@ -89,12 +89,21 @@ public abstract class AbstractSoapHeaderTestCase extends XMLTestCase { assertFalse("header element iterator has too many elements", iterator.hasNext()); } + public void testGetResult() throws Exception { + String content = + ""; + transformer.transform(new StringSource(content), soapHeader.getResult()); + Iterator iterator = soapHeader.examineAllHeaderElements(); + assertTrue("Header has no children", iterator.hasNext()); + SoapHeaderElement headerElement = (SoapHeaderElement) iterator.next(); + assertFalse("Header has too many children", iterator.hasNext()); + assertHeaderElementEqual(headerElement, content); + } + protected void assertHeaderElementEqual(SoapHeaderElement headerElement, String expected) throws Exception { StringResult result = new StringResult(); transformer.transform(headerElement.getSource(), result); - assertXMLEqual("Invalid contents of header element", - "", - result.toString()); + assertXMLEqual("Invalid contents of header element", expected, result.toString()); } } diff --git a/core/src/test/java/org/springframework/ws/soap/axiom/AxiomSoap11HeaderTest.java b/core/src/test/java/org/springframework/ws/soap/axiom/AxiomSoap11HeaderTest.java index 172bc045..68df5718 100644 --- a/core/src/test/java/org/springframework/ws/soap/axiom/AxiomSoap11HeaderTest.java +++ b/core/src/test/java/org/springframework/ws/soap/axiom/AxiomSoap11HeaderTest.java @@ -13,4 +13,6 @@ public class AxiomSoap11HeaderTest extends AbstractSoap11HeaderTestCase { return axiomSoapMessage.getSoapHeader(); } + public void testGetResult() throws Exception { + } } diff --git a/core/src/test/java/org/springframework/ws/soap/axiom/AxiomSoap12HeaderTest.java b/core/src/test/java/org/springframework/ws/soap/axiom/AxiomSoap12HeaderTest.java index 0241de06..2be723d4 100644 --- a/core/src/test/java/org/springframework/ws/soap/axiom/AxiomSoap12HeaderTest.java +++ b/core/src/test/java/org/springframework/ws/soap/axiom/AxiomSoap12HeaderTest.java @@ -29,4 +29,6 @@ public class AxiomSoap12HeaderTest extends AbstractSoap12HeaderTestCase { return axiomSoapMessage.getSoapHeader(); } + public void testGetResult() throws Exception { + } } diff --git a/core/src/test/java/org/springframework/ws/soap/saaj/AbstractSaajImplementationTestCase.java b/core/src/test/java/org/springframework/ws/soap/saaj/AbstractSaajImplementationTestCase.java new file mode 100644 index 00000000..0b7d43c3 --- /dev/null +++ b/core/src/test/java/org/springframework/ws/soap/saaj/AbstractSaajImplementationTestCase.java @@ -0,0 +1,272 @@ +/* + * Copyright 2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ws.soap.saaj; + +import java.io.ByteArrayOutputStream; +import java.util.Iterator; +import java.util.Locale; +import javax.activation.DataSource; +import javax.mail.util.ByteArrayDataSource; +import javax.xml.namespace.QName; +import javax.xml.soap.AttachmentPart; +import javax.xml.soap.Detail; +import javax.xml.soap.DetailEntry; +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPBody; +import javax.xml.soap.SOAPEnvelope; +import javax.xml.soap.SOAPException; +import javax.xml.soap.SOAPFault; +import javax.xml.soap.SOAPHeader; +import javax.xml.soap.SOAPHeaderElement; +import javax.xml.soap.SOAPMessage; +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 { + + private SaajImplementation implementation; + + private SOAPMessage message; + + protected final void setUp() throws Exception { + implementation = createSaajImplementation(); + MessageFactory messageFactory = MessageFactory.newInstance(); + message = messageFactory.createMessage(); + } + + protected abstract SaajImplementation createSaajImplementation(); + + public void testGetName() throws Exception { + QName name = implementation.getName(message.getSOAPBody()); + assertEquals("Invalid name", SoapVersion.SOAP_11.getBodyName(), name); + } + + public void testGetSource() throws Exception { + Source source = implementation.getSource(message.getSOAPBody()); + assertNotNull("No source returned", source); + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + StringResult result = new StringResult(); + transformer.transform(source, result); + assertXMLEqual("", result.toString()); + } + + public void testGetResult() throws Exception { + Source source = new StringSource(""); + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform(source, implementation.getResult(message.getSOAPBody())); + } + + public void testGetEnvelope() throws Exception { + SOAPEnvelope envelope = implementation.getEnvelope(message); + assertEquals("Invalid envelope", message.getSOAPPart().getEnvelope(), envelope); + } + + public void testGetHeader() throws Exception { + SOAPHeader header = implementation.getHeader(message.getSOAPPart().getEnvelope()); + assertEquals("Invalid header", message.getSOAPHeader(), header); + } + + public void testGetBody() throws Exception { + SOAPBody body = implementation.getBody(message.getSOAPPart().getEnvelope()); + assertEquals("Invalid body", message.getSOAPBody(), body); + } + + public void testExampleAllHeaderElements() throws Exception { + Iterator iterator = implementation.examineAllHeaderElements(message.getSOAPHeader()); + assertFalse("Header elements present", iterator.hasNext()); + createHeaderElement(); + iterator = implementation.examineAllHeaderElements(message.getSOAPHeader()); + assertTrue("No header elements present", iterator.hasNext()); + } + + public void testExampleMustUnderstandHeaderElements() throws Exception { + SOAPHeaderElement headerElement = createHeaderElement(); + headerElement.setMustUnderstand(true); + Iterator iterator = implementation.examineAllHeaderElements(message.getSOAPHeader()); + assertTrue("No header elements present", iterator.hasNext()); + } + + public void testAddHeaderElement() throws Exception { + SOAPHeaderElement headerElement = implementation + .addHeaderElement(message.getSOAPHeader(), new QName("http://springframework.org/spring-ws", "Header")); + assertNotNull("No header element returned", headerElement); + assertEquals("Invalid namespace", "http://springframework.org/spring-ws", headerElement.getNamespaceURI()); + assertEquals("Invalid local name", "Header", headerElement.getLocalName()); + } + + 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)); + } + + private SOAPHeaderElement createHeaderElement() throws SOAPException { + SOAPHeader header = message.getSOAPHeader(); + return header.addHeaderElement(new QName("http://springframework.org/spring-ws", "Header")); + } + + 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); + } + + public void testGetMustUnderstand() throws Exception { + SOAPHeaderElement headerElement = createHeaderElement(); + headerElement.setMustUnderstand(true); + assertTrue("Invalid mustUnderstand", implementation.getMustUnderstand(headerElement)); + } + + public void testSetMustUnderstand() throws Exception { + SOAPHeaderElement headerElement = createHeaderElement(); + implementation.setMustUnderstand(headerElement, true); + assertTrue("Invalid mustUnderstand", headerElement.getMustUnderstand()); + } + + public void testHasFault() throws Exception { + assertFalse("Body has fault", implementation.hasFault(message.getSOAPBody())); + message.getSOAPBody().addFault(); + assertTrue("Body has no fault", implementation.hasFault(message.getSOAPBody())); + } + + public void testGetFault() throws Exception { + assertNull("Body has fault", implementation.getFault(message.getSOAPBody())); + message.getSOAPBody().addFault(); + assertNotNull("Body has no fault", implementation.getFault(message.getSOAPBody())); + } + + public void testAddFault() throws Exception { + SOAPBody body = message.getSOAPBody(); + implementation + .addFault(body, new QName("http://springframework.org/spring-ws", "Fault"), "Fault", Locale.ENGLISH); + assertTrue("No Fault added", body.hasFault()); + } + + public void testGetFaultCode() throws Exception { + SOAPFault fault = createFault(); + assertEquals("Invalid fault code", new QName("http://springframework.org/spring-ws", "Fault"), + implementation.getFaultCode(fault)); + } + + private SOAPFault createFault() throws SOAPException { + SOAPBody body = message.getSOAPBody(); + return body.addFault(new QName("http://springframework.org/spring-ws", "Fault"), "Fault", Locale.ENGLISH); + } + + 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)); + } + + 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()); + } + + public void testGetFaultString() throws Exception { + SOAPFault fault = createFault(); + String faultString = "FaultString"; + fault.setFaultString(faultString); + assertEquals("Invalid fault string", faultString, implementation.getFaultString(fault)); + } + + public void testGetFaultStringLocale() throws Exception { + SOAPFault fault = createFault(); + assertEquals("Invalid fault string", Locale.ENGLISH, implementation.getFaultStringLocale(fault)); + } + + public void testGetFaultDetail() throws Exception { + SOAPFault fault = createFault(); + assertNull("Fault Detail returned", implementation.getFaultDetail(fault)); + fault.addDetail(); + assertNotNull("No Fault Detail returned", implementation.getFaultDetail(fault)); + } + + public void testAddFaultDetail() throws Exception { + SOAPFault fault = createFault(); + Detail detail = implementation.addFaultDetail(fault); + assertEquals("Invalid fault detail", fault.getDetail(), detail); + } + + 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()); + } + + public void testAddTextNode() throws Exception { + SOAPFault fault = createFault(); + Detail detail = fault.addDetail(); + DetailEntry detailEntry = + detail.addDetailEntry(new QName("http://springframework.org/spring-ws", "DetailEntry")); + implementation.addTextNode(detailEntry, "text"); + assertEquals("Invalid text", "text", detailEntry.getTextContent()); + } + + public void testGetDetailEntries() throws Exception { + SOAPFault fault = createFault(); + Detail detail = fault.addDetail(); + Iterator iterator = implementation.getDetailEntries(detail); + assertFalse("Detail entries found", iterator.hasNext()); + DetailEntry detailEntry = + detail.addDetailEntry(new QName("http://springframework.org/spring-ws", "DetailEntry")); + 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()); + } + + public void testWriteTo() throws Exception { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + implementation.writeTo(message, os); + assertTrue("Nothing written", os.toByteArray().length > 0); + } + + public void testGetAttachments() throws Exception { + Iterator iterator = implementation.getAttachments(message); + 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()); + } + + public void testAddAttachmentPart() throws Exception { + DataSource dataSource = new ByteArrayDataSource("data", "text"); + AttachmentPart attachmentPart = implementation.addAttachmentPart(message, dataSource); + assertNotNull("No attachment part", attachmentPart); + } + +} \ No newline at end of file diff --git a/core/src/test/java/org/springframework/ws/soap/saaj/Saaj12ImplementationTest.java b/core/src/test/java/org/springframework/ws/soap/saaj/Saaj12ImplementationTest.java new file mode 100644 index 00000000..20284973 --- /dev/null +++ b/core/src/test/java/org/springframework/ws/soap/saaj/Saaj12ImplementationTest.java @@ -0,0 +1,25 @@ +/* + * Copyright 2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ws.soap.saaj; + +public class Saaj12ImplementationTest extends AbstractSaajImplementationTestCase { + + protected SaajImplementation createSaajImplementation() { + return Saaj12Implementation.getImplementation(); + } + +} \ No newline at end of file diff --git a/core/src/test/java/org/springframework/ws/soap/saaj/Saaj13ImplementationTest.java b/core/src/test/java/org/springframework/ws/soap/saaj/Saaj13ImplementationTest.java new file mode 100644 index 00000000..86b56cea --- /dev/null +++ b/core/src/test/java/org/springframework/ws/soap/saaj/Saaj13ImplementationTest.java @@ -0,0 +1,25 @@ +/* + * Copyright 2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ws.soap.saaj; + +public class Saaj13ImplementationTest extends AbstractSaajImplementationTestCase { + + protected SaajImplementation createSaajImplementation() { + return Saaj13Implementation.getImplementation(); + } + +}