1   /*
2    * Copyright 2005-2012 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 org.junit.Assert;
22  import org.junit.Before;
23  import org.junit.Test;
24  
25  public class MethodEndpointTest {
26  
27      private MethodEndpoint endpoint;
28  
29      private boolean myMethodInvoked;
30  
31      private Method method;
32  
33      @Before
34      public void setUp() throws Exception {
35          myMethodInvoked = false;
36          method = getClass().getMethod("myMethod", String.class);
37          endpoint = new MethodEndpoint(this, method);
38      }
39  
40      @Test
41      public void testGetters() throws Exception {
42          Assert.assertEquals("Invalid bean", this, endpoint.getBean());
43          Assert.assertEquals("Invalid bean", method, endpoint.getMethod());
44      }
45  
46      @Test
47      public void testInvoke() throws Exception {
48          Assert.assertFalse("Method invoked before invocation", myMethodInvoked);
49          endpoint.invoke("arg");
50          Assert.assertTrue("Method invoked before invocation", myMethodInvoked);
51      }
52  
53      @Test
54      public void testEquals() throws Exception {
55          Assert.assertEquals("Not equal", endpoint, endpoint);
56          Assert.assertEquals("Not equal", new MethodEndpoint(this, method), endpoint);
57          Method otherMethod = getClass().getMethod("testEquals");
58          Assert.assertFalse("Equal", new MethodEndpoint(this, otherMethod).equals(endpoint));
59      }
60  
61      @Test
62      public void testHashCode() throws Exception {
63          Assert.assertEquals("Not equal", new MethodEndpoint(this, method).hashCode(), endpoint.hashCode());
64          Method otherMethod = getClass().getMethod("testEquals");
65          Assert.assertFalse("Equal", new MethodEndpoint(this, otherMethod).hashCode() == endpoint.hashCode());
66      }
67  
68      @Test
69      public void testToString() throws Exception {
70          Assert.assertNotNull("No valid toString", endpoint.toString());
71      }
72  
73      public void myMethod(String arg) {
74          Assert.assertEquals("Invalid argument", "arg", arg);
75          myMethodInvoked = true;
76      }
77  }