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 import org.junit.Before;
34 import org.junit.Test;
35
36 import static org.junit.Assert.*;
37
38 public class SimpleActionEndpointMappingTest extends AbstractWsAddressingTestCase {
39
40 private SimpleActionEndpointMapping mapping;
41
42 private Endpoint1 endpoint1;
43
44 @Before
45 public void createMappings() throws Exception {
46 mapping = new SimpleActionEndpointMapping();
47 Map<String, Object> map = new HashMap<String, Object>();
48 endpoint1 = new Endpoint1();
49 Endpoint2 endpoint2 = new Endpoint2();
50 map.put("http://example.com/fabrikam/mail/Delete", endpoint1);
51 map.put("http://example.com/fabrikam/mail/Add", endpoint2);
52 mapping.setPreInterceptors(new EndpointInterceptor[]{new PayloadLoggingInterceptor()});
53 mapping.setPostInterceptors(new EndpointInterceptor[]{new PayloadValidatingInterceptor()});
54 mapping.setAddress(new URI("mailto:[email protected]"));
55 mapping.setActionMap(map);
56 mapping.afterPropertiesSet();
57 }
58
59 @Test
60 public void testMatch() throws Exception {
61 SaajSoapMessage message = loadSaajMessage("200408/valid.xml");
62 MessageContext messageContext = new DefaultMessageContext(message, new SaajSoapMessageFactory(messageFactory));
63
64 EndpointInvocationChain endpoint = mapping.getEndpoint(messageContext);
65 assertNotNull("No endpoint returned", endpoint);
66 assertEquals("Invalid endpoint returned", endpoint1, endpoint.getEndpoint());
67 EndpointInterceptor[] interceptors = endpoint.getInterceptors();
68 assertEquals("Invalid amount of interceptors returned", 3, interceptors.length);
69 assertTrue("Invalid first interceptor", interceptors[0] instanceof PayloadLoggingInterceptor);
70 assertTrue("Invalid first interceptor", interceptors[1] instanceof AddressingEndpointInterceptor);
71 assertTrue("Invalid first interceptor", interceptors[2] instanceof PayloadValidatingInterceptor);
72 }
73
74 @Test
75 public void testNoMatch() throws Exception {
76 SaajSoapMessage message = loadSaajMessage("200408/response-no-message-id.xml");
77 MessageContext messageContext = new DefaultMessageContext(message, new SaajSoapMessageFactory(messageFactory));
78
79 EndpointInvocationChain endpoint = mapping.getEndpoint(messageContext);
80 assertNull("Endpoint returned", endpoint);
81 }
82
83 private static class Endpoint1 {
84
85 }
86
87 private static class Endpoint2 {
88
89 }
90 }