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.ByteArrayOutputStream;
20  
21  import junit.framework.Assert;
22  import org.springframework.core.io.ByteArrayResource;
23  import org.springframework.core.io.ClassPathResource;
24  import org.springframework.core.io.InputStreamSource;
25  import org.springframework.core.io.Resource;
26  import org.springframework.ws.soap.AbstractSoapMessageTestCase;
27  import org.springframework.ws.soap.SoapVersion;
28  import org.springframework.ws.transport.MockTransportOutputStream;
29  
30  public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageTestCase {
31  
32      public void testGetVersion() throws Exception {
33          Assert.assertEquals("Invalid SOAP version", SoapVersion.SOAP_12, soapMessage.getVersion());
34      }
35  
36      protected final Resource[] getSoapSchemas() {
37          return new Resource[]{new ClassPathResource("xml.xsd", AbstractSoap12MessageTestCase.class),
38                  new ClassPathResource("soap12.xsd", AbstractSoap12MessageTestCase.class)};
39      }
40  
41      public void testWriteToTransportOutputStream() throws Exception {
42          final ByteArrayOutputStream bos = new ByteArrayOutputStream();
43          MockTransportOutputStream tos = new MockTransportOutputStream(bos);
44          soapMessage.writeTo(tos);
45          String result = bos.toString("UTF-8");
46  
47          assertXMLEqual("<Envelope xmlns='http://www.w3.org/2003/05/soap-envelope'><Body/></Envelope>", result);
48          String contentType = (String) tos.getHeaders().get("Content-Type");
49          assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_12.getContentType()) != -1);
50      }
51  
52      public void testWriteToTransportResponseAttachment() throws Exception {
53          InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes("UTF-8"));
54          soapMessage.addAttachment("contentId", inputStreamSource, "text/plain");
55          ByteArrayOutputStream bos = new ByteArrayOutputStream();
56          MockTransportOutputStream tos = new MockTransportOutputStream(bos);
57          soapMessage.writeTo(tos);
58          String contentType = (String) tos.getHeaders().get("Content-Type");
59          assertTrue("Content-Type for attachment message does not contains multipart/related",
60                  contentType.indexOf("multipart/related") != -1);
61          assertTrue("Content-Type for attachment message does not contains type=\"application/soap+xml\"",
62                  contentType.indexOf("type=\"application/soap+xml\"") != -1);
63      }
64  
65  
66  }