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.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  }