1   /*
2    * Copyright 2005-2011 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.config;
18  
19  import java.util.ArrayList;
20  import java.util.List;
21  import java.util.Map;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  import org.junit.Test;
26  
27  import org.springframework.context.ApplicationContext;
28  import org.springframework.context.support.ClassPathXmlApplicationContext;
29  import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
30  import org.springframework.ws.soap.server.endpoint.interceptor.PayloadRootSmartSoapEndpointInterceptor;
31  import org.springframework.ws.soap.server.endpoint.interceptor.SoapActionSmartEndpointInterceptor;
32  
33  public class InterceptorsBeanDefinitionParserTest {
34  
35      @Test
36      public void namespace() throws Exception {
37          ApplicationContext applicationContext =
38                  new ClassPathXmlApplicationContext("interceptorsBeanDefinitionParserTest.xml", getClass());
39          Map<String, ?> result = applicationContext.getBeansOfType(DelegatingSmartEndpointInterceptor.class);
40          assertEquals("no smart interceptors found", 8, result.size());
41  
42          result = applicationContext.getBeansOfType(PayloadRootSmartSoapEndpointInterceptor.class);
43          assertEquals("no interceptors found", 3, result.size());
44  
45          result = applicationContext.getBeansOfType(SoapActionSmartEndpointInterceptor.class);
46          assertEquals("no interceptors found", 3, result.size());
47      }
48  
49      @Test
50      public void ordering() throws Exception {
51          ApplicationContext applicationContext =
52                  new ClassPathXmlApplicationContext("interceptorsBeanDefinitionParserOrderTest.xml", getClass());
53  
54          List<DelegatingSmartEndpointInterceptor> interceptors = new ArrayList<DelegatingSmartEndpointInterceptor>(
55                  applicationContext.getBeansOfType(DelegatingSmartEndpointInterceptor.class).values());
56          assertEquals("not enough smart interceptors found", 6, interceptors.size());
57  
58          for (int i = 0; i < interceptors.size(); i++) {
59              DelegatingSmartEndpointInterceptor delegatingInterceptor = interceptors.get(i);
60              MyInterceptor interceptor = (MyInterceptor) delegatingInterceptor.getDelegate();
61              assertEquals("Invalid ordering found for [" + delegatingInterceptor + "]", i, interceptor.getOrder());
62          }
63      }
64  
65      @Test
66      public void injection() throws Exception {
67          ApplicationContext applicationContext =
68                  new ClassPathXmlApplicationContext("interceptorsBeanDefinitionParserInjectionTest.xml", getClass());
69  
70          List<DelegatingSmartEndpointInterceptor> interceptors = new ArrayList<DelegatingSmartEndpointInterceptor>(
71                  applicationContext.getBeansOfType(DelegatingSmartEndpointInterceptor.class).values());
72          assertEquals("not enough smart interceptors found", 1, interceptors.size());
73  
74  	    DummyInterceptor interceptor =
75  			    (DummyInterceptor) interceptors.get(0).getDelegate();
76  	    assertNotNull(interceptor.getPropertyDependency());
77  	    assertNotNull(interceptor.getAutowiredDependency());
78      }
79  
80  }