INT-4432: Mock Handler: fix output channel

JIRA: https://jira.spring.io/browse/INT-4432

The `MockIntegrationContext.substituteMessageHandlerFor()` method
cannot get the correct output channel of target message handler
since the `outputChannel` property is not initialized.

* Use `getOutputChannel()` method instead of directly accessing
the `outputChannel` property. The `getOutputChannel()` method
guarantees the correct value is retrieved.

* Polishing Copyrights and author name
* Simplify `MockMessageHandlerTests.testHandlerSubstitutionWithOutputChannel()`
and its configuration

**Cherry-pick to 5.0.x**
This commit is contained in:
Yicheng Feng
2018-03-21 11:05:18 +08:00
committed by Artem Bilan
parent bcf4402b91
commit ed00f62549
2 changed files with 46 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 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.
@@ -46,8 +46,10 @@ import org.springframework.util.ObjectUtils;
* annotation and can be autowired into test class.
*
* @author Artem Bilan
* @author Yicheng Feng
*
* @since 5.0
*
* @see SpringIntegrationTest
*/
public class MockIntegrationContext implements BeanFactoryAware {
@@ -139,8 +141,7 @@ public class MockIntegrationContext implements BeanFactoryAware {
if (mockMessageHandler instanceof MessageProducer) {
if (targetMessageHandler instanceof MessageProducer) {
MessageChannel outputChannel = TestUtils.getPropertyValue(targetMessageHandler, "outputChannel",
MessageChannel.class);
MessageChannel outputChannel = ((MessageProducer) targetMessageHandler).getOutputChannel();
((MessageProducer) mockMessageHandler).setOutputChannel(outputChannel);
}
else {