Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
GH-45: Add @Import(ScriptVarGenConfig.class)
Browse files Browse the repository at this point in the history
Fixes GH-45 (spring-attic/app-starters-release#45)

Since we have `RouterSinkTests` in the same package as an original `RouterSinkConfiguration` and uses `@ComponentScan` from the `@SpringBootApplication`,
 we pick up unimported `ScriptVariableGeneratorConfiguration` as well for test environment.
In the real world `@SpringBootApplication` might be on a different package therefore  unimported `ScriptVariableGeneratorConfiguration` isn't scanned.

* Add `@Import(ScriptVariableGeneratorConfiguration.class)` to the `RouterSinkConfiguration`
* Modify `RouterSinkTests` do not scan packages
* Resolve deprecations according Spring Boot upgrade
  • Loading branch information
artembilan committed Jan 6, 2017
1 parent 03ef7e5 commit 23ee585
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion spring-cloud-starter-stream-sink-router/README.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//tag::ref-doc[]
= Router Sink

This module routes messages to named channels.
This application routes messages to named channels.

== Options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.cloud.stream.binding.BinderAwareChannelResolver;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor;
import org.springframework.integration.router.AbstractMappingMessageRouter;
Expand All @@ -34,10 +35,13 @@

/**
* A sink app that routes to one or more named channels.
*
* @author Gary Russell
* @author Artem Bilan
*/
@EnableBinding(Sink.class)
@EnableConfigurationProperties(RouterSinkProperties.class)
@Import(ScriptVariableGeneratorConfiguration.class)
public class RouterSinkConfiguration {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,31 @@
import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.stream.binder.BinderFactory;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.cloud.stream.test.binder.MessageCollector;
import org.springframework.cloud.stream.test.binder.TestSupportBinder;
import org.springframework.context.annotation.Import;
import org.springframework.integration.router.AbstractMappingMessageRouter;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Tests for RouterSinkConfiguration.
*
* @author Gary Russell
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = RouterSinkTests.RouterSinkApplication.class)
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@DirtiesContext
@WebIntegrationTest(randomPort = true)
public abstract class RouterSinkTests {

@Autowired
Expand All @@ -64,7 +65,7 @@ public abstract class RouterSinkTests {
@Autowired
protected AbstractMappingMessageRouter router;

@IntegrationTest({ "router.resolutionRequired = true" })
@TestPropertySource(properties = "router.resolutionRequired = true")
public static class DefaultRouterTests extends RouterSinkTests {

@Test
Expand All @@ -85,7 +86,9 @@ public void test() throws Exception {

}

@IntegrationTest({ "router.expression = headers['route']", "router.resolutionRequired = true" })
@TestPropertySource(properties = {
"router.expression = headers['route']",
"router.resolutionRequired = true" })
public static class DefaultRouterWithExpressionTests extends RouterSinkTests {

@Test
Expand All @@ -106,7 +109,9 @@ public void test() throws Exception {

}

@IntegrationTest({ "router.expression = headers['route']", "router.destinationMappings = foo=baz \\n bar=qux",
@TestPropertySource(properties = {
"router.expression = headers['route']",
"router.destinationMappings = foo=baz \\n bar=qux",
"router.resolutionRequired = true" })
public static class WithChannelMappingsTests extends RouterSinkTests {

Expand All @@ -128,8 +133,10 @@ public void test() throws Exception {

}

@IntegrationTest({ "router.expression = headers['route']", "router.defaultOutputChannel = discards",
"spring.cloud.stream.dynamicDestinations = foo,bar,discards" })
@TestPropertySource(properties = {
"router.expression = headers['route']",
"router.defaultOutputChannel = discards",
"spring.cloud.stream.dynamicDestinations = foo,bar,discards" })
public static class WithDiscardChannelTests extends RouterSinkTests {

@Test
Expand All @@ -156,8 +163,10 @@ public void test() throws Exception {

}

@IntegrationTest({ "router.script = classpath:/routertest.groovy", "router.variables = foo=baz",
"router.variablesLocation = classpath:/routertest.properties" })
@TestPropertySource(properties = {
"router.script = classpath:/routertest.groovy",
"router.variables = foo=baz",
"router.variablesLocation = classpath:/routertest.properties" })
public static class WithGroovyTests extends RouterSinkTests {

@Test
Expand All @@ -178,7 +187,10 @@ public void test() throws Exception {

}

@SpringBootApplication
// Avoid @SpringBootApplication with its @ComponentScan
@SpringBootConfiguration
@EnableAutoConfiguration
@Import(RouterSinkConfiguration.class)
public static class RouterSinkApplication {

}
Expand Down

0 comments on commit 23ee585

Please sign in to comment.