1   /*
2    * Copyright 2002-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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.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  }