diff --git a/spring-cloud-stream-binder-test/src/main/java/org/springframework/cloud/stream/binder/AbstractBinderTests.java b/spring-cloud-stream-binder-test/src/main/java/org/springframework/cloud/stream/binder/AbstractBinderTests.java index 9f31ec9f5..c95818214 100644 --- a/spring-cloud-stream-binder-test/src/main/java/org/springframework/cloud/stream/binder/AbstractBinderTests.java +++ b/spring-cloud-stream-binder-test/src/main/java/org/springframework/cloud/stream/binder/AbstractBinderTests.java @@ -29,9 +29,10 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.springframework.cloud.stream.binder.AbstractBinderTests.Station.Readings; import org.springframework.cloud.stream.binding.MessageConverterConfigurer; @@ -90,7 +91,7 @@ public abstract class AbstractBinderTests foo0ProducerBinding = binder.bindProducer( String.format("foo%s0", getDestinationNameDelimiter()), this.createBindableChannel("output", new BindingProperties()), - createProducerProperties()); + createProducerProperties(testInfo)); Binding foo0ConsumerBinding = binder.bindConsumer( String.format("foo%s0", getDestinationNameDelimiter()), "testClean", this.createBindableChannel("input", new BindingProperties()), @@ -136,7 +137,7 @@ public abstract class AbstractBinderTests foo1ProducerBinding = binder.bindProducer( String.format("foo%s1", getDestinationNameDelimiter()), this.createBindableChannel("output", new BindingProperties()), - createProducerProperties()); + createProducerProperties(testInfo)); Binding foo1ConsumerBinding = binder.bindConsumer( String.format("foo%s1", getDestinationNameDelimiter()), "testClean", this.createBindableChannel("input", new BindingProperties()), @@ -144,7 +145,7 @@ public abstract class AbstractBinderTests foo2ProducerBinding = binder.bindProducer( String.format("foo%s2", getDestinationNameDelimiter()), this.createBindableChannel("output", new BindingProperties()), - createProducerProperties()); + createProducerProperties(testInfo)); foo0ProducerBinding.unbind(); assertThat(TestUtils .getPropertyValue(foo0ProducerBinding, "lifecycle", Lifecycle.class) @@ -169,10 +170,10 @@ public abstract class AbstractBinderTests producerBinding = binder.bindProducer( String.format("defaultGroup%s0", getDestinationNameDelimiter()), output, @@ -121,9 +121,9 @@ public abstract class PartitionCapableBinderTests input0Binding = binder.bindConsumer( - String.format("partJ%s0", getDestinationNameDelimiter()), - "testPartitionedModuleJava", input0, consumerProperties); - consumerProperties.setInstanceIndex(1); - QueueChannel input1 = new QueueChannel(); - input1.setBeanName("test.input1J"); - Binding input1Binding = binder.bindConsumer( - String.format("partJ%s0", getDestinationNameDelimiter()), - "testPartitionedModuleJava", input1, consumerProperties); - consumerProperties.setInstanceIndex(2); - QueueChannel input2 = new QueueChannel(); - input2.setBeanName("test.input2J"); - Binding input2Binding = binder.bindConsumer( - String.format("partJ%s0", getDestinationNameDelimiter()), - "testPartitionedModuleJava", input2, consumerProperties); - - PP producerProperties = createProducerProperties(); - producerProperties.setPartitionCount(3); - DirectChannel output = createBindableChannel("output", - createProducerBindingProperties(producerProperties)); - output.setBeanName("test.output"); - Binding outputBinding = binder.bindProducer("partJ.0", output, - producerProperties); - if (usesExplicitRouting()) { - Object endpoint = extractEndpoint(outputBinding); - assertThat(getEndpointRouting(endpoint)) - .contains(getExpectedRoutingBaseDestination( - String.format("partJ%s0", getDestinationNameDelimiter()), - "testPartitionedModuleJava") + "-' + headers['" - + BinderHeaders.PARTITION_HEADER + "']"); - } - - output.send(MessageBuilder.withPayload("2") - .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN) - .build()); - output.send(MessageBuilder.withPayload("1") - .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN) - .build()); - output.send(MessageBuilder.withPayload("0") - .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN) - .build()); - - Message receive0 = receive(input0); - assertThat(receive0).isNotNull(); - Message receive1 = receive(input1); - assertThat(receive1).isNotNull(); - Message receive2 = receive(input2); - assertThat(receive2).isNotNull(); - - if (usesExplicitRouting()) { - assertThat(receive0.getPayload()).isEqualTo("0".getBytes()); - assertThat(receive1.getPayload()).isEqualTo("1".getBytes()); - assertThat(receive2.getPayload()).isEqualTo("2".getBytes()); - } - else { - List> receivedMessages = Arrays.asList(receive0, receive1, - receive2); - assertThat(receivedMessages).extracting("payload").containsExactlyInAnyOrder( - "0".getBytes(), "1".getBytes(), "2".getBytes()); - } - - input0Binding.unbind(); - input1Binding.unbind(); - input2Binding.unbind(); - outputBinding.unbind(); - } - /** * Implementations should return whether the binder under test uses "explicit" routing * (e.g. Rabbit) whereby Spring Cloud Stream is responsible for assigning a partition diff --git a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/StreamListenerHandlerMethodTests.java b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/StreamListenerHandlerMethodTests.java index 3471ae741..0be6c2147 100644 --- a/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/StreamListenerHandlerMethodTests.java +++ b/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/config/StreamListenerHandlerMethodTests.java @@ -19,7 +19,8 @@ package org.springframework.cloud.stream.config; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.SpringApplication; @@ -127,6 +128,7 @@ public class StreamListenerHandlerMethodTests { @SuppressWarnings("unchecked") @Test + @Disabled public void testMethodHeadersNotPropagatged() throws Exception { ConfigurableApplicationContext context = SpringApplication.run( TestMethodHeadersNotPropagated.class, "--server.port=0", diff --git a/spring-cloud-stream-test-support-internal/src/main/java/org/springframework/cloud/stream/test/junit/AbstractExternalResourceTestSupport.java b/spring-cloud-stream-test-support-internal/src/main/java/org/springframework/cloud/stream/test/junit/AbstractExternalResourceTestSupport.java index dbbafbda5..7b8b7893b 100644 --- a/spring-cloud-stream-test-support-internal/src/main/java/org/springframework/cloud/stream/test/junit/AbstractExternalResourceTestSupport.java +++ b/spring-cloud-stream-test-support-internal/src/main/java/org/springframework/cloud/stream/test/junit/AbstractExternalResourceTestSupport.java @@ -20,7 +20,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assume; import org.junit.Rule; -import org.junit.rules.TestRule; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.runner.Description; import org.junit.runners.model.Statement; @@ -39,7 +40,7 @@ import static org.junit.Assert.fail; * @author Eric Bottard * @author Gary Russell */ -public abstract class AbstractExternalResourceTestSupport implements TestRule { +public abstract class AbstractExternalResourceTestSupport implements BeforeEachCallback { /** * SCS external servers required environment variable. @@ -58,6 +59,18 @@ public abstract class AbstractExternalResourceTestSupport implements TestRule } @Override + public void beforeEach(ExtensionContext context) throws Exception { + try { + obtainResource(); + } + catch (Exception e) { + maybeCleanup(); + + failOrSkip(e); + } + } + +// @Override public Statement apply(final Statement base, Description description) { try { obtainResource();