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.io.InputStream;
020: import java.util.Iterator;
021: import java.util.Properties;
022:
023: import org.springframework.ws.WebServiceMessage;
024: import org.springframework.ws.mime.Attachment;
025: import org.springframework.ws.soap.AbstractSoapMessageFactoryTestCase;
026: import org.springframework.ws.soap.SoapMessage;
027: import org.springframework.ws.soap.SoapVersion;
028: import org.springframework.ws.transport.MockTransportInputStream;
029: import org.springframework.ws.transport.TransportInputStream;
030:
031: public abstract class AbstractSoap11MessageFactoryTestCase extends
032: AbstractSoapMessageFactoryTestCase {
033:
034: public void testCreateEmptySoap11Message() throws Exception {
035: WebServiceMessage message = messageFactory
036: .createWebServiceMessage();
037: assertTrue("Not a SoapMessage", message instanceof SoapMessage);
038: SoapMessage soapMessage = (SoapMessage) message;
039: assertEquals("Invalid soap version", SoapVersion.SOAP_11,
040: soapMessage.getVersion());
041: }
042:
043: public void testCreateSoapMessageNoAttachment() throws Exception {
044: InputStream is = AbstractSoap11MessageFactoryTestCase.class
045: .getResourceAsStream("soap11.xml");
046: final Properties headers = new Properties();
047: headers.setProperty("Content-Type", "text/xml");
048: String soapAction = "http://springframework.org/spring-ws/Action";
049: headers.setProperty("SOAPAction", soapAction);
050: TransportInputStream tis = new MockTransportInputStream(is,
051: headers);
052:
053: WebServiceMessage message = messageFactory
054: .createWebServiceMessage(tis);
055: assertTrue("Not a SoapMessage", message instanceof SoapMessage);
056: SoapMessage soapMessage = (SoapMessage) message;
057: assertEquals("Invalid soap version", SoapVersion.SOAP_11,
058: soapMessage.getVersion());
059: assertEquals("Invalid soap action", soapAction, soapMessage
060: .getSoapAction());
061: assertFalse("Message a XOP pacakge", soapMessage.isXopPackage());
062: }
063:
064: public void testCreateSoapMessageSwA() throws Exception {
065: InputStream is = AbstractSoap11MessageFactoryTestCase.class
066: .getResourceAsStream("soap11-attachment.bin");
067: Properties headers = new Properties();
068: headers.setProperty("Content-Type", "multipart/related;"
069: + "type=\"text/xml\";"
070: + "boundary=\"----=_Part_0_11416420.1149699787554\"");
071: TransportInputStream tis = new MockTransportInputStream(is,
072: headers);
073:
074: WebServiceMessage message = messageFactory
075: .createWebServiceMessage(tis);
076: assertTrue("Not a SoapMessage", message instanceof SoapMessage);
077: SoapMessage soapMessage = (SoapMessage) message;
078: assertEquals("Invalid soap version", SoapVersion.SOAP_11,
079: soapMessage.getVersion());
080: assertFalse("Message a XOP pacakge", soapMessage.isXopPackage());
081: Iterator iter = soapMessage.getAttachments();
082: assertTrue("No attachments read", iter.hasNext());
083: Attachment attachment = soapMessage
084: .getAttachment("interface21");
085: assertNotNull("No attachment read", attachment);
086: assertEquals("Invalid content id", "interface21", attachment
087: .getContentId());
088: }
089:
090: public void testCreateSoapMessageMtom() throws Exception {
091: InputStream is = AbstractSoap11MessageFactoryTestCase.class
092: .getResourceAsStream("soap11-mtom.bin");
093: Properties headers = new Properties();
094: headers
095: .setProperty(
096: "Content-Type",
097: "multipart/related;"
098: + "start-info=\"text/xml\";"
099: + "type=\"application/xop+xml\";"
100: + "start=\"<0.urn:uuid:492264AB42E57108E01176731445508@apache.org>\";"
101: + "boundary=\"MIMEBoundaryurn_uuid_492264AB42E57108E01176731445507\"");
102: TransportInputStream tis = new MockTransportInputStream(is,
103: headers);
104:
105: WebServiceMessage message = messageFactory
106: .createWebServiceMessage(tis);
107: assertTrue("Not a SoapMessage", message instanceof SoapMessage);
108: SoapMessage soapMessage = (SoapMessage) message;
109: assertEquals("Invalid soap version", SoapVersion.SOAP_11,
110: soapMessage.getVersion());
111: assertTrue("Message not a XOP pacakge", soapMessage
112: .isXopPackage());
113: Iterator iter = soapMessage.getAttachments();
114: assertTrue("No attachments read", iter.hasNext());
115:
116: Attachment attachment = soapMessage
117: .getAttachment("<1.urn:uuid:492264AB42E57108E01176731445504@apache.org>");
118: assertNotNull("No attachment read", attachment);
119: }
120:
121: public void testCreateSoapMessageMtomWeirdStartInfo()
122: throws Exception {
123: InputStream is = AbstractSoap11MessageFactoryTestCase.class
124: .getResourceAsStream("soap11-mtom.bin");
125: Properties headers = new Properties();
126: headers
127: .setProperty(
128: "Content-Type",
129: "multipart/related;"
130: + "startinfo=\"text/xml\";"
131: + "type=\"application/xop+xml\";"
132: + "start=\"<0.urn:uuid:492264AB42E57108E01176731445508@apache.org>\";"
133: + "boundary=\"MIMEBoundaryurn_uuid_492264AB42E57108E01176731445507\"");
134: TransportInputStream tis = new MockTransportInputStream(is,
135: headers);
136:
137: WebServiceMessage message = messageFactory
138: .createWebServiceMessage(tis);
139: assertTrue("Not a SoapMessage", message instanceof SoapMessage);
140: SoapMessage soapMessage = (SoapMessage) message;
141: assertEquals("Invalid soap version", SoapVersion.SOAP_11,
142: soapMessage.getVersion());
143: assertTrue("Message not a XOP pacakge", soapMessage
144: .isXopPackage());
145: Iterator iter = soapMessage.getAttachments();
146: assertTrue("No attachments read", iter.hasNext());
147:
148: Attachment attachment = soapMessage
149: .getAttachment("<1.urn:uuid:492264AB42E57108E01176731445504@apache.org>");
150: assertNotNull("No attachment read", attachment);
151: }
152:
153: }
|