Added checkstyle
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,9 @@ public interface MessageCollector {
|
||||
|
||||
/**
|
||||
* Obtain a queue that will receive messages sent to the given channel.
|
||||
* @param channel message channel
|
||||
* @return blocking queue for stored message
|
||||
*/
|
||||
BlockingQueue<Message<?>> forChannel(MessageChannel channel);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,7 +32,8 @@ public class MessageCollectorAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public MessageCollector messageCollector(BinderFactory binderFactory) {
|
||||
return ((TestSupportBinder) binderFactory.getBinder("test", MessageChannel.class)).messageCollector();
|
||||
return ((TestSupportBinder) binderFactory.getBinder("test", MessageChannel.class))
|
||||
.messageCollector();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,9 +33,12 @@ import org.springframework.core.env.MapPropertySource;
|
||||
public class TestBinderEnvironmentPostProcessor implements EnvironmentPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
Map<String, Object> propertiesToAdd = new HashMap<>();
|
||||
propertiesToAdd.put("spring.cloud.stream.binders.test.defaultCandidate", "false");
|
||||
environment.getPropertySources().addLast(new MapPropertySource("testBinderConfig", propertiesToAdd));
|
||||
environment.getPropertySources()
|
||||
.addLast(new MapPropertySource("testBinderConfig", propertiesToAdd));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,15 +64,16 @@ import org.springframework.util.StringUtils;
|
||||
* @author Soby Chacko
|
||||
* @see MessageQueueMatcher
|
||||
*/
|
||||
public class TestSupportBinder implements Binder<MessageChannel, ConsumerProperties, ProducerProperties> {
|
||||
public class TestSupportBinder
|
||||
implements Binder<MessageChannel, ConsumerProperties, ProducerProperties> {
|
||||
|
||||
private final MessageCollectorImpl messageCollector = new MessageCollectorImpl();
|
||||
|
||||
private final ConcurrentMap<String, MessageChannel> messageChannels = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Binding<MessageChannel> bindConsumer(String name, String group, MessageChannel inboundBindTarget,
|
||||
ConsumerProperties properties) {
|
||||
public Binding<MessageChannel> bindConsumer(String name, String group,
|
||||
MessageChannel inboundBindTarget, ConsumerProperties properties) {
|
||||
return new TestBinding(inboundBindTarget, null);
|
||||
}
|
||||
|
||||
@@ -81,9 +82,10 @@ public class TestSupportBinder implements Binder<MessageChannel, ConsumerPropert
|
||||
* retrieval and assertion in tests.
|
||||
*/
|
||||
@Override
|
||||
public Binding<MessageChannel> bindProducer(String name, MessageChannel outboundBindTarget,
|
||||
ProducerProperties properties) {
|
||||
final BlockingQueue<Message<?>> queue = messageCollector.register(outboundBindTarget, properties.isUseNativeEncoding());
|
||||
public Binding<MessageChannel> bindProducer(String name,
|
||||
MessageChannel outboundBindTarget, ProducerProperties properties) {
|
||||
final BlockingQueue<Message<?>> queue = this.messageCollector
|
||||
.register(outboundBindTarget, properties.isUseNativeEncoding());
|
||||
((SubscribableChannel) outboundBindTarget).subscribe(new MessageHandler() {
|
||||
@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
@@ -91,11 +93,11 @@ public class TestSupportBinder implements Binder<MessageChannel, ConsumerPropert
|
||||
}
|
||||
});
|
||||
this.messageChannels.put(name, outboundBindTarget);
|
||||
return new TestBinding(outboundBindTarget, messageCollector);
|
||||
return new TestBinding(outboundBindTarget, this.messageCollector);
|
||||
}
|
||||
|
||||
public MessageCollector messageCollector() {
|
||||
return messageCollector;
|
||||
return this.messageCollector;
|
||||
}
|
||||
|
||||
public MessageChannel getChannelForName(String name) {
|
||||
@@ -111,29 +113,36 @@ public class TestSupportBinder implements Binder<MessageChannel, ConsumerPropert
|
||||
|
||||
private final Map<MessageChannel, BlockingQueue<Message<?>>> results = new HashMap<>();
|
||||
|
||||
private BlockingQueue<Message<?>> register(MessageChannel channel, boolean useNativeEncoding) {
|
||||
// we need to add this interceptor to ensure MessageCollector's compatibility with
|
||||
private BlockingQueue<Message<?>> register(MessageChannel channel,
|
||||
boolean useNativeEncoding) {
|
||||
// we need to add this interceptor to ensure MessageCollector's compatibility
|
||||
// with
|
||||
// previous versions of SCSt when native encoding is disabled.
|
||||
if (!useNativeEncoding) {
|
||||
((AbstractMessageChannel) channel).addInterceptor(new InboundMessageConvertingInterceptor());
|
||||
((AbstractMessageChannel) channel)
|
||||
.addInterceptor(new InboundMessageConvertingInterceptor());
|
||||
}
|
||||
LinkedBlockingDeque<Message<?>> result = new LinkedBlockingDeque<>();
|
||||
Assert.isTrue(!results.containsKey(channel), "Channel [" + channel + "] was already bound");
|
||||
results.put(channel, result);
|
||||
Assert.isTrue(!this.results.containsKey(channel),
|
||||
"Channel [" + channel + "] was already bound");
|
||||
this.results.put(channel, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void unregister(MessageChannel channel) {
|
||||
Assert.notNull(results.remove(channel),
|
||||
"Trying to unregister a mapping for an unknown channel [" + channel + "]");
|
||||
Assert.notNull(this.results.remove(channel),
|
||||
"Trying to unregister a mapping for an unknown channel [" + channel
|
||||
+ "]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockingQueue<Message<?>> forChannel(MessageChannel channel) {
|
||||
BlockingQueue<Message<?>> queue = results.get(channel);
|
||||
Assert.notNull(queue, "Channel [" + channel + "] was not bound by " + TestSupportBinder.class);
|
||||
BlockingQueue<Message<?>> queue = this.results.get(channel);
|
||||
Assert.notNull(queue, "Channel [" + channel + "] was not bound by "
|
||||
+ TestSupportBinder.class);
|
||||
return queue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,56 +154,80 @@ public class TestSupportBinder implements Binder<MessageChannel, ConsumerPropert
|
||||
|
||||
private final MessageCollectorImpl messageCollector;
|
||||
|
||||
private TestBinding(MessageChannel target, MessageCollectorImpl messageCollector) {
|
||||
private TestBinding(MessageChannel target,
|
||||
MessageCollectorImpl messageCollector) {
|
||||
this.target = target;
|
||||
this.messageCollector = messageCollector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unbind() {
|
||||
if (messageCollector != null) {
|
||||
messageCollector.unregister(target);
|
||||
if (this.messageCollector != null) {
|
||||
this.messageCollector.unregister(this.target);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This is really an interceptor to maintain MessageCollector's backward compatibility
|
||||
* with the behavior established in 1.3
|
||||
* - BINDER_ORIGINAL_CONTENT_TYPE
|
||||
* - Kryo and Java deserialization
|
||||
* - byte[] to String conversion
|
||||
* - etc
|
||||
* with the behavior established in 1.3 - BINDER_ORIGINAL_CONTENT_TYPE - Kryo and Java
|
||||
* deserialization - byte[] to String conversion - etc.
|
||||
*/
|
||||
private final static class InboundMessageConvertingInterceptor implements ChannelInterceptor {
|
||||
private final static class InboundMessageConvertingInterceptor
|
||||
implements ChannelInterceptor {
|
||||
|
||||
private final DefaultContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver();
|
||||
|
||||
private final CompositeMessageConverterFactory converterFactory = new CompositeMessageConverterFactory();
|
||||
|
||||
/*
|
||||
* Candidate to go into some utils class
|
||||
*/
|
||||
private static boolean equalTypeAndSubType(MimeType m1, MimeType m2) {
|
||||
return m1 != null && m2 != null && m1.getType().equalsIgnoreCase(m2.getType())
|
||||
&& m1.getSubtype().equalsIgnoreCase(m2.getSubtype());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message<?> preSend(Message<?> message, MessageChannel channel) {
|
||||
Class<?> targetClass = null;
|
||||
MessageConverter converter = null;
|
||||
MimeType contentType = message.getHeaders().containsKey(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)
|
||||
? MimeType.valueOf(message.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE).toString())
|
||||
: MimeType.valueOf(contentTypeResolver.resolve(message.getHeaders()).toString());
|
||||
MimeType contentType = message.getHeaders()
|
||||
.containsKey(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)
|
||||
? MimeType.valueOf(message.getHeaders()
|
||||
.get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)
|
||||
.toString())
|
||||
: MimeType.valueOf(this.contentTypeResolver
|
||||
.resolve(message.getHeaders()).toString());
|
||||
|
||||
if (contentType != null){
|
||||
if (equalTypeAndSubType(MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT, contentType) ||
|
||||
equalTypeAndSubType(MessageConverterUtils.X_JAVA_OBJECT, contentType)) {
|
||||
// for Java and Kryo de-serialization we need to reset the content type
|
||||
message = MessageBuilder.fromMessage(message).setHeader(MessageHeaders.CONTENT_TYPE, contentType).build();
|
||||
converter = equalTypeAndSubType(MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT, contentType)
|
||||
? converterFactory.getMessageConverterForType(contentType)
|
||||
: converterFactory.getMessageConverterForAllRegistered();
|
||||
if (contentType != null) {
|
||||
if (equalTypeAndSubType(MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT,
|
||||
contentType)
|
||||
|| equalTypeAndSubType(MessageConverterUtils.X_JAVA_OBJECT,
|
||||
contentType)) {
|
||||
// for Java and Kryo de-serialization we need to reset the content
|
||||
// type
|
||||
message = MessageBuilder.fromMessage(message)
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, contentType).build();
|
||||
converter = equalTypeAndSubType(
|
||||
MessageConverterUtils.X_JAVA_SERIALIZED_OBJECT, contentType)
|
||||
? this.converterFactory
|
||||
.getMessageConverterForType(contentType)
|
||||
: this.converterFactory
|
||||
.getMessageConverterForAllRegistered();
|
||||
String targetClassName = contentType.getParameter("type");
|
||||
if (StringUtils.hasText(targetClassName)) {
|
||||
try {
|
||||
targetClass = Class.forName(targetClassName, false, Thread.currentThread().getContextClassLoader());
|
||||
targetClass = Class.forName(targetClassName, false,
|
||||
Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException("Failed to determine class name for contentType: "
|
||||
+ message.getHeaders().get(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE), e);
|
||||
throw new IllegalStateException(
|
||||
"Failed to determine class name for contentType: "
|
||||
+ message.getHeaders().get(
|
||||
BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE),
|
||||
e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,41 +235,41 @@ public class TestSupportBinder implements Binder<MessageChannel, ConsumerPropert
|
||||
}
|
||||
|
||||
Object payload;
|
||||
if (converter != null){
|
||||
Assert.isTrue(!(equalTypeAndSubType(MessageConverterUtils.X_JAVA_OBJECT, contentType) && targetClass == null),
|
||||
if (converter != null) {
|
||||
Assert.isTrue(
|
||||
!(equalTypeAndSubType(MessageConverterUtils.X_JAVA_OBJECT,
|
||||
contentType) && targetClass == null),
|
||||
"Cannot deserialize into message since 'contentType` is not "
|
||||
+ "encoded with the actual target type."
|
||||
+ "Consider 'application/x-java-object; type=foo.bar.MyClass'");
|
||||
+ "encoded with the actual target type."
|
||||
+ "Consider 'application/x-java-object; type=foo.bar.MyClass'");
|
||||
payload = converter.fromMessage(message, targetClass);
|
||||
}
|
||||
else {
|
||||
MimeType deserializeContentType = contentTypeResolver.resolve(message.getHeaders());
|
||||
MimeType deserializeContentType = this.contentTypeResolver
|
||||
.resolve(message.getHeaders());
|
||||
if (deserializeContentType == null) {
|
||||
deserializeContentType = contentType;
|
||||
}
|
||||
payload = deserializeContentType == null ? message.getPayload() : this.deserializePayload(message.getPayload(), deserializeContentType);
|
||||
payload = deserializeContentType == null ? message.getPayload() : this
|
||||
.deserializePayload(message.getPayload(), deserializeContentType);
|
||||
}
|
||||
message = MessageBuilder.withPayload(payload)
|
||||
.copyHeaders(message.getHeaders())
|
||||
.setHeader(MessageHeaders.CONTENT_TYPE, contentType)
|
||||
.removeHeader(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE)
|
||||
.build();
|
||||
.removeHeader(BinderHeaders.BINDER_ORIGINAL_CONTENT_TYPE).build();
|
||||
return message;
|
||||
}
|
||||
|
||||
private Object deserializePayload(Object payload, MimeType contentType) {
|
||||
if (payload instanceof byte[] && ("text".equalsIgnoreCase(contentType.getType()) ||
|
||||
equalTypeAndSubType(MimeTypeUtils.APPLICATION_JSON, contentType))) {
|
||||
payload = new String((byte[])payload, StandardCharsets.UTF_8);
|
||||
if (payload instanceof byte[]
|
||||
&& ("text".equalsIgnoreCase(contentType.getType())
|
||||
|| equalTypeAndSubType(MimeTypeUtils.APPLICATION_JSON,
|
||||
contentType))) {
|
||||
payload = new String((byte[]) payload, StandardCharsets.UTF_8);
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
/*
|
||||
* Candidate to go into some utils class
|
||||
*/
|
||||
private static boolean equalTypeAndSubType(MimeType m1, MimeType m2) {
|
||||
return m1 != null && m2 != null && m1.getType().equalsIgnoreCase(m2.getType()) && m1.getSubtype().equalsIgnoreCase(m2.getSubtype());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,4 +59,5 @@ public class TestSupportBinderAutoConfiguration {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ public class TestSupportBinderConfiguration {
|
||||
|
||||
@Bean
|
||||
public Binder<MessageChannel, ?, ?> binder() {
|
||||
return messageChannelBinder;
|
||||
return this.messageChannelBinder;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ import org.springframework.messaging.Message;
|
||||
* </pre>
|
||||
* </p>
|
||||
*
|
||||
* @param <T> return type
|
||||
* @author Eric Bottard
|
||||
* @author Janne Valkealahti
|
||||
*/
|
||||
@@ -72,7 +73,8 @@ public class MessageQueueMatcher<T> extends BaseMatcher<BlockingQueue<Message<?>
|
||||
|
||||
private Map<BlockingQueue<Message<?>>, T> actuallyReceived = new HashMap<>();
|
||||
|
||||
public MessageQueueMatcher(Matcher<T> delegate, long timeout, TimeUnit unit, Extractor<Message<?>, T> extractor) {
|
||||
public MessageQueueMatcher(Matcher<T> delegate, long timeout, TimeUnit unit,
|
||||
Extractor<Message<?>, T> extractor) {
|
||||
this.delegate = delegate;
|
||||
this.timeout = timeout;
|
||||
this.unit = (unit != null ? unit : TimeUnit.SECONDS);
|
||||
@@ -80,7 +82,8 @@ public class MessageQueueMatcher<T> extends BaseMatcher<BlockingQueue<Message<?>
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static <P> MessageQueueMatcher<P> receivesMessageThat(Matcher<Message<P>> messageMatcher) {
|
||||
public static <P> MessageQueueMatcher<P> receivesMessageThat(
|
||||
Matcher<Message<P>> messageMatcher) {
|
||||
return new MessageQueueMatcher(messageMatcher, 5, TimeUnit.SECONDS,
|
||||
new Extractor<Message<P>, Message<P>>("a message that ") {
|
||||
@Override
|
||||
@@ -91,7 +94,8 @@ public class MessageQueueMatcher<T> extends BaseMatcher<BlockingQueue<Message<?>
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static <P> MessageQueueMatcher<P> receivesPayloadThat(Matcher<P> payloadMatcher) {
|
||||
public static <P> MessageQueueMatcher<P> receivesPayloadThat(
|
||||
Matcher<P> payloadMatcher) {
|
||||
return new MessageQueueMatcher(payloadMatcher, 5, TimeUnit.SECONDS,
|
||||
new Extractor<Message<P>, P>("a message whose payload ") {
|
||||
@Override
|
||||
@@ -107,10 +111,10 @@ public class MessageQueueMatcher<T> extends BaseMatcher<BlockingQueue<Message<?>
|
||||
BlockingQueue<Message<?>> queue = (BlockingQueue<Message<?>>) item;
|
||||
Message<?> received = null;
|
||||
try {
|
||||
if (timeout > 0) {
|
||||
received = queue.poll(timeout, unit);
|
||||
if (this.timeout > 0) {
|
||||
received = queue.poll(this.timeout, this.unit);
|
||||
}
|
||||
else if (timeout == 0) {
|
||||
else if (this.timeout == 0) {
|
||||
received = queue.poll();
|
||||
}
|
||||
else {
|
||||
@@ -120,21 +124,22 @@ public class MessageQueueMatcher<T> extends BaseMatcher<BlockingQueue<Message<?>
|
||||
catch (InterruptedException e) {
|
||||
return false;
|
||||
}
|
||||
T unwrapped = extractor.apply(received);
|
||||
actuallyReceived.put(queue, unwrapped);
|
||||
return delegate.matches(unwrapped);
|
||||
T unwrapped = this.extractor.apply(received);
|
||||
this.actuallyReceived.put(queue, unwrapped);
|
||||
return this.delegate.matches(unwrapped);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeMismatch(Object item, Description description) {
|
||||
@SuppressWarnings("unchecked")
|
||||
BlockingQueue<Message<?>> queue = (BlockingQueue<Message<?>>) item;
|
||||
T value = actuallyReceived.get(queue);
|
||||
T value = this.actuallyReceived.get(queue);
|
||||
if (value != null) {
|
||||
description.appendText("received: ").appendValue(value);
|
||||
}
|
||||
else {
|
||||
description.appendText("timed out after " + timeout + " " + unit.name().toLowerCase());
|
||||
description.appendText("timed out after " + this.timeout + " "
|
||||
+ this.unit.name().toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,14 +157,19 @@ public class MessageQueueMatcher<T> extends BaseMatcher<BlockingQueue<Message<?>
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText("Channel to receive ").appendDescriptionOf(extractor).appendDescriptionOf(delegate);
|
||||
description.appendText("Channel to receive ").appendDescriptionOf(this.extractor)
|
||||
.appendDescriptionOf(this.delegate);
|
||||
}
|
||||
|
||||
/**
|
||||
* A transformation to be applied to a received message before asserting, <i>e.g.</i>
|
||||
* to only inspect the payload.
|
||||
*
|
||||
* @param <R> input type
|
||||
* @param <T> return type
|
||||
*/
|
||||
public static abstract class Extractor<R, T> implements Function<R, T>, SelfDescribing {
|
||||
public static abstract class Extractor<R, T>
|
||||
implements Function<R, T>, SelfDescribing {
|
||||
|
||||
private final String behaviorDescription;
|
||||
|
||||
@@ -169,8 +179,9 @@ public class MessageQueueMatcher<T> extends BaseMatcher<BlockingQueue<Message<?>
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText(behaviorDescription);
|
||||
description.appendText(this.behaviorDescription);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,8 +44,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = AggregateWithBeanTest.ChainedProcessors.class, properties = { "server.port=-1","--spring.cloud.stream.bindings.input.contentType=text/plain",
|
||||
"--spring.cloud.stream.bindings.output.contentType=text/plain"})
|
||||
@SpringBootTest(classes = AggregateWithBeanTest.ChainedProcessors.class, properties = {
|
||||
"server.port=-1", "--spring.cloud.stream.bindings.input.contentType=text/plain",
|
||||
"--spring.cloud.stream.bindings.output.contentType=text/plain" })
|
||||
@Ignore
|
||||
public class AggregateWithBeanTest {
|
||||
|
||||
@@ -58,10 +59,13 @@ public class AggregateWithBeanTest {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testAggregateApplication() throws InterruptedException {
|
||||
Processor uppercaseProcessor = aggregateApplication.getBinding(Processor.class, "upper");
|
||||
Processor suffixProcessor = aggregateApplication.getBinding(Processor.class, "suffix");
|
||||
Processor uppercaseProcessor = this.aggregateApplication
|
||||
.getBinding(Processor.class, "upper");
|
||||
Processor suffixProcessor = this.aggregateApplication.getBinding(Processor.class,
|
||||
"suffix");
|
||||
uppercaseProcessor.input().send(MessageBuilder.withPayload("Hello").build());
|
||||
Message<String> receivedMessage = (Message<String>) messageCollector.forChannel(suffixProcessor.output()).poll(1, TimeUnit.SECONDS);
|
||||
Message<String> receivedMessage = (Message<String>) this.messageCollector
|
||||
.forChannel(suffixProcessor.output()).poll(1, TimeUnit.SECONDS);
|
||||
assertThat(receivedMessage).isNotNull();
|
||||
assertThat(receivedMessage.getPayload()).isEqualTo("HELLO WORLD!");
|
||||
}
|
||||
@@ -73,8 +77,10 @@ public class AggregateWithBeanTest {
|
||||
@Bean
|
||||
public AggregateApplication aggregateApplication() {
|
||||
return new AggregateApplicationBuilder().from(UppercaseProcessor.class)
|
||||
.namespace("upper").to(SuffixProcessor.class).namespace("suffix").build();
|
||||
.namespace("upper").to(SuffixProcessor.class).namespace("suffix")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -86,6 +92,7 @@ public class AggregateWithBeanTest {
|
||||
public String transform(String in) {
|
||||
return in.toUpperCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@@ -97,5 +104,7 @@ public class AggregateWithBeanTest {
|
||||
public String transform(String in) {
|
||||
return in + " WORLD!";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -48,17 +48,22 @@ public class AggregateWithMainTest {
|
||||
@Test
|
||||
public void testAggregateApplication() throws InterruptedException {
|
||||
// emulate a main method
|
||||
ConfigurableApplicationContext context = new AggregateApplicationBuilder(MainConfiguration.class).web(false)
|
||||
.from(UppercaseProcessor.class).namespace("upper")
|
||||
.to(SuffixProcessor.class).namespace("suffix")
|
||||
.run("--spring.cloud.stream.bindings.input.contentType=text/plain","--spring.cloud.stream.bindings.output.contentType=text/plain");
|
||||
ConfigurableApplicationContext context = new AggregateApplicationBuilder(
|
||||
MainConfiguration.class).web(false).from(UppercaseProcessor.class)
|
||||
.namespace("upper").to(SuffixProcessor.class).namespace("suffix")
|
||||
.run("--spring.cloud.stream.bindings.input.contentType=text/plain",
|
||||
"--spring.cloud.stream.bindings.output.contentType=text/plain");
|
||||
|
||||
AggregateApplication aggregateAccessor = context.getBean(AggregateApplication.class);
|
||||
AggregateApplication aggregateAccessor = context
|
||||
.getBean(AggregateApplication.class);
|
||||
MessageCollector messageCollector = context.getBean(MessageCollector.class);
|
||||
Processor uppercaseProcessor = aggregateAccessor.getBinding(Processor.class, "upper");
|
||||
Processor suffixProcessor = aggregateAccessor.getBinding(Processor.class, "suffix");
|
||||
Processor uppercaseProcessor = aggregateAccessor.getBinding(Processor.class,
|
||||
"upper");
|
||||
Processor suffixProcessor = aggregateAccessor.getBinding(Processor.class,
|
||||
"suffix");
|
||||
uppercaseProcessor.input().send(MessageBuilder.withPayload("Hello").build());
|
||||
Message<String> receivedMessage = (Message<String>) messageCollector.forChannel(suffixProcessor.output()).poll(1, TimeUnit.SECONDS);
|
||||
Message<String> receivedMessage = (Message<String>) messageCollector
|
||||
.forChannel(suffixProcessor.output()).poll(1, TimeUnit.SECONDS);
|
||||
assertThat(receivedMessage).isNotNull();
|
||||
assertThat(receivedMessage.getPayload()).isEqualTo("HELLO WORLD!");
|
||||
context.close();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,11 +41,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = AutoconfigurationDisabledTest.MyProcessor.class, properties = {
|
||||
"server.port=-1",
|
||||
"spring.cloud.stream.defaultBinder=test",
|
||||
"server.port=-1", "spring.cloud.stream.defaultBinder=test",
|
||||
"--spring.cloud.stream.bindings.input.contentType=text/plain",
|
||||
"--spring.cloud.stream.bindings.output.contentType=text/plain"
|
||||
})
|
||||
"--spring.cloud.stream.bindings.output.contentType=text/plain" })
|
||||
@DirtiesContext
|
||||
public class AutoconfigurationDisabledTest {
|
||||
|
||||
@@ -58,9 +56,10 @@ public class AutoconfigurationDisabledTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testAutoconfigurationDisabled() throws Exception {
|
||||
processor.input().send(MessageBuilder.withPayload("Hello").build());
|
||||
this.processor.input().send(MessageBuilder.withPayload("Hello").build());
|
||||
// Since the interaction is synchronous, the result should be immediate
|
||||
Message<String> response = (Message<String>) messageCollector.forChannel(processor.output()).poll(1000, TimeUnit.MILLISECONDS);
|
||||
Message<String> response = (Message<String>) this.messageCollector
|
||||
.forChannel(this.processor.output()).poll(1000, TimeUnit.MILLISECONDS);
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getPayload()).isEqualTo("Hello world");
|
||||
}
|
||||
@@ -73,5 +72,7 @@ public class AutoconfigurationDisabledTest {
|
||||
public String transform(String in) {
|
||||
return in + " world";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,10 +39,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* correctly.
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = ExampleTest.MyProcessor.class, webEnvironment = SpringBootTest.WebEnvironment.NONE,
|
||||
properties = {
|
||||
// @checkstyle:off
|
||||
@SpringBootTest(classes = ExampleTest.MyProcessor.class, webEnvironment = SpringBootTest.WebEnvironment.NONE, properties = {
|
||||
"--spring.cloud.stream.bindings.input.contentType=text/plain",
|
||||
"--spring.cloud.stream.bindings.output.contentType=text/plain"})
|
||||
"--spring.cloud.stream.bindings.output.contentType=text/plain" })
|
||||
// @checkstyle:on
|
||||
@DirtiesContext
|
||||
public class ExampleTest {
|
||||
|
||||
@@ -57,7 +58,8 @@ public class ExampleTest {
|
||||
public void testWiring() {
|
||||
Message<String> message = new GenericMessage<>("hello");
|
||||
this.processor.input().send(message);
|
||||
Message<String> received = (Message<String>) this.messageCollector.forChannel(this.processor.output()).poll();
|
||||
Message<String> received = (Message<String>) this.messageCollector
|
||||
.forChannel(this.processor.output()).poll();
|
||||
assertThat(received.getPayload()).isEqualTo("hello world");
|
||||
}
|
||||
|
||||
@@ -69,6 +71,7 @@ public class ExampleTest {
|
||||
public String transform(String in) {
|
||||
return in + " world";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,13 +44,14 @@ public class MessageQueueMatcherTest {
|
||||
@Test
|
||||
public void testTimeout() {
|
||||
Message<?> msg = new GenericMessage<>("hello");
|
||||
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg)).within(2,
|
||||
TimeUnit.MILLISECONDS);
|
||||
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg))
|
||||
.within(2, TimeUnit.MILLISECONDS);
|
||||
|
||||
boolean result = matcher.matches(this.queue);
|
||||
assertThat(result).isFalse();
|
||||
matcher.describeMismatch(this.queue, this.description);
|
||||
assertThat(this.description.toString()).isEqualTo("timed out after 2 milliseconds");
|
||||
assertThat(this.description.toString())
|
||||
.isEqualTo("timed out after 2 milliseconds");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,16 +77,19 @@ public class MessageQueueMatcherTest {
|
||||
|
||||
@Test
|
||||
public void testExtractor() {
|
||||
Message<?> msg = new GenericMessage<>("hello", Collections.singletonMap("foo", (Object) "bar"));
|
||||
Message<?> msg = new GenericMessage<>("hello",
|
||||
Collections.singletonMap("foo", (Object) "bar"));
|
||||
|
||||
MessageQueueMatcher.Extractor<Message<?>, String> headerExtractor = new MessageQueueMatcher.Extractor<Message<?>, String>(
|
||||
MessageQueueMatcher.Extractor<Message<?>, String> headerExtractor;
|
||||
headerExtractor = new MessageQueueMatcher.Extractor<Message<?>, String>(
|
||||
"whose 'foo' header") {
|
||||
@Override
|
||||
public String apply(Message<?> message) {
|
||||
return message.getHeaders().get("foo", String.class);
|
||||
}
|
||||
};
|
||||
MessageQueueMatcher<?> matcher = new MessageQueueMatcher<>(is("bar"), -1, null, headerExtractor);
|
||||
MessageQueueMatcher<?> matcher = new MessageQueueMatcher<>(is("bar"), -1, null,
|
||||
headerExtractor);
|
||||
this.queue.offer(msg);
|
||||
boolean result = matcher.matches(this.queue);
|
||||
assertThat(result);
|
||||
@@ -102,6 +106,8 @@ public class MessageQueueMatcherTest {
|
||||
Message<?> msg = new GenericMessage<>("hello");
|
||||
MessageQueueMatcher<?> matcher = MessageQueueMatcher.receivesMessageThat(is(msg));
|
||||
this.description.appendDescriptionOf(matcher);
|
||||
assertThat(this.description.toString()).isEqualTo(("Channel to receive a message that is <" + msg + ">"));
|
||||
assertThat(this.description.toString())
|
||||
.isEqualTo(("Channel to receive a message that is <" + msg + ">"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user