1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.soap11;
18
19 import java.io.ByteArrayOutputStream;
20
21 import junit.framework.Assert;
22
23 import org.springframework.core.io.ByteArrayResource;
24 import org.springframework.core.io.ClassPathResource;
25 import org.springframework.core.io.InputStreamSource;
26 import org.springframework.core.io.Resource;
27 import org.springframework.ws.soap.AbstractSoapMessageTestCase;
28 import org.springframework.ws.soap.SoapBody;
29 import org.springframework.ws.soap.SoapVersion;
30 import org.springframework.ws.transport.MockTransportOutputStream;
31 import org.springframework.xml.transform.StringSource;
32
33 public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageTestCase {
34
35 protected final Resource[] getSoapSchemas() {
36 return new Resource[]{new ClassPathResource("soap11.xsd", AbstractSoap11MessageTestCase.class)};
37 }
38
39 public void testGetVersion() throws Exception {
40 Assert.assertEquals("Invalid SOAP version", SoapVersion.SOAP_11, soapMessage.getVersion());
41 }
42
43 public void testWriteToTransportOutputStream() throws Exception {
44 SoapBody body = soapMessage.getSoapBody();
45 String payload = "<payload xmlns='http://www.springframework.org' />";
46 transformer.transform(new StringSource(payload), body.getPayloadResult());
47
48 ByteArrayOutputStream bos = new ByteArrayOutputStream();
49 MockTransportOutputStream tos = new MockTransportOutputStream(bos);
50 String soapAction = "http://springframework.org/spring-ws/Action";
51 soapMessage.setSoapAction(soapAction);
52 soapMessage.writeTo(tos);
53 String result = bos.toString("UTF-8");
54 assertXMLEqual(
55 "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Body><payload xmlns='http://www.springframework.org' /></Body></Envelope>",
56 result);
57 String contentType = (String) tos.getHeaders().get("Content-Type");
58 assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_11.getContentType()) != -1);
59 String resultSoapAction = (String) tos.getHeaders().get("SOAPAction");
60 assertEquals("Invalid soap action", "\"" + soapAction + "\"", resultSoapAction);
61 String resultAccept = (String) tos.getHeaders().get("Accept");
62 assertNotNull("Invalid accept header", resultAccept);
63 }
64
65 public void testWriteToTransportResponseAttachment() throws Exception {
66 InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes("UTF-8"));
67 soapMessage.addAttachment("contentId", inputStreamSource, "text/plain");
68 ByteArrayOutputStream bos = new ByteArrayOutputStream();
69 MockTransportOutputStream tos = new MockTransportOutputStream(bos);
70 soapMessage.writeTo(tos);
71 String contentType = (String) tos.getHeaders().get("Content-Type");
72 assertTrue("Content-Type for attachment message does not contains multipart/related",
73 contentType.indexOf("multipart/related") != -1);
74 assertTrue("Content-Type for attachment message does not contains type=\"text/xml\"",
75 contentType.indexOf("type=\"text/xml\"") != -1);
76 }
77 }