Merge pull request #587 from olegz/INT-2712

This commit is contained in:
Gary Russell
2012-08-14 15:03:13 -04:00
2 changed files with 28 additions and 17 deletions

View File

@@ -32,7 +32,7 @@ import org.springframework.context.expression.BeanFactoryResolver;
import org.springframework.context.expression.MapAccessor; import org.springframework.context.expression.MapAccessor;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.support.ConfigurableConversionService; import org.springframework.core.convert.converter.ConverterRegistry;
import org.springframework.core.convert.support.GenericConversionService; import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.expression.Expression; import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression; import org.springframework.expression.common.LiteralExpression;
@@ -291,17 +291,17 @@ public class HttpRequestExecutingMessageHandler extends AbstractReplyProducingMe
if (conversionService == null){ if (conversionService == null){
conversionService = new GenericConversionService(); conversionService = new GenericConversionService();
} }
if (conversionService instanceof ConfigurableConversionService){ if (conversionService instanceof ConverterRegistry){
ConfigurableConversionService configurableConversionService = ConverterRegistry converterRegistry =
(ConfigurableConversionService) conversionService; (ConverterRegistry) conversionService;
configurableConversionService.addConverter(new ClassToStringConverter()); converterRegistry.addConverter(new ClassToStringConverter());
configurableConversionService.addConverter(new ObjectToStringConverter()); converterRegistry.addConverter(new ObjectToStringConverter());
this.evaluationContext.setTypeConverter(new StandardTypeConverter(configurableConversionService)); this.evaluationContext.setTypeConverter(new StandardTypeConverter(conversionService));
} }
else { else {
logger.warn("ConversionService is not an instance of ConfigurableConversionService therefore" + logger.warn("ConversionService is not an instance of ConverterRegistry therefore" +
"ClassToStringConverter and ObjectToStringConverter will not be registered"); "ClassToStringConverter and ObjectToStringConverter will not be registered");
} }
} }

View File

@@ -21,10 +21,7 @@ import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertSame; import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@@ -32,19 +29,22 @@ import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.xml.transform.Source; import javax.xml.transform.Source;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.DirectFieldAccessor; import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterRegistry;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
@@ -716,12 +716,23 @@ public class HttpRequestExecutingMessageHandlerTests {
HttpRequestExecutingMessageHandler handler = HttpRequestExecutingMessageHandler handler =
new HttpRequestExecutingMessageHandler("http://www.springsource.org/spring-integration"); new HttpRequestExecutingMessageHandler("http://www.springsource.org/spring-integration");
ConfigurableListableBeanFactory bf = new DefaultListableBeanFactory(); ConfigurableListableBeanFactory bf = new DefaultListableBeanFactory();
ConfigurableConversionService mockConfigurableConversionService = mock(ConfigurableConversionService.class); ProxyFactory pf = new ProxyFactory(new Class[] {ConversionService.class, ConverterRegistry.class});
bf.registerSingleton("integrationConversionService", mockConfigurableConversionService); final AtomicInteger converterCount = new AtomicInteger();
pf.addAdvice(new MethodInterceptor() {
public Object invoke(MethodInvocation invocation) throws Throwable {
if (invocation.getMethod().getName().equals("addConverter")) {
converterCount.incrementAndGet();
}
return null;
}
});
ConversionService mockConversionService = (ConversionService) pf.getProxy();
bf.registerSingleton("integrationConversionService", mockConversionService);
handler.setBeanFactory(bf); handler.setBeanFactory(bf);
handler.afterPropertiesSet(); handler.afterPropertiesSet();
verify(mockConfigurableConversionService, times(2)).addConverter(any(Converter.class)); assertEquals(2, converterCount.get());
assertSame(mockConfigurableConversionService, TestUtils.getPropertyValue(handler, "conversionService")); assertSame(mockConversionService, TestUtils.getPropertyValue(handler, "conversionService"));
} }
public static class City{ public static class City{