|
25 | 25 | import org.springframework.ws.context.MessageContext; |
26 | 26 | import org.springframework.ws.server.EndpointInterceptor; |
27 | 27 | import org.springframework.ws.server.EndpointInvocationChain; |
| 28 | +import org.springframework.ws.server.SmartEndpointInterceptor; |
28 | 29 | import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor; |
29 | 30 | import org.springframework.ws.server.endpoint.interceptor.EndpointInterceptorAdapter; |
30 | 31 |
|
31 | 32 | import static org.assertj.core.api.Assertions.assertThat; |
| 33 | +import static org.mockito.BDDMockito.given; |
| 34 | +import static org.mockito.Mockito.mock; |
| 35 | +import static org.mockito.Mockito.verify; |
32 | 36 |
|
33 | 37 | /** |
34 | 38 | * Test case for {@link AbstractEndpointMapping}. |
@@ -124,6 +128,55 @@ protected Object getEndpointInternal(MessageContext givenRequest) { |
124 | 128 | assertThat(result.getInterceptors()[1]).isInstanceOf(MySmartEndpointInterceptor.class); |
125 | 129 | } |
126 | 130 |
|
| 131 | + @Test |
| 132 | + void smartEndpointInterceptorAddedOnlyIfNecessary() throws Exception { |
| 133 | + StaticApplicationContext applicationContext = new StaticApplicationContext(); |
| 134 | + Object endpoint = new Object(); |
| 135 | + SmartEndpointInterceptor firstInterceptor = mock(SmartEndpointInterceptor.class); |
| 136 | + given(firstInterceptor.shouldIntercept(this.messageContext, endpoint)).willReturn(false); |
| 137 | + applicationContext.registerBean("first", SmartEndpointInterceptor.class, () -> firstInterceptor); |
| 138 | + SmartEndpointInterceptor secondInterceptor = mock(SmartEndpointInterceptor.class); |
| 139 | + given(secondInterceptor.shouldIntercept(this.messageContext, endpoint)).willReturn(true); |
| 140 | + applicationContext.registerBean("second", SmartEndpointInterceptor.class, () -> secondInterceptor); |
| 141 | + |
| 142 | + AbstractEndpointMapping mapping = new AbstractEndpointMapping() { |
| 143 | + @Override |
| 144 | + protected Object getEndpointInternal(MessageContext givenRequest) { |
| 145 | + assertThat(givenRequest).isEqualTo(EndpointMappingTest.this.messageContext); |
| 146 | + return endpoint; |
| 147 | + } |
| 148 | + }; |
| 149 | + mapping.setApplicationContext(applicationContext); |
| 150 | + EndpointInvocationChain result = mapping.getEndpoint(this.messageContext); |
| 151 | + assertThat(result).isNotNull(); |
| 152 | + assertThat(result.getInterceptors()).singleElement().isSameAs(secondInterceptor); |
| 153 | + verify(firstInterceptor).shouldIntercept(this.messageContext, endpoint); |
| 154 | + verify(secondInterceptor).shouldIntercept(this.messageContext, endpoint); |
| 155 | + } |
| 156 | + |
| 157 | + @Test |
| 158 | + void smartEndpointInterceptorSetAsInterceptorAreHandled() throws Exception { |
| 159 | + Object endpoint = new Object(); |
| 160 | + SmartEndpointInterceptor firstInterceptor = mock(SmartEndpointInterceptor.class); |
| 161 | + given(firstInterceptor.shouldIntercept(this.messageContext, endpoint)).willReturn(false); |
| 162 | + SmartEndpointInterceptor secondInterceptor = mock(SmartEndpointInterceptor.class); |
| 163 | + given(secondInterceptor.shouldIntercept(this.messageContext, endpoint)).willReturn(true); |
| 164 | + |
| 165 | + AbstractEndpointMapping mapping = new AbstractEndpointMapping() { |
| 166 | + @Override |
| 167 | + protected Object getEndpointInternal(MessageContext givenRequest) { |
| 168 | + assertThat(givenRequest).isEqualTo(EndpointMappingTest.this.messageContext); |
| 169 | + return endpoint; |
| 170 | + } |
| 171 | + }; |
| 172 | + mapping.setInterceptors(new EndpointInterceptor[] { firstInterceptor, secondInterceptor }); |
| 173 | + EndpointInvocationChain result = mapping.getEndpoint(this.messageContext); |
| 174 | + assertThat(result).isNotNull(); |
| 175 | + assertThat(result.getInterceptors()).singleElement().isSameAs(secondInterceptor); |
| 176 | + verify(firstInterceptor).shouldIntercept(this.messageContext, endpoint); |
| 177 | + verify(secondInterceptor).shouldIntercept(this.messageContext, endpoint); |
| 178 | + } |
| 179 | + |
127 | 180 | @Test |
128 | 181 | public void endpointBeanName() throws Exception { |
129 | 182 |
|
|
0 commit comments