1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }