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 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 AbstractSoap11MessageTestCase extends AbstractSoapMessageTestCase {
31
32 protected final Resource[] getSoapSchemas() {
33 return new Resource[]{new ClassPathResource("soap11.xsd", AbstractSoap11MessageTestCase.class)};
34 }
35
36 public void testGetVersion() throws Exception {
37 Assert.assertEquals("Invalid SOAP version", SoapVersion.SOAP_11, soapMessage.getVersion());
38 }
39
40 public void testWriteToTransportOutputStream() throws Exception {
41 ByteArrayOutputStream bos = new ByteArrayOutputStream();
42 MockTransportOutputStream tos = new MockTransportOutputStream(bos);
43 String soapAction = "http://springframework.org/spring-ws/Action";
44 soapMessage.setSoapAction(soapAction);
45 soapMessage.writeTo(tos);
46 String result = bos.toString("UTF-8");
47 assertXMLEqual("<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Body/></Envelope>", result);
48 String contentType = (String) tos.getHeaders().get("Content-Type");
49 assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_11.getContentType()) != -1);
50 String resultSoapAction = (String) tos.getHeaders().get("SOAPAction");
51 assertEquals("Invalid soap action", "\"" + soapAction + "\"", resultSoapAction);
52 }
53
54 public void testWriteToTransportResponseAttachment() throws Exception {
55 InputStreamSource inputStreamSource = new ByteArrayResource("contents".getBytes("UTF-8"));
56 soapMessage.addAttachment("contentId", inputStreamSource, "text/plain");
57 ByteArrayOutputStream bos = new ByteArrayOutputStream();
58 MockTransportOutputStream tos = new MockTransportOutputStream(bos);
59 soapMessage.writeTo(tos);
60 String contentType = (String) tos.getHeaders().get("Content-Type");
61 assertTrue("Content-Type for attachment message does not contains multipart/related",
62 contentType.indexOf("multipart/related") != -1);
63 assertTrue("Content-Type for attachment message does not contains type=\"text/xml\"",
64 contentType.indexOf("type=\"text/xml\"") != -1);
65 }
66
67
68 }