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.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 AbstractSoap12MessageFactoryTestCase extends
032: AbstractSoapMessageFactoryTestCase {
033:
034: public void testCreateEmptyMessage() 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_12,
040: soapMessage.getVersion());
041: }
042:
043: public void testCreateSoapMessageNoAttachment() throws Exception {
044: InputStream is = AbstractSoap12MessageFactoryTestCase.class
045: .getResourceAsStream("soap12.xml");
046: final Properties headers = new Properties();
047: headers.setProperty("Content-Type", "application/soap+xml");
048: TransportInputStream tis = new MockTransportInputStream(is,
049: headers);
050:
051: WebServiceMessage message = messageFactory
052: .createWebServiceMessage(tis);
053: assertTrue("Not a SoapMessage", message instanceof SoapMessage);
054: SoapMessage soapMessage = (SoapMessage) message;
055: assertEquals("Invalid soap version", SoapVersion.SOAP_12,
056: soapMessage.getVersion());
057: assertFalse("Message is a XOP pacakge", soapMessage
058: .isXopPackage());
059: }
060:
061: public void testCreateSoapMessageSwA() throws Exception {
062: InputStream is = AbstractSoap12MessageFactoryTestCase.class
063: .getResourceAsStream("soap12-attachment.bin");
064: Properties headers = new Properties();
065: headers.setProperty("Content-Type", "multipart/related;"
066: + "type=\"application/soap+xml\";"
067: + "boundary=\"----=_Part_0_11416420.1149699787554\"");
068: TransportInputStream tis = new MockTransportInputStream(is,
069: headers);
070:
071: WebServiceMessage message = messageFactory
072: .createWebServiceMessage(tis);
073: assertTrue("Not a SoapMessage", message instanceof SoapMessage);
074: SoapMessage soapMessage = (SoapMessage) message;
075: assertEquals("Invalid soap version", SoapVersion.SOAP_12,
076: soapMessage.getVersion());
077: assertFalse("Message is a XOP package", soapMessage
078: .isXopPackage());
079: Attachment attachment = soapMessage
080: .getAttachment("interface21");
081: assertNotNull("No attachment read", attachment);
082: }
083:
084: public void testCreateSoapMessageMtom() throws Exception {
085: InputStream is = AbstractSoap12MessageFactoryTestCase.class
086: .getResourceAsStream("soap12-mtom.bin");
087: Properties headers = new Properties();
088: headers
089: .setProperty(
090: "Content-Type",
091: "multipart/related;"
092: + "start-info=\"application/soap+xml\";"
093: + "type=\"application/xop+xml\";"
094: + "start=\"<0.urn:uuid:40864869929B855F971176851454456@apache.org>\";"
095: + "boundary=\"MIMEBoundaryurn_uuid_40864869929B855F971176851454455\"");
096: TransportInputStream tis = new MockTransportInputStream(is,
097: headers);
098:
099: WebServiceMessage message = messageFactory
100: .createWebServiceMessage(tis);
101: assertTrue("Not a SoapMessage", message instanceof SoapMessage);
102: SoapMessage soapMessage = (SoapMessage) message;
103: assertEquals("Invalid soap version", SoapVersion.SOAP_12,
104: soapMessage.getVersion());
105: assertTrue("Message is not a XOP pacakge", soapMessage
106: .isXopPackage());
107: Iterator iter = soapMessage.getAttachments();
108: assertTrue("No attachments read", iter.hasNext());
109:
110: Attachment attachment = soapMessage
111: .getAttachment("<1.urn:uuid:40864869929B855F971176851454452@apache.org>");
112: assertNotNull("No attachment read", attachment);
113: }
114:
115: }
|