1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.saaj;
18
19 import java.io.ByteArrayOutputStream;
20 import java.io.IOException;
21 import java.util.Collections;
22 import java.util.Map;
23 import javax.xml.soap.MessageFactory;
24 import javax.xml.soap.SOAPConstants;
25 import javax.xml.soap.SOAPMessage;
26
27 import org.springframework.ws.WebServiceMessageFactory;
28 import org.springframework.ws.soap.SoapMessage;
29 import org.springframework.ws.soap.soap11.AbstractSoap11MessageFactoryTestCase;
30
31 import org.junit.Test;
32
33 import static org.junit.Assert.assertTrue;
34
35 public class SaajSoap11MessageFactoryTest extends AbstractSoap11MessageFactoryTestCase {
36
37 @Override
38 protected WebServiceMessageFactory createMessageFactory() throws Exception {
39 MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
40 return new SaajSoapMessageFactory(messageFactory);
41 }
42
43 @Test
44 public void properties() throws IOException {
45 Map<String, ?> properties = Collections.singletonMap(SOAPMessage.WRITE_XML_DECLARATION, "true");
46 ((SaajSoapMessageFactory)messageFactory).setMessageProperties(properties);
47 SoapMessage soapMessage = (SoapMessage) messageFactory.createWebServiceMessage();
48 ByteArrayOutputStream os = new ByteArrayOutputStream();
49 soapMessage.writeTo(os);
50 String result = os.toString("UTF-8");
51 assertTrue("XML declaration not written", result.startsWith("<?xml version=\"1.0\""));
52 }
53
54
55 }