1   /*
2    * Copyright 2006 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;
18  
19  import org.springframework.core.io.Resource;
20  import org.springframework.util.StringUtils;
21  import org.springframework.ws.mime.AbstractMimeMessageTestCase;
22  import org.springframework.ws.mime.MimeMessage;
23  import org.springframework.xml.validation.XmlValidator;
24  import org.springframework.xml.validation.XmlValidatorFactory;
25  import org.xml.sax.SAXParseException;
26  
27  public abstract class AbstractSoapMessageTestCase extends AbstractMimeMessageTestCase {
28  
29      protected SoapMessage soapMessage;
30  
31      protected MimeMessage createMimeMessage() throws Exception {
32          soapMessage = createSoapMessage();
33          return soapMessage;
34      }
35  
36      protected abstract SoapMessage createSoapMessage() throws Exception;
37  
38      public void testValidate() throws Exception {
39          XmlValidator validator =
40                  XmlValidatorFactory.createValidator(getSoapSchemas(), XmlValidatorFactory.SCHEMA_W3C_XML);
41          SAXParseException[] errors = validator.validate(soapMessage.getEnvelope().getSource());
42          if (errors.length > 0) {
43              fail(StringUtils.arrayToCommaDelimitedString(errors));
44          }
45      }
46  
47      public void testSoapAction() throws Exception {
48          assertEquals("Invalid default SOAP Action", "\"\"", soapMessage.getSoapAction());
49          soapMessage.setSoapAction("SoapAction");
50          assertEquals("Invalid SOAP Action", "\"SoapAction\"", soapMessage.getSoapAction());
51      }
52  
53      protected abstract Resource[] getSoapSchemas();
54  
55      public abstract void testGetVersion() throws Exception;
56  
57      public abstract void testWriteToTransportOutputStream() throws Exception;
58  
59      public abstract void testWriteToTransportResponseAttachment() throws Exception;
60  }