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  
31  public abstract class AbstractSoap12MessageFactoryTestCase extends AbstractSoapMessageFactoryTestCase {
32  
33      public void testCreateEmptyMessage() throws Exception {
34          WebServiceMessage message = messageFactory.createWebServiceMessage();
35          assertTrue("Not a SoapMessage", message instanceof SoapMessage);
36          SoapMessage soapMessage = (SoapMessage) message;
37          assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
38      }
39  
40      public void testCreateSoapMessageNoAttachment() throws Exception {
41          InputStream is = AbstractSoap12MessageFactoryTestCase.class.getResourceAsStream("soap12.xml");
42          final Properties headers = new Properties();
43          headers.setProperty("Content-Type", "application/soap+xml");
44          TransportInputStream tis = new MockTransportInputStream(is, headers);
45  
46          WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
47          assertTrue("Not a SoapMessage", message instanceof SoapMessage);
48          SoapMessage soapMessage = (SoapMessage) message;
49          assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
50          assertFalse("Message is a XOP pacakge", soapMessage.isXopPackage());
51      }
52  
53      public void testCreateSoapMessageSwA() throws Exception {
54          InputStream is = AbstractSoap12MessageFactoryTestCase.class.getResourceAsStream("soap12-attachment.bin");
55          Properties headers = new Properties();
56          headers.setProperty("Content-Type", "multipart/related;" + "type=\"application/soap+xml\";" +
57                  "boundary=\"----=_Part_0_11416420.1149699787554\"");
58          TransportInputStream tis = new MockTransportInputStream(is, headers);
59  
60          WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
61          assertTrue("Not a SoapMessage", message instanceof SoapMessage);
62          SoapMessage soapMessage = (SoapMessage) message;
63          assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
64          assertFalse("Message is a XOP package", soapMessage.isXopPackage());
65          Attachment attachment = soapMessage.getAttachment("interface21");
66          assertNotNull("No attachment read", attachment);
67      }
68  
69      public void testCreateSoapMessageMtom() throws Exception {
70          InputStream is = AbstractSoap12MessageFactoryTestCase.class.getResourceAsStream("soap12-mtom.bin");
71          Properties headers = new Properties();
72          headers.setProperty("Content-Type", "multipart/related;" + "start-info=\"application/soap+xml\";" +
73                  "type=\"application/xop+xml\";" + "start=\"<0.urn:uuid:[email protected]>\";" +
74                  "boundary=\"MIMEBoundaryurn_uuid_40864869929B855F971176851454455\"");
75          TransportInputStream tis = new MockTransportInputStream(is, headers);
76  
77          WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
78          assertTrue("Not a SoapMessage", message instanceof SoapMessage);
79          SoapMessage soapMessage = (SoapMessage) message;
80          assertEquals("Invalid soap version", SoapVersion.SOAP_12, soapMessage.getVersion());
81          assertTrue("Message is not a XOP pacakge", soapMessage.isXopPackage());
82          Iterator iter = soapMessage.getAttachments();
83          assertTrue("No attachments read", iter.hasNext());
84  
85          Attachment attachment = soapMessage.getAttachment("<1.urn:uuid:[email protected]>");
86          assertNotNull("No attachment read", attachment);
87      }
88  
89  
90  }