1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }