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.soap11;
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 AbstractSoap11HeaderTestCase extends
028: AbstractSoapHeaderTestCase {
029:
030: private static final String PREFIX = "spring";
031:
032: public void testGetType() {
033: assertTrue("Invalid type returned",
034: soapHeader instanceof Soap11Header);
035: }
036:
037: public void testGetName() throws Exception {
038: assertEquals("Invalid qualified name",
039: new QName(
040: SoapVersion.SOAP_11.getEnvelopeNamespaceUri(),
041: "Header"), soapHeader.getName());
042: }
043:
044: public void testGetSource() throws Exception {
045: StringResult result = new StringResult();
046: transformer.transform(soapHeader.getSource(), result);
047: assertXMLEqual(
048: "Invalid contents of header",
049: "<SOAP-ENV:Header xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' />",
050: result.toString());
051: }
052:
053: public void testExamineHeaderElementsToProcessActors()
054: throws Exception {
055: QName qName = new QName(NAMESPACE, "localName1", PREFIX);
056: SoapHeaderElement headerElement = soapHeader
057: .addHeaderElement(qName);
058: headerElement.setActorOrRole("role1");
059: qName = new QName(NAMESPACE, "localName2", PREFIX);
060: headerElement = soapHeader.addHeaderElement(qName);
061: headerElement.setActorOrRole("role2");
062: qName = new QName(NAMESPACE, "localName3", PREFIX);
063: headerElement = soapHeader.addHeaderElement(qName);
064: headerElement.setActorOrRole(SoapVersion.SOAP_11
065: .getNextActorOrRoleUri());
066: Iterator iterator = ((Soap11Header) soapHeader)
067: .examineHeaderElementsToProcess(new String[] { "role1" });
068: assertNotNull("header element iterator is null", iterator);
069: assertTrue("header element iterator has no elements", iterator
070: .hasNext());
071: checkHeaderElement((SoapHeaderElement) iterator.next());
072: assertTrue("header element iterator has no elements", iterator
073: .hasNext());
074: checkHeaderElement((SoapHeaderElement) iterator.next());
075: assertFalse("header element iterator has too many elements",
076: iterator.hasNext());
077: }
078:
079: public void testExamineHeaderElementsToProcessNoActors()
080: throws Exception {
081: QName qName = new QName(NAMESPACE, "localName1", PREFIX);
082: SoapHeaderElement headerElement = soapHeader
083: .addHeaderElement(qName);
084: headerElement.setActorOrRole("");
085: qName = new QName(NAMESPACE, "localName2", PREFIX);
086: headerElement = soapHeader.addHeaderElement(qName);
087: headerElement.setActorOrRole("role1");
088: qName = new QName(NAMESPACE, "localName3", PREFIX);
089: headerElement = soapHeader.addHeaderElement(qName);
090: headerElement.setActorOrRole(SoapVersion.SOAP_11
091: .getNextActorOrRoleUri());
092: Iterator iterator = ((Soap11Header) soapHeader)
093: .examineHeaderElementsToProcess(new String[0]);
094: assertNotNull("header element iterator is null", iterator);
095: assertTrue("header element iterator has no elements", iterator
096: .hasNext());
097: checkHeaderElement((SoapHeaderElement) iterator.next());
098: assertTrue("header element iterator has no elements", iterator
099: .hasNext());
100: checkHeaderElement((SoapHeaderElement) iterator.next());
101: assertFalse("header element iterator has too many elements",
102: iterator.hasNext());
103: }
104:
105: private void checkHeaderElement(SoapHeaderElement headerElement) {
106: QName name = headerElement.getName();
107: assertTrue("Invalid name on header element", new QName(
108: NAMESPACE, "localName1", PREFIX).equals(name)
109: || new QName(NAMESPACE, "localName3", PREFIX)
110: .equals(name));
111: }
112:
113: }
|