1   /*
2    * Copyright 2005-2010 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 org.springframework.ws.MockWebServiceMessage;
20  import org.springframework.ws.MockWebServiceMessageFactory;
21  import org.springframework.ws.context.DefaultMessageContext;
22  import org.springframework.ws.context.MessageContext;
23  
24  import org.junit.Assert;
25  import org.junit.Before;
26  import org.junit.Test;
27  
28  public class SimpleMethodEndpointMappingTest {
29  
30      private SimpleMethodEndpointMapping mapping;
31  
32      @Before
33      public void setUp() throws Exception {
34          mapping = new SimpleMethodEndpointMapping();
35          mapping.setMethodPrefix("prefix");
36          mapping.setMethodSuffix("Suffix");
37          MyBean bean = new MyBean();
38          mapping.setEndpoints(new Object[]{bean});
39          mapping.afterPropertiesSet();
40      }
41  
42      @Test
43      public void testRegistration() throws Exception {
44          Assert.assertNotNull("Endpoint not registered", mapping.lookupEndpoint("MyRequest"));
45          Assert.assertNull("Endpoint registered", mapping.lookupEndpoint("request"));
46      }
47  
48      @Test
49      public void testGetLookupKeyForMessageNoNamespace() throws Exception {
50          MockWebServiceMessage request = new MockWebServiceMessage("<MyRequest/>");
51          MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
52          String result = mapping.getLookupKeyForMessage(messageContext);
53          Assert.assertEquals("Invalid lookup key", "MyRequest", result);
54      }
55  
56      @Test
57      public void testGetLookupKeyForMessageNamespace() throws Exception {
58          MockWebServiceMessage request =
59                  new MockWebServiceMessage("<MyRequest xmlns='http://springframework.org/spring-ws/' />");
60          MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory());
61          String result = mapping.getLookupKeyForMessage(messageContext);
62          Assert.assertEquals("Invalid lookup key", "MyRequest", result);
63      }
64  
65      private static class MyBean {
66  
67          public void prefixMyRequestSuffix() {
68  
69          }
70  
71          public void request() {
72  
73          }
74      }
75  }