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:
Gary Russell
2013-08-26 20:45:48 -04:00
committed by Mark Fisher
parent 06b06b1c8f
commit 52b340956f
55 changed files with 531 additions and 119 deletions

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2011 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.
@@ -31,7 +31,7 @@ import org.springframework.util.ReflectionUtils;
/**
* FactoryBean for creating {@link MessageHandler} instances to handle a message as a SpEL expression.
*
*
* @author Dave Syer
* @author Mark Fisher
* @author Oleg Zhurakousky
@@ -48,9 +48,10 @@ public class ExpressionControlBusFactoryBean extends AbstractSimpleMessageHandle
this.sendTimeout = sendTimeout;
}
@Override
protected MessageHandler createHandler() {
ExpressionCommandMessageProcessor processor = new ExpressionCommandMessageProcessor(this.methodFilter);
processor.setBeanFactory(this.getBeanFactory());
ExpressionCommandMessageProcessor processor =
new ExpressionCommandMessageProcessor(this.methodFilter, this.getBeanFactory());
ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
if (this.sendTimeout != null) {
handler.setSendTimeout(this.sendTimeout);

View File

@@ -20,6 +20,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.expression.BeanFactoryResolver;
import org.springframework.context.expression.MapAccessor;
import org.springframework.core.convert.ConversionService;
import org.springframework.expression.spel.support.StandardEvaluationContext;
@@ -45,12 +46,16 @@ public abstract class ExpressionUtils {
* @param conversionService the conversion service.
* @return the evaluation context.
*/
private static StandardEvaluationContext createStandardEvaluationContext(ConversionService conversionService) {
private static StandardEvaluationContext createStandardEvaluationContext(ConversionService conversionService,
BeanFactory beanFactory) {
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
evaluationContext.addPropertyAccessor(new MapAccessor());
if (conversionService != null) {
evaluationContext.setTypeConverter(new StandardTypeConverter(conversionService));
}
if (beanFactory != null) {
evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
}
return evaluationContext;
}
@@ -85,7 +90,7 @@ public abstract class ExpressionUtils {
if (beanFactory != null) {
conversionService = IntegrationContextUtils.getConversionService(beanFactory);
}
evaluationContext = createStandardEvaluationContext(conversionService);
evaluationContext = createStandardEvaluationContext(conversionService, beanFactory);
}
return evaluationContext;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2010 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. 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.
@@ -18,6 +18,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.AccessException;
import org.springframework.expression.EvaluationContext;
@@ -32,9 +33,10 @@ import org.springframework.integration.Message;
/**
* A MessageProcessor implementation that expects an Expression or expressionString
* as the Message payload. When processing, it simply evaluates that expression.
*
*
* @author Dave Syer
* @author Mark Fisher
* @author Gary Russell
* @since 2.0
*/
public class ExpressionCommandMessageProcessor extends AbstractMessageProcessor<Object> {
@@ -43,9 +45,16 @@ public class ExpressionCommandMessageProcessor extends AbstractMessageProcessor<
}
public ExpressionCommandMessageProcessor(MethodFilter methodFilter) {
this(methodFilter, null);
}
public ExpressionCommandMessageProcessor(MethodFilter methodFilter, BeanFactory beanFactory) {
if (beanFactory != null) {
this.setBeanFactory(beanFactory);
}
if (methodFilter != null) {
MethodResolver methodResolver = new ExpressionCommandMethodResolver(methodFilter);
this.getEvaluationContext().setMethodResolvers(Collections.singletonList(methodResolver));
this.getEvaluationContext(false).setMethodResolvers(Collections.singletonList(methodResolver));
}
}
@@ -54,6 +63,7 @@ public class ExpressionCommandMessageProcessor extends AbstractMessageProcessor<
* Evaluates the Message payload expression as a command.
* @throws IllegalArgumentException if the payload is not an Exception or String
*/
@Override
public Object processMessage(Message<?> message) {
Object expression = message.getPayload();
if (expression instanceof Expression) {
@@ -72,10 +82,11 @@ public class ExpressionCommandMessageProcessor extends AbstractMessageProcessor<
private ExpressionCommandMethodResolver(MethodFilter methodFilter) {
this.methodFilter = methodFilter;
this.methodFilter = methodFilter;
}
@Override
public MethodExecutor resolve(EvaluationContext context,
Object targetObject, String name, List<TypeDescriptor> argumentTypes) throws AccessException {
this.validateMethod(targetObject, name, (argumentTypes != null ? argumentTypes.size() : 0));
@@ -96,7 +107,7 @@ public class ExpressionCommandMessageProcessor extends AbstractMessageProcessor<
}
List<Method> supportedMethods = this.methodFilter.filter(candidates);
if (supportedMethods.size() == 0) {
String methodDescription = (candidates.size() > 0) ? candidates.get(0).toString() : name;
String methodDescription = (candidates.size() > 0) ? candidates.get(0).toString() : name;
throw new EvaluationException("The method '" + methodDescription + "' is not supported by this command processor. " +
"If using the Control Bus, consider adding @ManagedOperation or @ManagedAttribute.");
}

View File

@@ -13,13 +13,15 @@
package org.springframework.integration.aggregator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
@@ -35,6 +37,7 @@ import org.springframework.integration.support.MessageBuilder;
* @author Alex Peters
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
*/
public class ExpressionEvaluatingCorrelationStrategyTests {
@@ -57,6 +60,8 @@ public class ExpressionEvaluatingCorrelationStrategyTests {
ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
Expression expression = parser.parseExpression("payload.substring(0,1)");
strategy = new ExpressionEvaluatingCorrelationStrategy(expression);
strategy.setBeanFactory(mock(BeanFactory.class));
strategy.afterPropertiesSet();
Object correlationKey = strategy.getCorrelationKey(new GenericMessage<String>("bla"));
assertThat(correlationKey, is(instanceOf(String.class)));
assertThat((String) correlationKey, is("b"));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 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.aggregator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
@@ -30,19 +31,21 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.Message;
import org.springframework.integration.store.MessageGroup;
import org.springframework.integration.support.MessageBuilder;
/**
* @author Alex Peters
* @author Mark Fisher
* @author Mark Fisher
* @author Gary Russell
*/
@RunWith(MockitoJUnitRunner.class)
public class ExpressionEvaluatingMessageGroupProcessorTests {
private ExpressionEvaluatingMessageGroupProcessor processor;
@Mock
private MessageGroup group;
@@ -62,6 +65,7 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
public void testProcessAndSendWithSizeExpressionEvaluated() throws Exception {
when(group.getMessages()).thenReturn(messages);
processor = new ExpressionEvaluatingMessageGroupProcessor("#root.size()");
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
assertTrue(result instanceof Message<?>);
Message<?> resultMessage = (Message<?>) result;
@@ -72,7 +76,9 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
public void testProcessAndCheckHeaders() throws Exception {
when(group.getMessages()).thenReturn(messages);
processor = new ExpressionEvaluatingMessageGroupProcessor("#root");
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
processor.setBeanFactory(mock(BeanFactory.class));
assertTrue(result instanceof Message<?>);
Message<?> resultMessage = (Message<?>) result;
assertEquals("bar", resultMessage.getHeaders().get("foo"));
@@ -82,6 +88,7 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
public void testProcessAndSendWithProjectionExpressionEvaluated() throws Exception {
when(group.getMessages()).thenReturn(messages);
processor = new ExpressionEvaluatingMessageGroupProcessor("![payload]");
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
assertTrue(result instanceof Message<?>);
Message<?> resultMessage = (Message<?>) result;
@@ -99,6 +106,7 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
public void testProcessAndSendWithFilterAndProjectionExpressionEvaluated() throws Exception {
when(group.getMessages()).thenReturn(messages);
processor = new ExpressionEvaluatingMessageGroupProcessor("?[payload>2].![payload]");
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
assertTrue(result instanceof Message<?>);
Message<?> resultMessage = (Message<?>) result;
@@ -115,6 +123,7 @@ public class ExpressionEvaluatingMessageGroupProcessorTests {
when(group.getMessages()).thenReturn(messages);
processor = new ExpressionEvaluatingMessageGroupProcessor(String.format("T(%s).sum(?[payload>2].![payload])",
getClass().getName()));
processor.setBeanFactory(mock(BeanFactory.class));
Object result = processor.processMessageGroup(group);
assertTrue(result instanceof Message<?>);
Message<?> resultMessage = (Message<?>) result;

View File

@@ -1,24 +1,42 @@
/*
* 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.integration.aggregator;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.store.SimpleMessageGroup;
/**
* @author Alex Peters
* @author Dave Syer
*
* @author Gary Russell
*
*/
public class ExpressionEvaluatingReleaseStrategyTests {
private ExpressionEvaluatingReleaseStrategy strategy;
private SimpleMessageGroup messages = new SimpleMessageGroup("foo");
private final SimpleMessageGroup messages = new SimpleMessageGroup("foo");
@Before
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -31,18 +49,21 @@ public class ExpressionEvaluatingReleaseStrategyTests {
@Test
public void testCompletedWithSizeSpelEvaluated() throws Exception {
strategy = new ExpressionEvaluatingReleaseStrategy("#root.size()==5");
strategy.setBeanFactory(mock(BeanFactory.class));
assertThat(strategy.canRelease(messages), is(true));
}
@Test
public void testCompletedWithFilterSpelEvaluated() throws Exception {
strategy = new ExpressionEvaluatingReleaseStrategy("!?[payload==5].empty");
strategy.setBeanFactory(mock(BeanFactory.class));
assertThat(strategy.canRelease(messages), is(true));
}
@Test
public void testCompletedWithFilterSpelReturnsNotCompleted() throws Exception {
strategy = new ExpressionEvaluatingReleaseStrategy("!?[payload==6].empty");
strategy.setBeanFactory(mock(BeanFactory.class));
assertThat(strategy.canRelease(messages), is(false));
}

View File

@@ -25,6 +25,7 @@ import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.integration.Message;
@@ -43,10 +44,11 @@ public class MessagePublishingInterceptorTests {
private final QueueChannel testChannel = new QueueChannel();
private DefaultListableBeanFactory beanFactory;
@Before
public void setup() {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory = new DefaultListableBeanFactory();
channelResolver = new BeanFactoryChannelResolver(beanFactory);
beanFactory.registerSingleton("c", testChannel);
}
@@ -55,6 +57,7 @@ public class MessagePublishingInterceptorTests {
public void returnValue() {
PublisherMetadataSource metadataSource = new TestPublisherMetadataSource();
MessagePublishingInterceptor interceptor = new MessagePublishingInterceptor(metadataSource);
interceptor.setBeanFactory(beanFactory);
interceptor.setChannelResolver(channelResolver);
ProxyFactory pf = new ProxyFactory(new TestBeanImpl());
pf.addAdvice(interceptor);
@@ -82,6 +85,7 @@ public class MessagePublishingInterceptorTests {
metadataSource.setHeaderExpressionMap(headerExpressionMap);
MessagePublishingInterceptor interceptor = new MessagePublishingInterceptor(metadataSource);
interceptor.setBeanFactory(beanFactory);
interceptor.setChannelResolver(channelResolver);
ProxyFactory pf = new ProxyFactory(new TestBeanImpl());
pf.addAdvice(interceptor);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 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.
@@ -17,6 +17,7 @@
package org.springframework.integration.endpoint;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
import java.util.HashMap;
@@ -26,6 +27,7 @@ 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.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
@@ -38,6 +40,7 @@ import org.springframework.util.ErrorHandler;
/**
* @author Mark Fisher
* @author Gary Russell
* @since 2.0
*/
public class ExpressionEvaluatingMessageSourceIntegrationTests {
@@ -58,6 +61,7 @@ public class ExpressionEvaluatingMessageSourceIntegrationTests {
factoryBean.afterPropertiesSet();
Expression expression = factoryBean.getObject();
ExpressionEvaluatingMessageSource<Object> source = new ExpressionEvaluatingMessageSource<Object>(expression, Object.class);
source.setBeanFactory(mock(BeanFactory.class));
source.setHeaderExpressions(headerExpressions);
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
adapter.setSource(source);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 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,8 +18,11 @@ package org.springframework.integration.endpoint;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
@@ -27,6 +30,7 @@ import org.springframework.integration.Message;
/**
* @author Mark Fisher
* @author Gary Russell
* @since 2.0
*/
public class ExpressionEvaluatingMessageSourceTests {
@@ -37,6 +41,7 @@ public class ExpressionEvaluatingMessageSourceTests {
Expression expression = new LiteralExpression("foo");
ExpressionEvaluatingMessageSource<String> source =
new ExpressionEvaluatingMessageSource<String>(expression, String.class);
source.setBeanFactory(mock(BeanFactory.class));
Message<?> message = source.receive();
assertNotNull(message);
assertEquals("foo", message.getPayload());
@@ -47,6 +52,7 @@ public class ExpressionEvaluatingMessageSourceTests {
Expression expression = new LiteralExpression("foo");
ExpressionEvaluatingMessageSource<Integer> source =
new ExpressionEvaluatingMessageSource<Integer>(expression, Integer.class);
source.setBeanFactory(mock(BeanFactory.class));
source.receive();
}

View File

@@ -18,12 +18,15 @@ package org.springframework.integration.endpoint;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.Message;
import org.springframework.integration.channel.QueueChannel;
@@ -57,6 +60,7 @@ public class PseudoTransactionalMessageSourceTests {
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor =
new ExpressionEvaluatingTransactionSynchronizationProcessor();
syncProcessor.setBeanFactory(mock(BeanFactory.class));
PollableChannel queueChannel = new QueueChannel();
syncProcessor.setBeforeCommitExpression(new SpelExpressionParser().parseExpression("#bix"));
syncProcessor.setBeforeCommitChannel(queueChannel);
@@ -101,6 +105,7 @@ public class PseudoTransactionalMessageSourceTests {
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor =
new ExpressionEvaluatingTransactionSynchronizationProcessor();
syncProcessor.setBeanFactory(mock(BeanFactory.class));
PollableChannel queueChannel = new QueueChannel();
syncProcessor.setAfterRollbackChannel(queueChannel);
syncProcessor.setAfterRollbackExpression(new SpelExpressionParser().parseExpression("#baz"));
@@ -142,6 +147,7 @@ public class PseudoTransactionalMessageSourceTests {
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor =
new ExpressionEvaluatingTransactionSynchronizationProcessor();
syncProcessor.setBeanFactory(mock(BeanFactory.class));
syncProcessor.setBeforeCommitExpression(new SpelExpressionParser().parseExpression("#bix"));
syncProcessor.setBeforeCommitChannel(queueChannel);
syncProcessor.setAfterCommitChannel(queueChannel);
@@ -187,6 +193,7 @@ public class PseudoTransactionalMessageSourceTests {
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor();
syncProcessor.setBeanFactory(mock(BeanFactory.class));
syncProcessor.setAfterRollbackChannel(queueChannel);
syncProcessor.setAfterRollbackExpression(new SpelExpressionParser().parseExpression("#baz"));
@@ -230,6 +237,7 @@ public class PseudoTransactionalMessageSourceTests {
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor();
syncProcessor.setBeanFactory(mock(BeanFactory.class));
syncProcessor.setAfterRollbackChannel(queueChannel);
syncProcessor.setAfterRollbackExpression(new SpelExpressionParser().parseExpression("#baz"));

View File

@@ -75,7 +75,7 @@ public class ExpressionUtilsTests {
new RootBeanDefinition(ConversionServiceFactoryBean.class));
context.refresh();
StandardEvaluationContext evalContext = ExpressionUtils.createStandardEvaluationContext(context);
assertNull(evalContext.getBeanResolver());
assertNotNull(evalContext.getBeanResolver());
TypeConverter typeConverter = evalContext.getTypeConverter();
assertNotNull(typeConverter);
assertNotSame(TestUtils.getPropertyValue(typeConverter, "defaultConversionService"),

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 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,12 +18,14 @@ package org.springframework.integration.gateway;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
@@ -33,12 +35,13 @@ import org.springframework.integration.message.GenericMessage;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @since 2.0
*/
public class AsyncGatewayTests {
// TODO: changed from 0 because of recurrent failure: is this right?
private long safety = 100;
private final long safety = 100;
@Test
public void futureWithMessageReturned() throws Exception {
@@ -48,6 +51,7 @@ public class AsyncGatewayTests {
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setServiceInterface(TestEchoService.class);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Future<Message<?>> f = service.returnMessage("foo");
@@ -67,6 +71,7 @@ public class AsyncGatewayTests {
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setServiceInterface(TestEchoService.class);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Future<String> f = service.returnString("foo");
@@ -87,6 +92,7 @@ public class AsyncGatewayTests {
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setServiceInterface(TestEchoService.class);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestEchoService service = (TestEchoService) proxyFactory.getObject();
Future<?> f = service.returnSomething("foo");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 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.gateway;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import java.lang.reflect.Method;
import java.util.HashMap;
@@ -25,6 +26,7 @@ import java.util.Map;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
@@ -36,6 +38,7 @@ import org.springframework.integration.support.MessageBuilder;
/**
* @author Mark Fisher
* @author Gary Russell
*/
public class GatewayMethodInboundMessageMapperToMessageTests {
@@ -43,6 +46,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void toMessageWithPayload() throws Exception {
Method method = TestService.class.getMethod("sendPayload", String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> message = mapper.toMessage(new Object[] { "test" });
assertEquals("test", message.getPayload());
}
@@ -51,6 +55,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void toMessageWithTooManyParameters() throws Exception {
Method method = TestService.class.getMethod("sendPayload", String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
mapper.toMessage(new Object[] { "test" , "oops" });
}
@@ -58,6 +63,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void toMessageWithEmptyParameterArray() throws Exception {
Method method = TestService.class.getMethod("sendPayload", String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
mapper.toMessage(new Object[] {});
}
@@ -66,6 +72,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
Method method = TestService.class.getMethod(
"sendPayloadAndHeader", String.class, String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> message = mapper.toMessage(new Object[] { "test", "bar" });
assertEquals("test", message.getPayload());
assertEquals("bar", message.getHeaders().get("foo"));
@@ -76,6 +83,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
Method method = TestService.class.getMethod(
"sendPayloadAndHeader", String.class, String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
mapper.toMessage(new Object[] { "test", null });
}
@@ -84,6 +92,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
Method method = TestService.class.getMethod(
"sendPayloadAndOptionalHeader", String.class, String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> message = mapper.toMessage(new Object[] { "test", "bar" });
assertEquals("test", message.getPayload());
assertEquals("bar", message.getHeaders().get("foo"));
@@ -94,6 +103,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
Method method = TestService.class.getMethod(
"sendPayloadAndOptionalHeader", String.class, String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> message = mapper.toMessage(new Object[] { "test", null });
assertEquals("test", message.getPayload());
assertNull(message.getHeaders().get("foo"));
@@ -104,6 +114,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
Method method = TestService.class.getMethod(
"sendPayloadAndHeadersMap", String.class, Map.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("abc", 123);
headers.put("def", 456);
@@ -118,6 +129,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
Method method = TestService.class.getMethod(
"sendPayloadAndHeadersMap", String.class, Map.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> message = mapper.toMessage(new Object[] { "test", null });
assertEquals("test", message.getPayload());
}
@@ -127,6 +139,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
Method method = TestService.class.getMethod(
"sendPayloadAndHeadersMap", String.class, Map.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Map<Integer, String> headers = new HashMap<Integer, String>();
headers.put(123, "abc");
mapper.toMessage(new Object[] { "test", headers });
@@ -136,6 +149,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void toMessageWithMessageParameter() throws Exception {
Method method = TestService.class.getMethod("sendMessage", Message.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
Message<?> message = mapper.toMessage(new Object[] { inputMessage });
assertEquals("test message", message.getPayload());
@@ -145,6 +159,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void toMessageWithMessageParameterAndHeader() throws Exception {
Method method = TestService.class.getMethod("sendMessageAndHeader", Message.class, String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
Message<?> message = mapper.toMessage(new Object[] { inputMessage, "bar" });
assertEquals("test message", message.getPayload());
@@ -155,6 +170,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void toMessageWithMessageParameterAndRequiredHeaderButNullValue() throws Exception {
Method method = TestService.class.getMethod("sendMessageAndHeader", Message.class, String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
mapper.toMessage(new Object[] { inputMessage, null });
}
@@ -163,6 +179,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void toMessageWithMessageParameterAndOptionalHeaderWithValue() throws Exception {
Method method = TestService.class.getMethod("sendMessageAndOptionalHeader", Message.class, String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
Message<?> message = mapper.toMessage(new Object[] { inputMessage, "bar" });
assertEquals("test message", message.getPayload());
@@ -173,6 +190,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void toMessageWithMessageParameterAndOptionalHeaderWithNull() throws Exception {
Method method = TestService.class.getMethod("sendMessageAndOptionalHeader", Message.class, String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> inputMessage = MessageBuilder.withPayload("test message").build();
Message<?> message = mapper.toMessage(new Object[] { inputMessage, null });
assertEquals("test message", message.getPayload());
@@ -183,6 +201,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void noArgs() throws Exception {
Method method = TestService.class.getMethod("noArgs", new Class<?>[] {});
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
mapper.toMessage(new Object[] {});
}
@@ -190,6 +209,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
public void onlyHeaders() throws Exception {
Method method = TestService.class.getMethod("onlyHeaders", String.class, String.class);
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
mapper.toMessage(new Object[] { "abc", "def" });
}
@@ -201,6 +221,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
headers.put("bar", new SpelExpressionParser().parseExpression("6 * 7"));
headers.put("baz", new LiteralExpression("hello"));
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method, headers);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> message = mapper.toMessage(new Object[] { "test" });
assertEquals("test", message.getPayload());
assertEquals("foo", message.getHeaders().get("foo"));
@@ -214,6 +235,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
map.put(1, "One");
map.put(2, "Two");
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
mapper.setPayloadExpression("'hello'");
Message<?> message = mapper.toMessage(new Object[] { map });
assertEquals("hello", message.getPayload());
@@ -226,6 +248,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
map.put(1, "One");
map.put(2, "Two");
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
mapper.setPayloadExpression("#args[0]");
Message<?> message = mapper.toMessage(new Object[] { map });
assertEquals(map, message.getPayload());
@@ -238,6 +261,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
map.put(1, "One");
map.put(2, "Two");
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
Message<?> message = mapper.toMessage(new Object[] { map });
assertEquals(map, message.getPayload());
}
@@ -252,6 +276,7 @@ public class GatewayMethodInboundMessageMapperToMessageTests {
mapB.put("1", "ONE");
mapB.put("2", "TWO");
GatewayMethodInboundMessageMapper mapper = new GatewayMethodInboundMessageMapper(method);
mapper.setBeanFactory(mock(BeanFactory.class));
mapper.setPayloadExpression("#args[0]");
Message<?> message = mapper.toMessage(new Object[] { mapA, mapB });
assertEquals(mapA, message.getPayload());

View File

@@ -18,6 +18,7 @@ package org.springframework.integration.gateway;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import java.lang.reflect.Method;
import java.util.Random;
@@ -28,6 +29,8 @@ import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -49,6 +52,7 @@ import org.springframework.util.ReflectionUtils;
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
*/
public class GatewayProxyFactoryBeanTests {
@@ -59,6 +63,7 @@ public class GatewayProxyFactoryBeanTests {
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setServiceInterface(TestService.class);
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.setBeanName("testGateway");
proxyFactory.afterPropertiesSet();
TestService service = (TestService) proxyFactory.getObject();
@@ -100,6 +105,7 @@ public class GatewayProxyFactoryBeanTests {
proxyFactory.setServiceInterface(TestService.class);
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestService service = (TestService) proxyFactory.getObject();
service.oneWay("test");
@@ -138,6 +144,7 @@ public class GatewayProxyFactoryBeanTests {
proxyFactory.setServiceInterface(TestService.class);
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestService service = (TestService) proxyFactory.getObject();
Integer result = service.requestReplyWithIntegers(123);
@@ -207,6 +214,7 @@ public class GatewayProxyFactoryBeanTests {
proxyFactory.setServiceInterface(TestService.class);
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestService service = (TestService) proxyFactory.getObject();
String result = service.requestReplyWithMessageParameter(new GenericMessage<String>("foo"));
@@ -221,6 +229,7 @@ public class GatewayProxyFactoryBeanTests {
proxyFactory.setServiceInterface(TestService.class);
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestService service = (TestService) proxyFactory.getObject();
String result = service.requestReplyWithPayloadAnnotation();
@@ -241,6 +250,7 @@ public class GatewayProxyFactoryBeanTests {
proxyFactory.setServiceInterface(TestService.class);
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestService service = (TestService) proxyFactory.getObject();
Message<?> result = service.requestReplyWithMessageReturnValue("foo");
@@ -269,6 +279,7 @@ public class GatewayProxyFactoryBeanTests {
proxyFactory.setDefaultRequestChannel(new DirectChannel());
proxyFactory.setServiceInterface(TestService.class);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
Object proxy = proxyFactory.getObject();
String expected = "gateway proxy for";
@@ -290,6 +301,7 @@ public class GatewayProxyFactoryBeanTests {
proxyFactory.setDefaultRequestChannel(channel);
proxyFactory.setServiceInterface(TestExceptionThrowingInterface.class);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestExceptionThrowingInterface proxy = (TestExceptionThrowingInterface) proxyFactory.getObject();
proxy.throwCheckedException("test");

View File

@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
@@ -31,6 +32,7 @@ import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.expression.Expression;
@@ -71,7 +73,7 @@ public class DelayHandlerTests {
private DelayHandler delayHandler;
private ResultHandler resultHandler = new ResultHandler();
private final ResultHandler resultHandler = new ResultHandler();
@Before
public void setup() {
@@ -81,6 +83,7 @@ public class DelayHandlerTests {
taskScheduler.afterPropertiesSet();
delayHandler = new DelayHandler(DELAYER_MESSAGE_GROUP_ID, taskScheduler);
delayHandler.setOutputChannel(output);
delayHandler.setBeanFactory(mock(BeanFactory.class));
input.subscribe(delayHandler);
output.subscribe(resultHandler);
}
@@ -399,6 +402,7 @@ public class DelayHandlerTests {
this.delayHandler.setOutputChannel(output);
this.delayHandler.setDefaultDelay(200);
this.delayHandler.setMessageStore(messageGroupStore);
this.delayHandler.setBeanFactory(mock(BeanFactory.class));
this.startDelayerHandler();
assertTrue(this.latch.await(10, TimeUnit.SECONDS));

View File

@@ -15,6 +15,7 @@ package org.springframework.integration.handler;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.util.Arrays;
@@ -26,6 +27,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -49,6 +51,7 @@ import org.springframework.integration.test.util.TestUtils;
* @author Dave Syer
* @author Mark Fisher
* @author Gunnar Hillert
* @author Gary Russell
* @since 2.0
*/
public class ExpressionEvaluatingMessageProcessorTests {
@@ -67,6 +70,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
public void testProcessMessage() {
Expression expression = expressionParser.parseExpression("payload");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
processor.setBeanFactory(mock(BeanFactory.class));
assertEquals("foo", processor.processMessage(new GenericMessage<String>("foo")));
}
@@ -81,6 +85,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
}
Expression expression = expressionParser.parseExpression("#target.stringify(payload)");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
processor.setBeanFactory(mock(BeanFactory.class));
processor.afterPropertiesSet();
EvaluationContext evaluationContext = TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class);
evaluationContext.setVariable("target", new TestTarget());
@@ -97,6 +102,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
}
Expression expression = expressionParser.parseExpression("#target.ping(payload)");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
processor.setBeanFactory(mock(BeanFactory.class));
processor.afterPropertiesSet();
EvaluationContext evaluationContext = TestUtils.getPropertyValue(processor, "evaluationContext", EvaluationContext.class);
evaluationContext.setVariable("target", new TestTarget());
@@ -133,6 +139,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
public void testProcessMessageWithDollarInBrackets() {
Expression expression = expressionParser.parseExpression("headers['$foo_id']");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
processor.setBeanFactory(mock(BeanFactory.class));
Message<String> message = MessageBuilder.withPayload("foo").setHeader("$foo_id", "abc").build();
assertEquals("abc", processor.processMessage(message));
}
@@ -142,6 +149,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
public void testProcessMessageWithDollarPropertyAccess() {
Expression expression = expressionParser.parseExpression("headers.$foo_id");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
processor.setBeanFactory(mock(BeanFactory.class));
Message<String> message = MessageBuilder.withPayload("foo").setHeader("$foo_id", "xyz").build();
assertEquals("xyz", processor.processMessage(message));
}
@@ -151,6 +159,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
public void testProcessMessageWithStaticKey() {
Expression expression = expressionParser.parseExpression("headers[headers.ID]");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
processor.setBeanFactory(mock(BeanFactory.class));
GenericMessage<String> message = new GenericMessage<String>("foo");
assertEquals(message.getHeaders().getId(), processor.processMessage(message));
}
@@ -205,6 +214,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
});
Expression expression = expressionParser.parseExpression("payload.fixMe()");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
processor.setBeanFactory(mock(BeanFactory.class));
assertEquals("foo", processor.processMessage(new GenericMessage<String>("foo")));
}
@@ -225,6 +235,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
});
Expression expression = expressionParser.parseExpression("payload.throwRuntimeException()");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
processor.setBeanFactory(mock(BeanFactory.class));
assertEquals("foo", processor.processMessage(new GenericMessage<TestPayload>(new TestPayload())));
}
@@ -245,6 +256,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
});
Expression expression = expressionParser.parseExpression("payload.throwCheckedException()");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
processor.setBeanFactory(mock(BeanFactory.class));
assertEquals("foo", processor.processMessage(new GenericMessage<TestPayload>(new TestPayload())));
}

View File

@@ -49,6 +49,7 @@ import org.mockito.stubbing.Answer;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.MessagingException;
@@ -105,6 +106,7 @@ public class AdvisedMessageHandlerTests {
PollableChannel successChannel = new QueueChannel();
PollableChannel failureChannel = new QueueChannel();
ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
advice.setBeanFactory(mock(BeanFactory.class));
advice.setSuccessChannel(successChannel);
advice.setFailureChannel(failureChannel);
advice.setOnSuccessExpression("'foo'");
@@ -183,6 +185,7 @@ public class AdvisedMessageHandlerTests {
PollableChannel successChannel = new QueueChannel();
PollableChannel failureChannel = new QueueChannel();
ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
advice.setBeanFactory(mock(BeanFactory.class));
advice.setSuccessChannel(successChannel);
advice.setFailureChannel(failureChannel);
advice.setOnSuccessExpression("1/0");
@@ -657,6 +660,7 @@ public class AdvisedMessageHandlerTests {
List<Advice> adviceChain = new ArrayList<Advice>();
ExpressionEvaluatingRequestHandlerAdvice expressionAdvice = new ExpressionEvaluatingRequestHandlerAdvice();
expressionAdvice.setBeanFactory(mock(BeanFactory.class));
// MessagingException / RuntimeException
expressionAdvice.setOnFailureExpression("#exception.cause.message");
expressionAdvice.setReturnFailureExpressionResult(true);
@@ -704,6 +708,7 @@ public class AdvisedMessageHandlerTests {
List<Advice> adviceChain = new ArrayList<Advice>();
ExpressionEvaluatingRequestHandlerAdvice expressionAdvice = new ExpressionEvaluatingRequestHandlerAdvice();
expressionAdvice.setBeanFactory(mock(BeanFactory.class));
expressionAdvice.setOnFailureExpression("#exception.message");
expressionAdvice.setFailureChannel(errors);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 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.
@@ -19,11 +19,14 @@ package org.springframework.integration.message;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
@@ -33,6 +36,7 @@ import org.springframework.integration.endpoint.MethodInvokingMessageSource;
/**
* @author Mark Fisher
* @author Gary Russell
*/
public class MethodInvokingMessageSourceTests {
@@ -53,6 +57,7 @@ public class MethodInvokingMessageSourceTests {
headerExpressions.put("foo", new LiteralExpression("abc"));
headerExpressions.put("bar", new SpelExpressionParser().parseExpression("new Integer(123)"));
MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setBeanFactory(mock(BeanFactory.class));
source.setObject(new TestBean());
source.setMethodName("validMethod");
source.setHeaderExpressions(headerExpressions);

View File

@@ -54,6 +54,7 @@ import org.springframework.scheduling.support.PeriodicTrigger;
* @author Mark Fisher
* @author Gunnar Hillert
* @author Artem Bilan
* @author Gary Russell
*
* @since 2.1
*/
@@ -106,6 +107,7 @@ public class ContentEnricherTests {
enricher.setPropertyExpressions(expressions);
enricher.setRequiresReply(true);
enricher.setBeanName("Enricher");
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
final AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@@ -161,6 +163,7 @@ public class ContentEnricherTests {
ContentEnricher enricher = new ContentEnricher();
enricher.setRequestChannel(requestChannel);
enricher.setRequestTimeout(requestTimeout);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
Target target = new Target("replace me");
@@ -194,6 +197,7 @@ public class ContentEnricherTests {
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
Target target = new Target("replace me");
@@ -210,6 +214,7 @@ public class ContentEnricherTests {
ContentEnricher enricher = new ContentEnricher();
enricher.setReplyChannel(replyChannel);
enricher.setBeanFactory(mock(BeanFactory.class));
try {
enricher.afterPropertiesSet();
@@ -225,6 +230,7 @@ public class ContentEnricherTests {
public void setNullReplyTimeout() {
ContentEnricher enricher = new ContentEnricher();
enricher.setBeanFactory(mock(BeanFactory.class));
try {
enricher.setReplyTimeout(null);
@@ -240,6 +246,7 @@ public class ContentEnricherTests {
public void setNullRequestTimeout() {
ContentEnricher enricher = new ContentEnricher();
enricher.setBeanFactory(mock(BeanFactory.class));
try {
enricher.setRequestTimeout(null);
@@ -259,6 +266,7 @@ public class ContentEnricherTests {
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("name", parser.parseExpression("'just a static string'"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
Target target = new Target("replace me");
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
@@ -272,6 +280,7 @@ public class ContentEnricherTests {
ContentEnricher enricher = new ContentEnricher();
enricher.setReplyChannel(new QueueChannel());
enricher.setBeanFactory(mock(BeanFactory.class));
try {
enricher.afterPropertiesSet();
@@ -300,6 +309,7 @@ public class ContentEnricherTests {
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("child.name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
Target target = new Target("test");
@@ -329,6 +339,7 @@ public class ContentEnricherTests {
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
Target target = new Target("replace me");
@@ -358,6 +369,7 @@ public class ContentEnricherTests {
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
TargetUser target = new TargetUser();
@@ -390,6 +402,7 @@ public class ContentEnricherTests {
Map<String, Expression> propertyExpressions = new HashMap<String, Expression>();
propertyExpressions.put("name", parser.parseExpression("payload.lastName + ', ' + payload.firstName"));
enricher.setPropertyExpressions(propertyExpressions);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
UncloneableTargetUser target = new UncloneableTargetUser();
@@ -411,6 +424,7 @@ public class ContentEnricherTests {
@Test
public void testLifeCycleMethodsWithoutRequestChannel() {
ContentEnricher enricher = new ContentEnricher();
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
@@ -432,6 +446,7 @@ public class ContentEnricherTests {
ContentEnricher enricher = new ContentEnricher();
enricher.setRequestChannel(requestChannel);
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();