INT-3115 Fix EvaluationContext Initialization
There were several "helper" classes where the context was initialized in the constructor, before the BeanFactory was passed in. Generally fixed by adding the BeanFactory to the constructor args. Other cases where the container-managed bean instantiated a helper and never passed in the BeanFactory. Finally, a fix to ExpressionUtils where the caller had a BeanFactory but the BF did not contain an EvaluationContext factory bean, the BeanResolver was not set up. This is unlikely in a Spring Integration application, but added for completeness. INT-3115 Add a BeanFactory to Test Cases Change the WARN log in ExpressionUtils to a fatal exception to detect cases where an EvaluationContext was created without a BeanFactory. While this was generally in test cases, it also exposed some cases in code where the context was initialized without a BF. polishing on merge
This commit is contained in:
committed by
Mark Fisher
parent
06b06b1c8f
commit
52b340956f
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* 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.
|
||||
@@ -30,6 +30,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -57,6 +59,7 @@ public class HttpRequestHandlingControllerTests {
|
||||
public void sendOnly() throws Exception {
|
||||
QueueChannel requestChannel = new QueueChannel();
|
||||
HttpRequestHandlingController controller = new HttpRequestHandlingController(false);
|
||||
controller.setBeanFactory(mock(BeanFactory.class));
|
||||
controller.setRequestChannel(requestChannel);
|
||||
controller.setViewName("foo");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -80,6 +83,7 @@ public class HttpRequestHandlingControllerTests {
|
||||
public void sendOnlyViewExpression() throws Exception {
|
||||
QueueChannel requestChannel = new QueueChannel();
|
||||
HttpRequestHandlingController controller = new HttpRequestHandlingController(false);
|
||||
controller.setBeanFactory(mock(BeanFactory.class));
|
||||
controller.setRequestChannel(requestChannel);
|
||||
Expression viewExpression = new SpelExpressionParser().parseExpression("'baz'");
|
||||
controller.setViewExpression(viewExpression);
|
||||
@@ -111,6 +115,7 @@ public class HttpRequestHandlingControllerTests {
|
||||
};
|
||||
requestChannel.subscribe(handler);
|
||||
HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
|
||||
controller.setBeanFactory(mock(BeanFactory.class));
|
||||
controller.setRequestChannel(requestChannel);
|
||||
controller.setViewName("foo");
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -142,6 +147,7 @@ public class HttpRequestHandlingControllerTests {
|
||||
};
|
||||
requestChannel.subscribe(handler);
|
||||
HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
|
||||
controller.setBeanFactory(mock(BeanFactory.class));
|
||||
controller.setRequestChannel(requestChannel);
|
||||
Expression viewExpression = new SpelExpressionParser().parseExpression("headers['bar']");
|
||||
controller.setViewExpression(viewExpression);
|
||||
@@ -171,6 +177,7 @@ public class HttpRequestHandlingControllerTests {
|
||||
};
|
||||
requestChannel.subscribe(handler);
|
||||
HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
|
||||
controller.setBeanFactory(mock(BeanFactory.class));
|
||||
controller.setRequestChannel(requestChannel);
|
||||
Expression viewExpression = new SpelExpressionParser().parseExpression("headers['bar']");
|
||||
controller.setViewExpression(viewExpression);
|
||||
@@ -198,6 +205,7 @@ public class HttpRequestHandlingControllerTests {
|
||||
};
|
||||
requestChannel.subscribe(handler);
|
||||
HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
|
||||
controller.setBeanFactory(mock(BeanFactory.class));
|
||||
controller.setRequestChannel(requestChannel);
|
||||
controller.setViewName("foo");
|
||||
controller.setReplyKey("myReply");
|
||||
@@ -229,6 +237,7 @@ public class HttpRequestHandlingControllerTests {
|
||||
};
|
||||
requestChannel.subscribe(handler);
|
||||
HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
|
||||
controller.setBeanFactory(mock(BeanFactory.class));
|
||||
controller.setRequestChannel(requestChannel);
|
||||
controller.setViewName("foo");
|
||||
controller.setExtractReplyPayload(false);
|
||||
@@ -259,6 +268,7 @@ public class HttpRequestHandlingControllerTests {
|
||||
}
|
||||
};
|
||||
HttpRequestHandlingController controller = new HttpRequestHandlingController(false);
|
||||
controller.setBeanFactory(mock(BeanFactory.class));
|
||||
controller.setRequestChannel(requestChannel);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setMethod("POST");
|
||||
@@ -295,6 +305,7 @@ public class HttpRequestHandlingControllerTests {
|
||||
};
|
||||
requestChannel.subscribe(handler);
|
||||
final HttpRequestHandlingController controller = new HttpRequestHandlingController(true);
|
||||
controller.setBeanFactory(mock(BeanFactory.class));
|
||||
controller.setRequestChannel(requestChannel);
|
||||
controller.setViewName("foo");
|
||||
final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* 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.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.http.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
@@ -27,6 +28,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.http.HttpInputMessage;
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -59,6 +62,7 @@ public class HttpRequestHandlingMessagingGatewayTests {
|
||||
public void getRequestGeneratesMapPayload() throws Exception {
|
||||
QueueChannel requestChannel = new QueueChannel();
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(false);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setRequestChannel(requestChannel);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setMethod("GET");
|
||||
@@ -77,6 +81,7 @@ public class HttpRequestHandlingMessagingGatewayTests {
|
||||
public void stringExpectedWithoutReply() throws Exception {
|
||||
QueueChannel requestChannel = new QueueChannel();
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(false);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setRequestPayloadType(String.class);
|
||||
gateway.setRequestChannel(requestChannel);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -105,6 +110,7 @@ public class HttpRequestHandlingMessagingGatewayTests {
|
||||
}
|
||||
});
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setRequestPayloadType(String.class);
|
||||
gateway.setRequestChannel(requestChannel);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -131,6 +137,7 @@ public class HttpRequestHandlingMessagingGatewayTests {
|
||||
}
|
||||
});
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setRequestPayloadType(String.class);
|
||||
gateway.setRequestChannel(requestChannel);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
@@ -155,6 +162,7 @@ public class HttpRequestHandlingMessagingGatewayTests {
|
||||
}
|
||||
};
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setRequestChannel(requestChannel);
|
||||
gateway.setConvertExceptions(true);
|
||||
gateway.setMessageConverters(Arrays.<HttpMessageConverter<?>>asList(new TestHttpMessageConverter()));
|
||||
@@ -171,6 +179,7 @@ public class HttpRequestHandlingMessagingGatewayTests {
|
||||
public void multiValueParameterMap() throws Exception {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(false);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setRequestChannel(channel);
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test");
|
||||
request.setParameter("foo", "123");
|
||||
@@ -197,6 +206,7 @@ public class HttpRequestHandlingMessagingGatewayTests {
|
||||
public void serializableRequestBody() throws Exception {
|
||||
QueueChannel channel = new QueueChannel();
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(false);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setRequestPayloadType(TestBean.class);
|
||||
gateway.setRequestChannel(channel);
|
||||
|
||||
@@ -251,6 +261,7 @@ public class HttpRequestHandlingMessagingGatewayTests {
|
||||
messageConverters.add(messageConverter);
|
||||
|
||||
final HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setMessageConverters(messageConverters);
|
||||
gateway.setRequestChannel(requestChannel);
|
||||
|
||||
@@ -272,7 +283,7 @@ public class HttpRequestHandlingMessagingGatewayTests {
|
||||
|
||||
private class ContentTypeCheckingMockHttpServletResponse extends MockHttpServletResponse {
|
||||
|
||||
private List<String> contentTypeList = new ArrayList<String>();
|
||||
private final List<String> contentTypeList = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public void addHeader(String name, String value) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* 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.
|
||||
@@ -18,10 +18,13 @@ package org.springframework.integration.http.inbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.ExpressionParser;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.Message;
|
||||
@@ -36,6 +39,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class HttpRequestHandlingMessagingGatewayWithPathMappingTests {
|
||||
|
||||
@@ -63,6 +67,7 @@ public class HttpRequestHandlingMessagingGatewayWithPathMappingTests {
|
||||
request.setRequestURI("/fname/bill/lname/clinton");
|
||||
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setPath("/fname/{f}/lname/{l}");
|
||||
gateway.setRequestChannel(echoChannel);
|
||||
|
||||
@@ -93,6 +98,7 @@ public class HttpRequestHandlingMessagingGatewayWithPathMappingTests {
|
||||
request.setRequestURI("/fname/bill/lname/clinton");
|
||||
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setPath("/fname/{f}/lname/{l}");
|
||||
gateway.setRequestChannel(echoChannel);
|
||||
gateway.setPayloadExpression(PARSER.parseExpression("#pathVariables.f"));
|
||||
@@ -124,6 +130,7 @@ public class HttpRequestHandlingMessagingGatewayWithPathMappingTests {
|
||||
request.setRequestURI("/fname/bill/lname/clinton");
|
||||
|
||||
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true);
|
||||
gateway.setBeanFactory(mock(BeanFactory.class));
|
||||
gateway.setPath("/fname/{f}/lname/{l}");
|
||||
gateway.setRequestChannel(echoChannel);
|
||||
gateway.setPayloadExpression(PARSER.parseExpression("#pathVariables"));
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.http.outbound;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -27,6 +28,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -39,6 +41,7 @@ import org.springframework.integration.message.GenericMessage;
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
* @author Wallace Wadge
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*/
|
||||
public class UriVariableExpressionTests {
|
||||
@@ -56,6 +59,7 @@ public class UriVariableExpressionTests {
|
||||
throw new RuntimeException("intentional");
|
||||
}
|
||||
});
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Message<?> message = new GenericMessage<Object>("bar");
|
||||
Exception exception = null;
|
||||
@@ -86,6 +90,8 @@ public class UriVariableExpressionTests {
|
||||
throw new RuntimeException("intentional");
|
||||
}
|
||||
});
|
||||
handler.setBeanFactory(mock(BeanFactory.class));
|
||||
handler.afterPropertiesSet();
|
||||
Message<?> message = new GenericMessage<Object>("bar");
|
||||
Exception exception = null;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user