From 7d2e3a38150bb509359a64ec4ececaa5f734cc16 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Thu, 21 Dec 2017 18:11:16 -0500 Subject: [PATCH] Fix AbstractBinderTests to populate properties Some tests in `AbstractBinderTests` are rely on the partition header, but that one can be populated only by the `PartitionInterceptor`. To allow it we need to provide appropriate producer properties, like `partitionKeyExpression`. * Populate test-based `ProducerProperties` to the `createBindableChannel()` where `PartitionInterceptor` is populated * Fix `checkstyle.xml` static imports rule for Mockito-2.x as the current base line Fix for the proper `BindingProperties` usage --- .../stream/binder/AbstractBinderTests.java | 145 ++++++++++++------ .../src/main/resources/checkstyle.xml | 7 +- 2 files changed, 101 insertions(+), 51 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 0d52fba60..c4bb09a55 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 @@ -73,6 +73,7 @@ import static org.junit.Assert.assertTrue; * @author Marius Bogoevici * @author Oleg Zhurakousky * @author Jacob Severson + * @author Artem Bilan */ @SuppressWarnings("unchecked") public abstract class AbstractBinderTests, CP, PP>, CP extends ConsumerProperties, PP extends ProducerProperties> { @@ -165,7 +166,7 @@ public abstract class AbstractBinderTests producerBinding = binder.bindProducer(String.format("foo%s0", getDestinationNameDelimiter()), moduleOutputChannel, outputBindingProperties.getProducer()); Binding consumerBinding = binder.bindConsumer(String.format("foo%s0", - getDestinationNameDelimiter()), "testSendAndReceive", moduleInputChannel, createConsumerProperties()); + getDestinationNameDelimiter()), "testSendAndReceive", moduleInputChannel, inputBindingProperties.getConsumer()); Message message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar") .build(); // Let the consumer actually bind to the producer before sending a msg @@ -197,6 +198,7 @@ public abstract class AbstractBinderTests producerBinding = binder.bindProducer(String.format("foo%s0x", getDestinationNameDelimiter()), moduleOutputChannel, outputBindingProperties.getProducer()); Binding consumerBinding = binder.bindConsumer(String.format("foo%s0x", - getDestinationNameDelimiter()), "testSendAndReceiveKryo", moduleInputChannel, createConsumerProperties()); + getDestinationNameDelimiter()), "testSendAndReceiveKryo", moduleInputChannel, inputBindingProperties.getConsumer()); Foo foo = new Foo(); foo.setName("Bill"); Message message = MessageBuilder.withPayload(foo).setHeader(MessageHeaders.CONTENT_TYPE, MessageConverterUtils.X_JAVA_OBJECT) @@ -250,7 +252,7 @@ public abstract class AbstractBinderTests consumerBinding = binder.bindConsumer(String.format("foo%s0y", getDestinationNameDelimiter()), "testSendAndReceiveJavaSerialization", moduleInputChannel, - createConsumerProperties()); + inputBindingProperties.getConsumer()); SerializableFoo foo = new SerializableFoo(); - Message message = MessageBuilder.withPayload(foo).setHeader(MessageHeaders.CONTENT_TYPE, MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT) - .build(); + Message message = + MessageBuilder.withPayload(foo) + .setHeader(MessageHeaders.CONTENT_TYPE, MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT) + .build(); // Let the consumer actually bind to the producer before sending a msg binderBindUnbindLatency(); @@ -306,17 +310,19 @@ public abstract class AbstractBinderTests producerBinding1 = binder.bindProducer(String.format("foo%sxy", - getDestinationNameDelimiter()), moduleOutputChannel1, createProducerProperties()); + getDestinationNameDelimiter()), moduleOutputChannel1, producerBindingProperties.getProducer()); Binding producerBinding2 = binder.bindProducer(String.format("foo%syz", - getDestinationNameDelimiter()), moduleOutputChannel2, createProducerProperties()); + + getDestinationNameDelimiter()), moduleOutputChannel2, producerBindingProperties.getProducer()); Binding consumerBinding1 = binder.bindConsumer(String.format("foo%sxy", getDestinationNameDelimiter()), "testSendAndReceiveMultipleTopics", moduleInputChannel, @@ -444,7 +450,7 @@ public abstract class AbstractBinderTests producerBinding = binder.bindProducer(String.format("bad%s0a", - getDestinationNameDelimiter()), moduleOutputChannel, createProducerProperties()); + getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer()); + Binding consumerBinding = binder.bindConsumer(String.format("bad%s0a", - getDestinationNameDelimiter()), "test-1", moduleInputChannel, createConsumerProperties()); + getDestinationNameDelimiter()), "test-1", moduleInputChannel, consumerBindingProperties.getConsumer()); Station station = new Station(); Message message = MessageBuilder.withPayload(station).build(); @@ -521,14 +533,20 @@ public abstract class AbstractBinderTests producerBinding = binder.bindProducer(String.format("bad%s0b", - getDestinationNameDelimiter()), moduleOutputChannel, createProducerProperties()); + getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer()); + Binding consumerBinding = binder.bindConsumer(String.format("bad%s0b", - getDestinationNameDelimiter()), "test-2", moduleInputChannel, createConsumerProperties()); + getDestinationNameDelimiter()), "test-2", moduleInputChannel, consumerBindingProperties.getConsumer()); Station station = new Station(); Message message = MessageBuilder.withPayload(station).setHeader( @@ -548,14 +566,20 @@ public abstract class AbstractBinderTests producerBinding = binder.bindProducer(String.format("bad%s0c", - getDestinationNameDelimiter()), moduleOutputChannel, createProducerProperties()); + getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer()); + Binding consumerBinding = binder.bindConsumer(String.format("bad%s0c", - getDestinationNameDelimiter()), "test-3", moduleInputChannel, createConsumerProperties()); + getDestinationNameDelimiter()), "test-3", moduleInputChannel, consumerBindingProperties.getConsumer()); try { Station station = new Station(); Message message = MessageBuilder.withPayload(station) @@ -576,14 +600,20 @@ public abstract class AbstractBinderTests producerBinding = binder.bindProducer(String.format("bad%s0d", - getDestinationNameDelimiter()), moduleOutputChannel, createProducerProperties()); + getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer()); + Binding consumerBinding = binder.bindConsumer(String.format("bad%s0d", - getDestinationNameDelimiter()), "test-4", moduleInputChannel, createConsumerProperties()); + getDestinationNameDelimiter()), "test-4", moduleInputChannel, consumerBindingProperties.getConsumer()); String value = "{\"readings\":[{\"stationid\":\"fgh\"," + "\"customerid\":\"12345\",\"timestamp\":null},{\"stationid\":\"hjk\",\"customerid\":\"222\",\"timestamp\":null}]}"; @@ -610,14 +640,20 @@ public abstract class AbstractBinderTests producerBinding = binder.bindProducer(String.format("bad%s0e", - getDestinationNameDelimiter()), moduleOutputChannel, createProducerProperties()); + getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer()); + Binding consumerBinding = binder.bindConsumer(String.format("bad%s0e", - getDestinationNameDelimiter()), "test-5", moduleInputChannel, createConsumerProperties()); + getDestinationNameDelimiter()), "test-5", moduleInputChannel, consumerBindingProperties.getConsumer()); String value = "{\"readings\":[{\"stationid\":\"fgh\"," + "\"customerid\":\"12345\",\"timestamp\":null},{\"stationid\":\"hjk\",\"customerid\":\"222\",\"timestamp\":null}]}"; @@ -644,14 +680,20 @@ public abstract class AbstractBinderTests producerBinding = binder.bindProducer(String.format("bad%s0f", - getDestinationNameDelimiter()), moduleOutputChannel, createProducerProperties()); + getDestinationNameDelimiter()), moduleOutputChannel, producerBindingProperties.getProducer()); + Binding consumerBinding = binder.bindConsumer(String.format("bad%s0f", - getDestinationNameDelimiter()), "test-6", moduleInputChannel, createConsumerProperties()); + getDestinationNameDelimiter()), "test-6", moduleInputChannel, consumerBindingProperties.getConsumer()); Readings r1 = new Readings(); r1.setCustomerid("123"); @@ -710,7 +752,7 @@ public abstract class AbstractBinderTests + value="org.junit.Assert.*, + org.mockito.Mockito.*, + org.mockito.BDDMockito.*, + org.mockito.ArgumentMatchers.*, + org.hamcrest.Matchers.*, + org.assertj.core.api.Assertions.*"/>