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.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
31: AbstractSoapMessageTestCase {
32:
33: public void testGetVersion() throws Exception {
34: Assert.assertEquals("Invalid SOAP version",
35: SoapVersion.SOAP_12, soapMessage.getVersion());
36: }
37:
38: protected final Resource[] getSoapSchemas() {
39: return new Resource[] {
40: new ClassPathResource("xml.xsd",
41: AbstractSoap12MessageTestCase.class),
42: new ClassPathResource("soap12.xsd",
43: AbstractSoap12MessageTestCase.class) };
44: }
45:
46: public void testWriteToTransportOutputStream() throws Exception {
47: final ByteArrayOutputStream bos = new ByteArrayOutputStream();
48: MockTransportOutputStream tos = new MockTransportOutputStream(
49: bos);
50: soapMessage.writeTo(tos);
51: String result = bos.toString("UTF-8");
52:
53: assertXMLEqual(
54: "<Envelope xmlns='http://www.w3.org/2003/05/soap-envelope'><Body/></Envelope>",
55: result);
56: String contentType = (String) tos.getHeaders().get(
57: "Content-Type");
58: assertTrue("Invalid Content-Type set", contentType
59: .indexOf(SoapVersion.SOAP_12.getContentType()) != -1);
60: }
61:
62: public void testWriteToTransportResponseAttachment()
63: throws Exception {
64: InputStreamSource inputStreamSource = new ByteArrayResource(
65: "contents".getBytes("UTF-8"));
66: soapMessage.addAttachment("contentId", inputStreamSource,
67: "text/plain");
68: ByteArrayOutputStream bos = new ByteArrayOutputStream();
69: MockTransportOutputStream tos = new MockTransportOutputStream(
70: bos);
71: soapMessage.writeTo(tos);
72: String contentType = (String) tos.getHeaders().get(
73: "Content-Type");
74: assertTrue(
75: "Content-Type for attachment message does not contains multipart/related",
76: contentType.indexOf("multipart/related") != -1);
77: assertTrue(
78: "Content-Type for attachment message does not contains type=\"application/soap+xml\"",
79: contentType.indexOf("type=\"application/soap+xml\"") != -1);
80: }
81:
82: }
|