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