1   /*
2    * Copyright 2005-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.addressing;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import javax.xml.soap.MessageFactory;
22  import javax.xml.soap.MimeHeaders;
23  import javax.xml.soap.SOAPConstants;
24  import javax.xml.soap.SOAPException;
25  
26  import org.springframework.ws.soap.saaj.SaajSoapMessage;
27  
28  import org.custommonkey.xmlunit.XMLUnit;
29  import org.junit.Before;
30  import org.w3c.dom.Document;
31  
32  import static org.junit.Assert.assertNotNull;
33  
34  public abstract class AbstractWsAddressingTestCase {
35  
36      protected MessageFactory messageFactory;
37  
38      @Before
39      public void createMessageFactory() throws Exception {
40          messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
41          XMLUnit.setIgnoreWhitespace(true);
42      }
43  
44  
45      protected SaajSoapMessage loadSaajMessage(String fileName) throws SOAPException, IOException {
46          MimeHeaders mimeHeaders = new MimeHeaders();
47          mimeHeaders.addHeader("Content-Type", " application/soap+xml");
48          InputStream is = AbstractWsAddressingTestCase.class.getResourceAsStream(fileName);
49          assertNotNull("Could not load " + fileName, is);
50          try {
51              return new SaajSoapMessage(messageFactory.createMessage(mimeHeaders, is));
52          }
53          finally {
54              is.close();
55          }
56      }
57  
58      protected void assertXMLEqual(String message, SaajSoapMessage expected, SaajSoapMessage result) {
59          Document expectedDocument = expected.getSaajMessage().getSOAPPart();
60          Document resultDocument = result.getSaajMessage().getSOAPPart();
61          org.custommonkey.xmlunit.XMLAssert.assertXMLEqual(message, expectedDocument, resultDocument);
62      }
63  }