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