1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.server.endpoint.adapter;
18
19 import javax.xml.transform.Source;
20 import javax.xml.transform.dom.DOMSource;
21 import javax.xml.transform.stream.StreamSource;
22
23 import org.springframework.ws.MockWebServiceMessage;
24 import org.springframework.ws.MockWebServiceMessageFactory;
25 import org.springframework.ws.WebServiceMessage;
26 import org.springframework.ws.context.DefaultMessageContext;
27 import org.springframework.ws.context.MessageContext;
28 import org.springframework.ws.server.endpoint.MethodEndpoint;
29
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33
34 public class PayloadMethodEndpointAdapterTest {
35
36 private PayloadMethodEndpointAdapter adapter;
37
38 private boolean noResponseInvoked;
39
40 private boolean responseInvoked;
41
42 private MessageContext messageContext;
43
44 @Before
45 public void setUp() throws Exception {
46 adapter = new PayloadMethodEndpointAdapter();
47 messageContext = new DefaultMessageContext(new MockWebServiceMessageFactory());
48 }
49
50 @Test
51 public void testSupportedNoResponse() throws NoSuchMethodException {
52 MethodEndpoint methodEndpoint = new MethodEndpoint(this, "noResponse", new Class[]{DOMSource.class});
53 Assert.assertTrue("Method unsupported", adapter.supportsInternal(methodEndpoint));
54 }
55
56 @Test
57 public void testSupportedResponse() throws NoSuchMethodException {
58 MethodEndpoint methodEndpoint = new MethodEndpoint(this, "response", new Class[]{StreamSource.class});
59 Assert.assertTrue("Method unsupported", adapter.supportsInternal(methodEndpoint));
60 }
61
62 @Test
63 public void testUnsupportedMethodMultipleParams() throws NoSuchMethodException {
64 Assert.assertFalse("Method supported", adapter.supportsInternal(
65 new MethodEndpoint(this, "unsupportedMultipleParams", new Class[]{Source.class, Source.class})));
66 }
67
68 @Test
69 public void testUnsupportedMethodWrongReturnType() throws NoSuchMethodException {
70 Assert.assertFalse("Method supported", adapter.supportsInternal(
71 new MethodEndpoint(this, "unsupportedWrongReturnType", new Class[]{Source.class})));
72 }
73
74 @Test
75 public void testUnsupportedMethodWrongParam() throws NoSuchMethodException {
76 Assert.assertFalse("Method supported",
77 adapter.supportsInternal(new MethodEndpoint(this, "unsupportedWrongParam", new Class[]{String.class})));
78 }
79
80 @Test
81 public void testNoResponse() throws Exception {
82 MethodEndpoint methodEndpoint = new MethodEndpoint(this, "noResponse", new Class[]{DOMSource.class});
83 Assert.assertFalse("Method invoked", noResponseInvoked);
84 adapter.invoke(messageContext, methodEndpoint);
85 Assert.assertTrue("Method not invoked", noResponseInvoked);
86 }
87
88 @Test
89 public void testResponse() throws Exception {
90 WebServiceMessage request = new MockWebServiceMessage("<request/>");
91 messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
92 MethodEndpoint methodEndpoint = new MethodEndpoint(this, "response", new Class[]{StreamSource.class});
93 Assert.assertFalse("Method invoked", responseInvoked);
94 adapter.invoke(messageContext, methodEndpoint);
95 Assert.assertTrue("Method not invoked", responseInvoked);
96 }
97
98 public void noResponse(DOMSource request) {
99 noResponseInvoked = true;
100 }
101
102 public Source response(StreamSource request) {
103 responseInvoked = true;
104 return request;
105 }
106
107 public void unsupportedMultipleParams(Source s1, Source s2) {
108 }
109
110 public Source unsupportedWrongParam(String request) {
111 return null;
112 }
113
114 public String unsupportedWrongReturnType(Source request) {
115 return null;
116 }
117
118 }