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;
18  
19  import java.lang.reflect.Method;
20  
21  import junit.framework.TestCase;
22  
23  public class MethodEndpointTest extends TestCase {
24  
25      private MethodEndpoint endpoint;
26  
27      private boolean myMethodInvoked;
28  
29      private Method method;
30  
31      protected void setUp() throws Exception {
32          myMethodInvoked = false;
33          method = getClass().getMethod("myMethod", new Class[]{String.class});
34          endpoint = new MethodEndpoint(this, method);
35      }
36  
37      public void testGetters() throws Exception {
38          assertEquals("Invalid bean", this, endpoint.getBean());
39          assertEquals("Invalid bean", method, endpoint.getMethod());
40      }
41  
42      public void testInvoke() throws Exception {
43          assertFalse("Method invoked before invocation", myMethodInvoked);
44          endpoint.invoke(new Object[]{"arg"});
45          assertTrue("Method invoked before invocation", myMethodInvoked);
46      }
47  
48      public void testEquals() throws Exception {
49          assertEquals("Not equal", endpoint, endpoint);
50          assertEquals("Not equal", new MethodEndpoint(this, method), endpoint);
51          Method otherMethod = getClass().getMethod("testEquals", new Class[0]);
52          assertFalse("Equal", new MethodEndpoint(this, otherMethod).equals(endpoint));
53      }
54  
55      public void testHashCode() throws Exception {
56          assertEquals("Not equal", new MethodEndpoint(this, method).hashCode(), endpoint.hashCode());
57          Method otherMethod = getClass().getMethod("testEquals", new Class[0]);
58          assertFalse("Equal", new MethodEndpoint(this, otherMethod).hashCode() == endpoint.hashCode());
59      }
60  
61      public void myMethod(String arg) {
62          assertEquals("Invalid argument", "arg", arg);
63          myMethodInvoked = true;
64      }
65  
66      public void testToString() throws Exception {
67          assertNotNull("Na valid toString", endpoint.toString());
68      }
69  }