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.server.endpoint;
18  
19  import javax.xml.transform.Source;
20  import javax.xml.transform.Transformer;
21  import javax.xml.transform.TransformerFactory;
22  
23  import org.springframework.xml.transform.StringResult;
24  import org.springframework.xml.transform.StringSource;
25  
26  public abstract class AbstractPayloadEndpointTestCase extends AbstractEndpointTestCase {
27  
28      private PayloadEndpoint endpoint;
29  
30      private Transformer transformer;
31  
32      protected final void setUp() throws Exception {
33          endpoint = createResponseEndpoint();
34          transformer = TransformerFactory.newInstance().newTransformer();
35      }
36  
37      public void testNoResponse() throws Exception {
38          endpoint = createNoResponseEndpoint();
39          StringSource requestSource = new StringSource(REQUEST);
40          Source resultSource = endpoint.invoke(requestSource);
41          assertNull("Response source returned", resultSource);
42      }
43  
44      public void testNoRequest() throws Exception {
45          endpoint = createNoRequestEndpoint();
46          Source resultSource = endpoint.invoke(null);
47          assertNull("Response source returned", resultSource);
48      }
49  
50      protected final void testSource(Source requestSource) throws Exception {
51          Source responseSource = endpoint.invoke(requestSource);
52          assertNotNull("No response source returned", responseSource);
53          StringResult result = new StringResult();
54          transformer.transform(responseSource, result);
55          assertXMLEqual(RESPONSE, result.toString());
56      }
57  
58      protected abstract PayloadEndpoint createNoResponseEndpoint() throws Exception;
59  
60      protected abstract PayloadEndpoint createResponseEndpoint() throws Exception;
61  
62      protected abstract PayloadEndpoint createNoRequestEndpoint() throws Exception;
63  }