1   /*
2    * Copyright 2008 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.custommonkey.xmlunit.XMLTestCase;
27  import org.custommonkey.xmlunit.XMLUnit;
28  import org.w3c.dom.Document;
29  
30  import org.springframework.ws.soap.saaj.SaajSoapMessage;
31  
32  public abstract class AbstractWsAddressingTestCase extends XMLTestCase {
33  
34      protected MessageFactory messageFactory;
35  
36      protected final void setUp() throws Exception {
37          messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
38          XMLUnit.setIgnoreWhitespace(true);
39          onSetUp();
40      }
41  
42      protected void onSetUp() throws Exception {
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          assertXMLEqual(message, expectedDocument, resultDocument);
62      }
63  }