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.soap.server.endpoint.mapping;
18  
19  import java.lang.reflect.Method;
20  
21  import junit.framework.TestCase;
22  import static org.easymock.EasyMock.*;
23  
24  import org.springframework.context.support.StaticApplicationContext;
25  import org.springframework.ws.WebServiceMessageFactory;
26  import org.springframework.ws.context.DefaultMessageContext;
27  import org.springframework.ws.context.MessageContext;
28  import org.springframework.ws.server.EndpointInvocationChain;
29  import org.springframework.ws.server.endpoint.MethodEndpoint;
30  import org.springframework.ws.server.endpoint.annotation.Endpoint;
31  import org.springframework.ws.soap.SoapMessage;
32  import org.springframework.ws.soap.server.endpoint.annotation.SoapAction;
33  
34  public class SoapActionAnnotationMethodEndpointMappingTest extends TestCase {
35  
36      private SoapActionAnnotationMethodEndpointMapping mapping;
37  
38      private StaticApplicationContext applicationContext;
39  
40      protected void setUp() throws Exception {
41          applicationContext = new StaticApplicationContext();
42          applicationContext.registerSingleton("mapping", SoapActionAnnotationMethodEndpointMapping.class);
43          applicationContext.registerSingleton("endpoint", MyEndpoint.class);
44          applicationContext.refresh();
45          mapping = (SoapActionAnnotationMethodEndpointMapping) applicationContext.getBean("mapping");
46      }
47  
48      public void testRegistration() throws Exception {
49          SoapMessage requestMock = createMock(SoapMessage.class);
50          expect(requestMock.getSoapAction()).andReturn("http://springframework.org/spring-ws/SoapAction");
51          WebServiceMessageFactory factoryMock = createMock(WebServiceMessageFactory.class);
52          replay(requestMock, factoryMock);
53  
54          MessageContext context = new DefaultMessageContext(requestMock, factoryMock);
55          EndpointInvocationChain chain = mapping.getEndpoint(context);
56          assertNotNull("MethodEndpoint not registered", chain);
57          Method doIt = MyEndpoint.class.getMethod("doIt", new Class[0]);
58          MethodEndpoint expected = new MethodEndpoint("endpoint", applicationContext, doIt);
59          assertEquals("Invalid endpoint registered", expected, chain.getEndpoint());
60  
61          verify(requestMock, factoryMock);
62      }
63  
64      @Endpoint
65      private static class MyEndpoint {
66  
67          @SoapAction("http://springframework.org/spring-ws/SoapAction")
68          public void doIt() {
69  
70          }
71  
72      }
73  }