1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.ws.soap.server.endpoint.interceptor;
18
19 import org.springframework.ws.context.DefaultMessageContext;
20 import org.springframework.ws.context.MessageContext;
21 import org.springframework.ws.server.EndpointInterceptor;
22 import org.springframework.ws.server.endpoint.interceptor.EndpointInterceptorAdapter;
23 import org.springframework.ws.soap.saaj.SaajSoapMessage;
24 import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
25
26 import org.junit.Before;
27 import org.junit.Test;
28
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.assertTrue;
31
32 public class SoapActionSmartEndpointInterceptorTest {
33
34 private EndpointInterceptor delegate;
35
36 private String soapAction;
37
38 private MessageContext messageContext;
39
40 @Before
41 public void setUp() {
42 delegate = new EndpointInterceptorAdapter();
43
44 soapAction = "http://springframework.org/spring-ws";
45
46 SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
47 messageFactory.afterPropertiesSet();
48 SaajSoapMessage request = messageFactory.createWebServiceMessage();
49 request.setSoapAction(soapAction);
50 messageContext = new DefaultMessageContext(request, messageFactory);
51 }
52
53 @Test(expected = IllegalArgumentException.class)
54 public void neitherNamespaceNorLocalPart() {
55 new SoapActionSmartEndpointInterceptor(delegate, null);
56 }
57
58 @Test
59 public void shouldInterceptMatch() throws Exception {
60 SoapActionSmartEndpointInterceptor interceptor = new SoapActionSmartEndpointInterceptor(delegate, soapAction);
61
62 boolean result = interceptor.shouldIntercept(messageContext, null);
63 assertTrue("Interceptor should apply", result);
64 }
65
66 @Test
67 public void shouldInterceptNonMatch() throws Exception {
68 SoapActionSmartEndpointInterceptor interceptor =
69 new SoapActionSmartEndpointInterceptor(delegate, "http://springframework.org/other");
70
71 boolean result = interceptor.shouldIntercept(messageContext, null);
72 assertFalse("Interceptor should apply", result);
73 }
74
75
76 }