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.mapping;
18  
19  import junit.framework.TestCase;
20  import org.springframework.context.support.StaticApplicationContext;
21  import org.springframework.ws.server.endpoint.MethodEndpoint;
22  import org.springframework.ws.server.endpoint.annotation.Endpoint;
23  import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
24  
25  public class PayloadRootAnnotationMethodEndpointMappingTest extends TestCase {
26  
27      private PayloadRootAnnotationMethodEndpointMapping mapping;
28  
29      private StaticApplicationContext applicationContext;
30  
31      protected void setUp() throws Exception {
32          applicationContext = new StaticApplicationContext();
33          applicationContext.registerSingleton("mapping", PayloadRootAnnotationMethodEndpointMapping.class);
34          applicationContext.registerSingleton("endpoint", MyEndpoint.class);
35          applicationContext.registerSingleton("other", OtherBean.class);
36          applicationContext.refresh();
37          mapping = (PayloadRootAnnotationMethodEndpointMapping) applicationContext.getBean("mapping");
38      }
39  
40      public void testRegistration() throws NoSuchMethodException {
41          MethodEndpoint endpoint = mapping.lookupEndpoint("{http://springframework.org/spring-ws}Request");
42          assertNotNull("MethodEndpoint not registered", endpoint);
43          MethodEndpoint expected = new MethodEndpoint(applicationContext.getBean("endpoint"), "doIt", new Class[0]);
44          assertEquals("Invalid endpoint registered", expected, endpoint);
45  
46          assertNull("Invalid endpoint registered",
47                  mapping.lookupEndpoint("{http://springframework.org/spring-ws}Request2"));
48      }
49  
50      @Endpoint
51      private static class MyEndpoint {
52  
53          @PayloadRoot(localPart = "Request", namespace = "http://springframework.org/spring-ws")
54          public void doIt() {
55  
56          }
57  
58      }
59  
60      private static class OtherBean {
61  
62          @PayloadRoot(localPart = "Request2", namespace = "http://springframework.org/spring-ws")
63          public void doIt() {
64  
65          }
66  
67      }
68  
69  }