1   /*
2    * Copyright 2006 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.soap12;
18  
19  import java.io.InputStream;
20  import java.util.Iterator;
21  import java.util.Properties;
22  
23  import org.springframework.ws.WebServiceMessage;
24  import org.springframework.ws.mime.Attachment;
25  import org.springframework.ws.soap.AbstractSoapMessageFactoryTestCase;
26  import org.springframework.ws.soap.SoapMessage;
27  import org.springframework.ws.soap.SoapVersion;
28  import org.springframework.ws.transport.MockTransportInputStream;
29  import org.springframework.ws.transport.TransportInputStream;
30  import org.springframework.ws.transport.TransportConstants;
31  
32  public abstract class AbstractSoap12MessageFactoryTestCase extends AbstractSoapMessageFactoryTestCase {
33  
34      public void testCreateEmptyMessage() throws Exception {
35          WebServiceMessage message = messageFactory.createWebServiceMessage();
36          assertTrue("Not a SoapMessage", message instanceof SoapMessage);
37          SoapMessage soapMessage = (SoapMessage) message;
38          assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
39      }
40  
41      public void testCreateSoapMessageNoAttachment() throws Exception {
42          InputStream is = AbstractSoap12MessageFactoryTestCase.class.getResourceAsStream("soap12.xml");
43          final Properties headers = new Properties();
44          String soapAction = "\"http://springframework.org/spring-ws/Action\"";
45          headers.setProperty(TransportConstants.HEADER_CONTENT_TYPE, "application/soap+xml; action=" + soapAction);
46          TransportInputStream tis = new MockTransportInputStream(is, headers);
47  
48          WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
49          assertTrue("Not a SoapMessage", message instanceof SoapMessage);
50          SoapMessage soapMessage = (SoapMessage) message;
51          assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
52          assertEquals("Invalid soap action", soapAction, soapMessage.getSoapAction());
53          assertFalse("Message is a XOP pacakge", soapMessage.isXopPackage());
54      }
55  
56      public void testCreateSoapMessageSwA() throws Exception {
57          InputStream is = AbstractSoap12MessageFactoryTestCase.class.getResourceAsStream("soap12-attachment.bin");
58          Properties headers = new Properties();
59          headers.setProperty("Content-Type", "multipart/related;" + "type=\"application/soap+xml\";" +
60                  "boundary=\"----=_Part_0_11416420.1149699787554\"");
61          TransportInputStream tis = new MockTransportInputStream(is, headers);
62  
63          WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
64          assertTrue("Not a SoapMessage", message instanceof SoapMessage);
65          SoapMessage soapMessage = (SoapMessage) message;
66          assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
67          assertFalse("Message is a XOP package", soapMessage.isXopPackage());
68          Attachment attachment = soapMessage.getAttachment("interface21");
69          assertNotNull("No attachment read", attachment);
70      }
71  
72      public void testCreateSoapMessageMtom() throws Exception {
73          InputStream is = AbstractSoap12MessageFactoryTestCase.class.getResourceAsStream("soap12-mtom.bin");
74          Properties headers = new Properties();
75          headers.setProperty("Content-Type", "multipart/related;" + "start-info=\"application/soap+xml\";" +
76                  "type=\"application/xop+xml\";" + "start=\"<0.urn:uuid:[email protected]>\";" +
77                  "boundary=\"MIMEBoundaryurn_uuid_40864869929B855F971176851454455\"");
78          TransportInputStream tis = new MockTransportInputStream(is, headers);
79  
80          WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
81          assertTrue("Not a SoapMessage", message instanceof SoapMessage);
82          SoapMessage soapMessage = (SoapMessage) message;
83          assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
84          assertTrue("Message is not a XOP pacakge", soapMessage.isXopPackage());
85          Iterator iter = soapMessage.getAttachments();
86          assertTrue("No attachments read", iter.hasNext());
87  
88          Attachment attachment = soapMessage.getAttachment("<1.urn:uuid:[email protected]>");
89          assertNotNull("No attachment read", attachment);
90      }
91  
92  
93  }