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.soap.server.endpoint.mapping;
18  
19  import org.springframework.ws.MockWebServiceMessageFactory;
20  import org.springframework.ws.context.DefaultMessageContext;
21  import org.springframework.ws.context.MessageContext;
22  import org.springframework.ws.server.EndpointInvocationChain;
23  import org.springframework.ws.server.EndpointMapping;
24  import org.springframework.ws.soap.server.SoapEndpointInvocationChain;
25  
26  import org.junit.Assert;
27  import org.junit.Before;
28  import org.junit.Test;
29  
30  import static org.easymock.EasyMock.*;
31  
32  public class DelegatingSoapEndpointMappingTest {
33  
34      private DelegatingSoapEndpointMapping endpointMapping;
35  
36      private EndpointMapping mock;
37  
38      @Before
39      public void setUp() throws Exception {
40          endpointMapping = new DelegatingSoapEndpointMapping();
41          mock = createMock(EndpointMapping.class);
42          endpointMapping.setDelegate(mock);
43      }
44  
45      @Test
46      public void testGetEndpointMapping() throws Exception {
47          String role = "http://www.springframework.org/spring-ws/role";
48          endpointMapping.setActorOrRole(role);
49          MessageContext context = new DefaultMessageContext(new MockWebServiceMessageFactory());
50          EndpointInvocationChain delegateChain = new EndpointInvocationChain(new Object());
51          expect(mock.getEndpoint(context)).andReturn(delegateChain);
52  
53          replay(mock);
54  
55          SoapEndpointInvocationChain resultChain = (SoapEndpointInvocationChain) endpointMapping.getEndpoint(context);
56          Assert.assertNotNull("No chain returned", resultChain);
57          Assert.assertEquals("Invalid ampount of roles returned", 1, resultChain.getActorsOrRoles().length);
58          Assert.assertEquals("Invalid role returned", role, resultChain.getActorsOrRoles()[0]);
59  
60          verify(mock);
61      }
62  }