001: /*
002: * Copyright 2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.soap.soap12;
018:
019: import java.util.Iterator;
020: import javax.xml.namespace.QName;
021:
022: import org.springframework.ws.soap.AbstractSoapHeaderTestCase;
023: import org.springframework.ws.soap.SoapHeaderElement;
024: import org.springframework.ws.soap.SoapVersion;
025: import org.springframework.xml.transform.StringResult;
026:
027: public abstract class AbstractSoap12HeaderTestCase extends
028: AbstractSoapHeaderTestCase {
029:
030: public void testGetType() {
031: assertTrue("Invalid type returned",
032: soapHeader instanceof Soap12Header);
033: }
034:
035: public void testGetName() throws Exception {
036: assertEquals("Invalid qualified name",
037: new QName(
038: SoapVersion.SOAP_12.getEnvelopeNamespaceUri(),
039: "Header"), soapHeader.getName());
040: }
041:
042: public void testGetSource() throws Exception {
043: StringResult result = new StringResult();
044: transformer.transform(soapHeader.getSource(), result);
045: assertXMLEqual(
046: "Invalid contents of header",
047: "<Header xmlns='http://www.w3.org/2003/05/soap-envelope' />",
048: result.toString());
049: }
050:
051: public void testAddNotUnderstood() throws Exception {
052: Soap12Header soap12Header = (Soap12Header) soapHeader;
053: QName headerName = new QName("http://www.springframework.org",
054: "NotUnderstood", "spring-ws");
055: soap12Header.addNotUnderstoodHeaderElement(headerName);
056: StringResult result = new StringResult();
057: transformer.transform(soapHeader.getSource(), result);
058: assertXMLEqual(
059: "Invalid contents of header",
060: "<Header xmlns='http://www.w3.org/2003/05/soap-envelope' >"
061: + "<NotUnderstood qname='spring-ws:NotUnderstood' xmlns:spring-ws='http://www.springframework.org' />"
062: + "</Header>", result.toString());
063: }
064:
065: public void testAddUpgrade() throws Exception {
066: String[] supportedUris = new String[] {
067: "http://schemas.xmlsoap.org/soap/envelope/",
068: "http://www.w3.org/2003/05/soap-envelope" };
069: Soap12Header soap12Header = (Soap12Header) soapHeader;
070: SoapHeaderElement header = soap12Header
071: .addUpgradeHeaderElement(supportedUris);
072: StringResult result = new StringResult();
073: transformer.transform(soapHeader.getSource(), result);
074: assertEquals("Invalid name", header.getName(), new QName(
075: "http://www.w3.org/2003/05/soap-envelope", "Upgrade"));
076: // XMLUnit can't test this:
077: /*
078: assertXMLEqual("Invalid contents of header", "<Header xmlns='http://www.w3.org/2003/05/soap-envelope' >" +
079: "<Upgrade>" +
080: "<SupportedEnvelope xmlns:ns0='http://schemas.xmlsoap.org/soap/envelope/' qname='ns0:Envelope'/>" +
081: "<SupportedEnvelope xmlns:ns1='http://www.w3.org/2003/05/soap-envelope' qname='ns1:Envelope'/>" +
082: "</Upgrade>" +
083: "</Header>", result.toString());
084: */
085: }
086:
087: public void testExamineHeaderElementsToProcessActors()
088: throws Exception {
089: QName qName = new QName(NAMESPACE, "localName1", PREFIX);
090: SoapHeaderElement headerElement = soapHeader
091: .addHeaderElement(qName);
092: headerElement.setActorOrRole("role1");
093: qName = new QName(NAMESPACE, "localName2", PREFIX);
094: headerElement = soapHeader.addHeaderElement(qName);
095: headerElement.setActorOrRole("role2");
096: qName = new QName(NAMESPACE, "localName3", PREFIX);
097: headerElement = soapHeader.addHeaderElement(qName);
098: headerElement.setActorOrRole(SoapVersion.SOAP_12
099: .getNextActorOrRoleUri());
100: Iterator iterator = ((Soap12Header) soapHeader)
101: .examineHeaderElementsToProcess(
102: new String[] { "role1" }, false);
103: assertNotNull("header element iterator is null", iterator);
104: assertTrue("header element iterator has no elements", iterator
105: .hasNext());
106: checkHeaderElement((SoapHeaderElement) iterator.next());
107: assertTrue("header element iterator has no elements", iterator
108: .hasNext());
109: checkHeaderElement((SoapHeaderElement) iterator.next());
110: assertFalse("header element iterator has too many elements",
111: iterator.hasNext());
112: }
113:
114: public void testExamineHeaderElementsToProcessNoActors()
115: throws Exception {
116: QName qName = new QName(NAMESPACE, "localName1", PREFIX);
117: SoapHeaderElement headerElement = soapHeader
118: .addHeaderElement(qName);
119: headerElement.setActorOrRole("");
120: qName = new QName(NAMESPACE, "localName2", PREFIX);
121: headerElement = soapHeader.addHeaderElement(qName);
122: headerElement.setActorOrRole("role1");
123: qName = new QName(NAMESPACE, "localName3", PREFIX);
124: headerElement = soapHeader.addHeaderElement(qName);
125: headerElement.setActorOrRole(SoapVersion.SOAP_12
126: .getNextActorOrRoleUri());
127: Iterator iterator = ((Soap12Header) soapHeader)
128: .examineHeaderElementsToProcess(new String[0], false);
129: assertNotNull("header element iterator is null", iterator);
130: assertTrue("header element iterator has no elements", iterator
131: .hasNext());
132: checkHeaderElement((SoapHeaderElement) iterator.next());
133: assertTrue("header element iterator has no elements", iterator
134: .hasNext());
135: checkHeaderElement((SoapHeaderElement) iterator.next());
136: assertFalse("header element iterator has too many elements",
137: iterator.hasNext());
138: }
139:
140: public void testExamineHeaderElementsToProcessUltimateDestination()
141: throws Exception {
142: QName qName = new QName(NAMESPACE, "localName", PREFIX);
143: SoapHeaderElement headerElement = soapHeader
144: .addHeaderElement(qName);
145: headerElement.setActorOrRole(SoapVersion.SOAP_12
146: .getUltimateReceiverRoleUri());
147: Iterator iterator = ((Soap12Header) soapHeader)
148: .examineHeaderElementsToProcess(
149: new String[] { "role" }, true);
150: assertNotNull("header element iterator is null", iterator);
151: headerElement = (SoapHeaderElement) iterator.next();
152: assertEquals("Invalid name on header element", new QName(
153: NAMESPACE, "localName", PREFIX), headerElement
154: .getName());
155: assertFalse("header element iterator has too many elements",
156: iterator.hasNext());
157: }
158:
159: private void checkHeaderElement(SoapHeaderElement headerElement) {
160: QName name = headerElement.getName();
161: assertTrue("Invalid name on header element", new QName(
162: NAMESPACE, "localName1", PREFIX).equals(name)
163: || new QName(NAMESPACE, "localName3", PREFIX)
164: .equals(name));
165: }
166:
167: }
|