|
18 | 18 |
|
19 | 19 | import java.util.List; |
20 | 20 |
|
21 | | -import org.junit.jupiter.api.BeforeEach; |
22 | 21 | import org.junit.jupiter.api.Test; |
23 | 22 |
|
24 | | -import org.springframework.context.ApplicationContext; |
| 23 | +import org.springframework.context.ConfigurableApplicationContext; |
25 | 24 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
26 | 25 | import org.springframework.context.annotation.Bean; |
27 | 26 | import org.springframework.context.annotation.Configuration; |
| 27 | +import org.springframework.ws.config.annotation.WsConfigurationSupportTest.CustomArgumentResolverConfig.MyArgumentResolver; |
| 28 | +import org.springframework.ws.config.annotation.WsConfigurationSupportTest.CustomDefaultMethodEndpointAdapterConfig.MyDefaultMethodEndpointAdapter; |
| 29 | +import org.springframework.ws.config.annotation.WsConfigurationSupportTest.CustomInterceptorConfig.MyInterceptor; |
| 30 | +import org.springframework.ws.config.annotation.WsConfigurationSupportTest.CustomReturnValueHandlerConfig.MyReturnValueHandler; |
28 | 31 | import org.springframework.ws.server.EndpointInterceptor; |
29 | 32 | import org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter; |
| 33 | +import org.springframework.ws.server.endpoint.adapter.method.MethodArgumentResolver; |
| 34 | +import org.springframework.ws.server.endpoint.adapter.method.MethodReturnValueHandler; |
| 35 | +import org.springframework.ws.server.endpoint.adapter.method.SourcePayloadMethodProcessor; |
30 | 36 | import org.springframework.ws.server.endpoint.interceptor.EndpointInterceptorAdapter; |
31 | 37 | import org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping; |
32 | 38 |
|
33 | 39 | import static org.assertj.core.api.Assertions.assertThat; |
34 | 40 |
|
35 | 41 | /** |
| 42 | + * Tests for {@link WsConfigurationSupport}. |
| 43 | + * |
36 | 44 | * @author Arjen Poutsma |
| 45 | + * @author Stephane Nicoll |
37 | 46 | */ |
38 | | -public class WsConfigurationSupportTest { |
| 47 | +class WsConfigurationSupportTest { |
39 | 48 |
|
40 | | - private ApplicationContext applicationContext; |
| 49 | + @Test |
| 50 | + void interceptors() { |
| 51 | + try (ConfigurableApplicationContext applicationContext = load(CustomInterceptorConfig.class)) { |
| 52 | + PayloadRootAnnotationMethodEndpointMapping endpointMapping = applicationContext |
| 53 | + .getBean(PayloadRootAnnotationMethodEndpointMapping.class); |
| 54 | + assertThat(endpointMapping.getOrder()).isEqualTo(0); |
| 55 | + EndpointInterceptor[] interceptors = endpointMapping.getInterceptors(); |
| 56 | + assertThat(interceptors).singleElement().isInstanceOf(MyInterceptor.class); |
| 57 | + } |
| 58 | + } |
41 | 59 |
|
42 | | - @BeforeEach |
43 | | - public void setUp() { |
| 60 | + @Test |
| 61 | + void argumentResolvers() { |
| 62 | + try (ConfigurableApplicationContext applicationContext = load(CustomArgumentResolverConfig.class)) { |
| 63 | + DefaultMethodEndpointAdapter bean = applicationContext.getBean(DefaultMethodEndpointAdapter.class); |
| 64 | + List<MethodArgumentResolver> methodArgumentResolvers = bean.getMethodArgumentResolvers(); |
| 65 | + assertThat(methodArgumentResolvers).hasSizeGreaterThan(1).element(0).isInstanceOf(MyArgumentResolver.class); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + void returnValueHandlers() { |
| 71 | + try (ConfigurableApplicationContext applicationContext = load(CustomReturnValueHandlerConfig.class)) { |
| 72 | + DefaultMethodEndpointAdapter bean = applicationContext.getBean(DefaultMethodEndpointAdapter.class); |
| 73 | + List<MethodReturnValueHandler> methodReturnValueHandlers = bean.getMethodReturnValueHandlers(); |
| 74 | + assertThat(methodReturnValueHandlers).hasSizeGreaterThan(1) |
| 75 | + .element(0) |
| 76 | + .isInstanceOf(MyReturnValueHandler.class); |
| 77 | + } |
| 78 | + } |
44 | 79 |
|
| 80 | + @Test |
| 81 | + void defaultMethodEndpointAdapter() { |
| 82 | + try (ConfigurableApplicationContext applicationContext = load(CustomDefaultMethodEndpointAdapterConfig.class)) { |
| 83 | + assertThat(applicationContext.getBean(DefaultMethodEndpointAdapter.class)) |
| 84 | + .isInstanceOf(MyDefaultMethodEndpointAdapter.class); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + private ConfigurableApplicationContext load(Class<?>... componentClasses) { |
45 | 89 | AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(); |
46 | | - applicationContext.register(TestConfig.class); |
| 90 | + applicationContext.register(componentClasses); |
47 | 91 | applicationContext.refresh(); |
48 | | - |
49 | | - this.applicationContext = applicationContext; |
| 92 | + return applicationContext; |
50 | 93 | } |
51 | 94 |
|
52 | | - @Test |
53 | | - public void interceptors() { |
| 95 | + @Configuration(proxyBeanMethods = false) |
| 96 | + static class CustomInterceptorConfig extends WsConfigurationSupport { |
54 | 97 |
|
55 | | - PayloadRootAnnotationMethodEndpointMapping endpointMapping = this.applicationContext |
56 | | - .getBean(PayloadRootAnnotationMethodEndpointMapping.class); |
| 98 | + @Override |
| 99 | + protected void addInterceptors(List<EndpointInterceptor> interceptors) { |
| 100 | + interceptors.add(new MyInterceptor()); |
| 101 | + } |
57 | 102 |
|
58 | | - assertThat(endpointMapping.getOrder()).isEqualTo(0); |
| 103 | + static class MyInterceptor extends EndpointInterceptorAdapter { |
59 | 104 |
|
60 | | - EndpointInterceptor[] interceptors = endpointMapping.getInterceptors(); |
| 105 | + } |
61 | 106 |
|
62 | | - assertThat(interceptors).hasSize(1); |
63 | | - assertThat(interceptors[0]).isInstanceOf(MyInterceptor.class); |
64 | 107 | } |
65 | 108 |
|
66 | | - @Test |
67 | | - public void defaultMethodEndpointAdapter() { |
| 109 | + @Configuration(proxyBeanMethods = false) |
| 110 | + static class CustomArgumentResolverConfig extends WsConfigurationSupport { |
| 111 | + |
| 112 | + @Override |
| 113 | + protected void addArgumentResolvers(List<MethodArgumentResolver> argumentResolvers) { |
| 114 | + assertThat(argumentResolvers).isNotEmpty(); |
| 115 | + argumentResolvers.add(0, new MyArgumentResolver()); |
| 116 | + } |
68 | 117 |
|
69 | | - DefaultMethodEndpointAdapter endpointAdapter = this.applicationContext |
70 | | - .getBean(DefaultMethodEndpointAdapter.class); |
| 118 | + static class MyArgumentResolver extends SourcePayloadMethodProcessor { |
| 119 | + |
| 120 | + } |
71 | 121 |
|
72 | | - assertThat(endpointAdapter).isNotNull(); |
73 | | - assertThat(endpointAdapter).isInstanceOf(MyDefaultMethodEndpointAdapter.class); |
74 | 122 | } |
75 | 123 |
|
76 | | - @Configuration |
77 | | - public static class TestConfig extends WsConfigurationSupport { |
| 124 | + @Configuration(proxyBeanMethods = false) |
| 125 | + static class CustomReturnValueHandlerConfig extends WsConfigurationSupport { |
78 | 126 |
|
79 | 127 | @Override |
80 | | - protected void addInterceptors(List<EndpointInterceptor> interceptors) { |
81 | | - interceptors.add(new MyInterceptor()); |
| 128 | + protected void addReturnValueHandlers(List<MethodReturnValueHandler> returnValueHandlers) { |
| 129 | + assertThat(returnValueHandlers).isNotEmpty(); |
| 130 | + returnValueHandlers.add(0, new MyReturnValueHandler()); |
| 131 | + } |
| 132 | + |
| 133 | + static class MyReturnValueHandler extends SourcePayloadMethodProcessor { |
| 134 | + |
82 | 135 | } |
83 | 136 |
|
| 137 | + } |
| 138 | + |
| 139 | + @Configuration(proxyBeanMethods = false) |
| 140 | + static class CustomDefaultMethodEndpointAdapterConfig extends WsConfigurationSupport { |
| 141 | + |
84 | 142 | @Bean |
85 | 143 | @Override |
86 | 144 | public DefaultMethodEndpointAdapter defaultMethodEndpointAdapter() { |
87 | 145 | return new MyDefaultMethodEndpointAdapter(); |
88 | 146 | } |
89 | 147 |
|
90 | | - } |
91 | | - |
92 | | - public static class MyInterceptor extends EndpointInterceptorAdapter { |
| 148 | + static class MyDefaultMethodEndpointAdapter extends DefaultMethodEndpointAdapter { |
93 | 149 |
|
94 | | - } |
95 | | - |
96 | | - public static class MyDefaultMethodEndpointAdapter extends DefaultMethodEndpointAdapter { |
| 150 | + } |
97 | 151 |
|
98 | 152 | } |
99 | 153 |
|
|
0 commit comments