1   /*
2    * Copyright ${YEAR} 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.addressing.server;
18  
19  import java.net.URI;
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.springframework.ws.context.DefaultMessageContext;
24  import org.springframework.ws.context.MessageContext;
25  import org.springframework.ws.server.EndpointInterceptor;
26  import org.springframework.ws.server.EndpointInvocationChain;
27  import org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor;
28  import org.springframework.ws.soap.addressing.AbstractWsAddressingTestCase;
29  import org.springframework.ws.soap.saaj.SaajSoapMessage;
30  import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
31  import org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor;
32  
33  public class SimpleActionEndpointMappingTest extends AbstractWsAddressingTestCase {
34  
35      private SimpleActionEndpointMapping mapping;
36  
37      private Endpoint1 endpoint1;
38  
39      protected void onSetUp() throws Exception {
40          mapping = new SimpleActionEndpointMapping();
41          Map map = new HashMap();
42          endpoint1 = new Endpoint1();
43          Endpoint2 endpoint2 = new Endpoint2();
44          map.put("http://example.com/fabrikam/mail/Delete", endpoint1);
45          map.put("http://example.com/fabrikam/mail/Add", endpoint2);
46          mapping.setPreInterceptors(new EndpointInterceptor[]{new PayloadLoggingInterceptor()});
47          mapping.setPostInterceptors(new EndpointInterceptor[]{new PayloadValidatingInterceptor()});
48          mapping.setAddress(new URI("mailto:[email protected]"));
49          mapping.setActionMap(map);
50          mapping.afterPropertiesSet();
51      }
52  
53      public void testMatch() throws Exception {
54          SaajSoapMessage message = loadSaajMessage("200408/valid.xml");
55          MessageContext messageContext = new DefaultMessageContext(message, new SaajSoapMessageFactory(messageFactory));
56  
57          EndpointInvocationChain endpoint = mapping.getEndpoint(messageContext);
58          assertNotNull("No endpoint returned", endpoint);
59          assertEquals("Invalid endpoint returned", endpoint1, endpoint.getEndpoint());
60          EndpointInterceptor[] interceptors = endpoint.getInterceptors();
61          assertEquals("Invalid amount of interceptors returned", 3, interceptors.length);
62          assertTrue("Invalid first interceptor", interceptors[0] instanceof PayloadLoggingInterceptor);
63          assertTrue("Invalid first interceptor", interceptors[1] instanceof AddressingEndpointInterceptor);
64          assertTrue("Invalid first interceptor", interceptors[2] instanceof PayloadValidatingInterceptor);
65      }
66  
67      public void testNoMatch() throws Exception {
68          SaajSoapMessage message = loadSaajMessage("200408/response-no-message-id.xml");
69          MessageContext messageContext = new DefaultMessageContext(message, new SaajSoapMessageFactory(messageFactory));
70  
71          EndpointInvocationChain endpoint = mapping.getEndpoint(messageContext);
72          assertNull("Endpoint returned", endpoint);
73      }
74  
75      private static class Endpoint1 {
76  
77      }
78  
79      private static class Endpoint2 {
80  
81      }
82  }