From 2133840fb9f97d61a265f5141994129dc6cd08ff Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Wed, 25 Sep 2019 19:32:09 +0200 Subject: [PATCH] Gh 3409 turbine stream test (#3665) * Add stream-test-support. * Fix condition. * Remove outdated workaround. (cherry picked from commit 24f5e0b043c89a483b0c75b80847c1381f8a6e94) --- spring-cloud-netflix-turbine-stream/pom.xml | 5 +++ .../turbine/stream/TurbineStreamTests.java | 40 ++++--------------- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/spring-cloud-netflix-turbine-stream/pom.xml b/spring-cloud-netflix-turbine-stream/pom.xml index ee90efd831..53ba73789c 100644 --- a/spring-cloud-netflix-turbine-stream/pom.xml +++ b/spring-cloud-netflix-turbine-stream/pom.xml @@ -131,5 +131,10 @@ spring-cloud-netflix-hystrix-contract test + + org.springframework.cloud + spring-cloud-stream-test-support + test + diff --git a/spring-cloud-netflix-turbine-stream/src/test/java/org/springframework/cloud/netflix/turbine/stream/TurbineStreamTests.java b/spring-cloud-netflix-turbine-stream/src/test/java/org/springframework/cloud/netflix/turbine/stream/TurbineStreamTests.java index 2d19561b24..7b689c1973 100644 --- a/spring-cloud-netflix-turbine-stream/src/test/java/org/springframework/cloud/netflix/turbine/stream/TurbineStreamTests.java +++ b/spring-cloud-netflix-turbine-stream/src/test/java/org/springframework/cloud/netflix/turbine/stream/TurbineStreamTests.java @@ -27,20 +27,15 @@ import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.beans.BeansException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.cloud.contract.stubrunner.StubTrigger; import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties.StubsMode; -import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpRequest; @@ -63,12 +58,13 @@ * @author Daniel Lavoie */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = TurbineStreamTests.Application.class, webEnvironment = RANDOM_PORT, properties = { - // TODO: we don't need this if we harmonize the turbine and hystrix destinations +@SpringBootTest(webEnvironment = RANDOM_PORT, properties = { + // TODO: we don't need this if we harmonize the turbine and hystrix + // destinations // https://github.com/spring-cloud/spring-cloud-netflix/issues/1948 "spring.cloud.stream.bindings.turbineStreamInput.destination=hystrixStreamOutput", "spring.jmx.enabled=true", "stubrunner.workOffline=true", - "stubrunner.ids=org.springframework.cloud:spring-cloud-netflix-hystrix-stream:${projectVersion:2.0.0.BUILD-SNAPSHOT}:stubs" }) + "stubrunner.ids=org.springframework.cloud:spring-cloud-netflix-hystrix-stream:${projectVersion:2.1.3.BUILD-SNAPSHOT}:stubs" }) @AutoConfigureStubRunner(stubsMode = StubsMode.LOCAL) public class TurbineStreamTests { @@ -106,7 +102,7 @@ public void contextLoads() throws Exception { } private boolean containsMetrics(String line) { - return line.startsWith("data:") && !line.contains("Ping"); + return line.startsWith("data:") && !line.contains("ping"); } @SuppressWarnings("unchecked") @@ -145,28 +141,8 @@ private ResponseEntity extract(ClientHttpResponse response) @EnableAutoConfiguration @EnableTurbineStream - public static class Application { - - // Workaround for stub runner lowercasing id somewhere - @Bean - BeanDefinitionRegistryPostProcessor myBeanDefinitionRegistryPostProcessor() { - return new BeanDefinitionRegistryPostProcessor() { - @Override - public void postProcessBeanDefinitionRegistry( - BeanDefinitionRegistry registry) throws BeansException { - BeanDefinition beanDefinition = registry - .getBeanDefinition(TurbineStreamClient.INPUT); - registry.registerBeanDefinition( - TurbineStreamClient.INPUT.toLowerCase(), beanDefinition); - } - - @Override - public void postProcessBeanFactory( - ConfigurableListableBeanFactory beanFactory) - throws BeansException { - } - }; - } + @Configuration + public static class TestConfig { }