1   /*
2    * Copyright 2005-2010 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.adapter;
18  
19  import org.springframework.ws.MockWebServiceMessageFactory;
20  import org.springframework.ws.context.DefaultMessageContext;
21  import org.springframework.ws.context.MessageContext;
22  import org.springframework.ws.server.endpoint.MethodEndpoint;
23  
24  import org.junit.Assert;
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  public class MessageMethodEndpointAdapterTest {
29  
30      private MessageMethodEndpointAdapter adapter;
31  
32      private boolean supportedInvoked;
33  
34      private MessageContext messageContext;
35  
36      @Before
37      public void setUp() throws Exception {
38          adapter = new MessageMethodEndpointAdapter();
39          messageContext = new DefaultMessageContext(new MockWebServiceMessageFactory());
40      }
41  
42      @Test
43      public void testSupported() throws NoSuchMethodException {
44          MethodEndpoint methodEndpoint = new MethodEndpoint(this, "supported", new Class[]{MessageContext.class});
45          Assert.assertTrue("Method unsupported", adapter.supportsInternal(methodEndpoint));
46      }
47  
48      @Test
49      public void testUnsupportedMethodMultipleParams() throws NoSuchMethodException {
50          Assert.assertFalse("Method supported", adapter.supportsInternal(
51                  new MethodEndpoint(this, "unsupportedMultipleParams",
52                          new Class[]{MessageContext.class, MessageContext.class})));
53      }
54  
55      @Test
56      public void testUnsupportedMethodWrongParam() throws NoSuchMethodException {
57          Assert.assertFalse("Method supported",
58                  adapter.supportsInternal(new MethodEndpoint(this, "unsupportedWrongParam", new Class[]{String.class})));
59      }
60  
61      @Test
62      public void testInvokeSupported() throws Exception {
63          MethodEndpoint methodEndpoint = new MethodEndpoint(this, "supported", new Class[]{MessageContext.class});
64          Assert.assertFalse("Method invoked", supportedInvoked);
65          adapter.invoke(messageContext, methodEndpoint);
66          Assert.assertTrue("Method not invoked", supportedInvoked);
67      }
68  
69      public void supported(MessageContext context) {
70          supportedInvoked = true;
71      }
72  
73      public void unsupportedMultipleParams(MessageContext s1, MessageContext s2) {
74      }
75  
76      public void unsupportedWrongParam(String request) {
77      }
78  }