01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.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
31: AbstractSoapMessageTestCase {
32:
33: protected final Resource[] getSoapSchemas() {
34: return new Resource[] { new ClassPathResource("soap11.xsd",
35: AbstractSoap11MessageTestCase.class) };
36: }
37:
38: public void testGetVersion() throws Exception {
39: Assert.assertEquals("Invalid SOAP version",
40: SoapVersion.SOAP_11, soapMessage.getVersion());
41: }
42:
43: public void testWriteToTransportOutputStream() throws Exception {
44: ByteArrayOutputStream bos = new ByteArrayOutputStream();
45: MockTransportOutputStream tos = new MockTransportOutputStream(
46: bos);
47: String soapAction = "http://springframework.org/spring-ws/Action";
48: soapMessage.setSoapAction(soapAction);
49: soapMessage.writeTo(tos);
50: String result = bos.toString("UTF-8");
51: assertXMLEqual(
52: "<Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/'><Body/></Envelope>",
53: result);
54: String contentType = (String) tos.getHeaders().get(
55: "Content-Type");
56: assertTrue("Invalid Content-Type set", contentType
57: .indexOf(SoapVersion.SOAP_11.getContentType()) != -1);
58: String resultSoapAction = (String) tos.getHeaders().get(
59: "SOAPAction");
60: assertEquals("Invalid soap action", soapAction,
61: resultSoapAction);
62: }
63:
64: public void testWriteToTransportResponseAttachment()
65: throws Exception {
66: InputStreamSource inputStreamSource = new ByteArrayResource(
67: "contents".getBytes("UTF-8"));
68: soapMessage.addAttachment("contentId", inputStreamSource,
69: "text/plain");
70: ByteArrayOutputStream bos = new ByteArrayOutputStream();
71: MockTransportOutputStream tos = new MockTransportOutputStream(
72: bos);
73: soapMessage.writeTo(tos);
74: String contentType = (String) tos.getHeaders().get(
75: "Content-Type");
76: assertTrue(
77: "Content-Type for attachment message does not contains multipart/related",
78: contentType.indexOf("multipart/related") != -1);
79: assertTrue(
80: "Content-Type for attachment message does not contains type=\"text/xml\"",
81: contentType.indexOf("type=\"text/xml\"") != -1);
82: }
83:
84: }
|