1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }