From dbe0d61e0ff6f4d0a990e4c1766b70597f62f04b Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Thu, 15 Jul 2021 12:53:05 -0400 Subject: [PATCH] Revert "JUnit 5 migration related to boot 2.6" This reverts commit ac5124dabf9b0887e7a165b212d4e8ecec7eacb3. --- .../stream/binder/AbstractBinderTests.java | 49 +++++---- .../binder/PartitionCapableBinderTests.java | 99 +++++++++++++++++-- .../StreamListenerHandlerMethodTests.java | 4 +- .../AbstractExternalResourceTestSupport.java | 17 +--- 4 files changed, 116 insertions(+), 53 deletions(-) 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 c95818214..9f31ec9f5 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,10 +29,9 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -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.junit.After; +import org.junit.Before; +import org.junit.Test; import org.springframework.cloud.stream.binder.AbstractBinderTests.Station.Readings; import org.springframework.cloud.stream.binding.MessageConverterConfigurer; @@ -91,7 +90,7 @@ public abstract class AbstractBinderTests foo0ProducerBinding = binder.bindProducer( String.format("foo%s0", getDestinationNameDelimiter()), this.createBindableChannel("output", new BindingProperties()), - createProducerProperties(testInfo)); + createProducerProperties()); Binding foo0ConsumerBinding = binder.bindConsumer( String.format("foo%s0", getDestinationNameDelimiter()), "testClean", this.createBindableChannel("input", new BindingProperties()), @@ -137,7 +136,7 @@ public abstract class AbstractBinderTests foo1ProducerBinding = binder.bindProducer( String.format("foo%s1", getDestinationNameDelimiter()), this.createBindableChannel("output", new BindingProperties()), - createProducerProperties(testInfo)); + createProducerProperties()); Binding foo1ConsumerBinding = binder.bindConsumer( String.format("foo%s1", getDestinationNameDelimiter()), "testClean", this.createBindableChannel("input", new BindingProperties()), @@ -145,7 +144,7 @@ public abstract class AbstractBinderTests foo2ProducerBinding = binder.bindProducer( String.format("foo%s2", getDestinationNameDelimiter()), this.createBindableChannel("output", new BindingProperties()), - createProducerProperties(testInfo)); + createProducerProperties()); foo0ProducerBinding.unbind(); assertThat(TestUtils .getPropertyValue(foo0ProducerBinding, "lifecycle", Lifecycle.class) @@ -170,10 +169,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 0be6c2147..3471ae741 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,8 +19,7 @@ package org.springframework.cloud.stream.config; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; +import org.junit.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.SpringApplication; @@ -128,7 +127,6 @@ 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 7b8b7893b..dbbafbda5 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,8 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assume; import org.junit.Rule; -import org.junit.jupiter.api.extension.BeforeEachCallback; -import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; @@ -40,7 +39,7 @@ import static org.junit.Assert.fail; * @author Eric Bottard * @author Gary Russell */ -public abstract class AbstractExternalResourceTestSupport implements BeforeEachCallback { +public abstract class AbstractExternalResourceTestSupport implements TestRule { /** * SCS external servers required environment variable. @@ -59,18 +58,6 @@ public abstract class AbstractExternalResourceTestSupport implements BeforeEa } @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();