Added test for DI in <sws:interceptors/>
Added test case in InterceptorsBeanDefinitionParserTest to test for both property and autowired injection on intercetors defined in <sws:interceptor/> blocks. Issue: SWS-814
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2005-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.server.EndpointInterceptor;
|
||||
|
||||
public class DummyInterceptor implements EndpointInterceptor {
|
||||
|
||||
@Autowired
|
||||
private DummyInterceptorDependency autowiredDependency;
|
||||
|
||||
private DummyInterceptorDependency propertyDependency;
|
||||
|
||||
public void setPropertyDependency(DummyInterceptorDependency propertyDependency) {
|
||||
this.propertyDependency = propertyDependency;
|
||||
}
|
||||
|
||||
public DummyInterceptorDependency getPropertyDependency() {
|
||||
return propertyDependency;
|
||||
}
|
||||
|
||||
public DummyInterceptorDependency getAutowiredDependency() {
|
||||
return autowiredDependency;
|
||||
}
|
||||
|
||||
public boolean handleRequest(MessageContext messageContext, Object endpoint)
|
||||
throws Exception {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleResponse(MessageContext messageContext, Object endpoint)
|
||||
throws Exception {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean handleFault(MessageContext messageContext, Object endpoint)
|
||||
throws Exception {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void afterCompletion(MessageContext messageContext, Object endpoint,
|
||||
Exception ex) throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.config;
|
||||
|
||||
public class DummyInterceptorDependency {
|
||||
|
||||
}
|
||||
@@ -20,16 +20,16 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.ws.server.endpoint.interceptor.DelegatingSmartEndpointInterceptor;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadRootSmartSoapEndpointInterceptor;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.SoapActionSmartEndpointInterceptor;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class InterceptorsBeanDefinitionParserTest {
|
||||
|
||||
@Test
|
||||
@@ -62,4 +62,19 @@ public class InterceptorsBeanDefinitionParserTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void injection() throws Exception {
|
||||
ApplicationContext applicationContext =
|
||||
new ClassPathXmlApplicationContext("interceptorsBeanDefinitionParserInjectionTest.xml", getClass());
|
||||
|
||||
List<DelegatingSmartEndpointInterceptor> interceptors = new ArrayList<DelegatingSmartEndpointInterceptor>(
|
||||
applicationContext.getBeansOfType(DelegatingSmartEndpointInterceptor.class).values());
|
||||
assertEquals("not enough smart interceptors found", 1, interceptors.size());
|
||||
|
||||
DummyInterceptor interceptor =
|
||||
(DummyInterceptor) interceptors.get(0).getDelegate();
|
||||
assertNotNull(interceptor.getPropertyDependency());
|
||||
assertNotNull(interceptor.getAutowiredDependency());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:sws="http://www.springframework.org/schema/web-services"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
|
||||
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
|
||||
|
||||
<context:annotation-config/>
|
||||
|
||||
<sws:interceptors>
|
||||
<bean class="org.springframework.ws.config.DummyInterceptor">
|
||||
<property name="propertyDependency" ref="dependency" />
|
||||
</bean>
|
||||
</sws:interceptors>
|
||||
|
||||
<bean id="dependency" class="org.springframework.ws.config.DummyInterceptorDependency"/>
|
||||
|
||||
</beans>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user