Support Java 14 (#3310)

* Support Java 14

* Provide changes to avoid deprecated Java API
and have a compatibility back to Java 8
* Change affected test classes to JUnit 5 whenever it is possible
* Ignore/Disable some TCP/IP tests which don't pass on Java 14

* Fix (some) TCP tests on JRE 14

* Fix SSL Handshake test - client side handshake is successful with java 14

- change the badClient cert to a badServer cert to force an error on the client side

Co-authored-by: artembilan <raven666>
Co-authored-by: Gary Russell <grussell@pivotal.io>
This commit is contained in:
Artem Bilan
2020-06-17 14:00:06 -04:00
committed by GitHub
parent b0cd0156c7
commit 3f5aba2cb9
53 changed files with 613 additions and 671 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2020 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.
@@ -20,6 +20,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.core.ResolvableType;
import org.springframework.integration.channel.DirectChannel;
@@ -55,14 +56,9 @@ public abstract class EndpointSpec<S extends EndpointSpec<S, F, H>, F extends Be
@SuppressWarnings("unchecked")
protected EndpointSpec(H handler) {
try {
Class<?> fClass = ResolvableType.forClass(this.getClass()).as(EndpointSpec.class).resolveGenerics()[1];
this.endpointFactoryBean = (F) fClass.newInstance();
this.handler = handler;
}
catch (Exception e) {
throw new IllegalStateException(e);
}
Class<?> fClass = ResolvableType.forClass(this.getClass()).as(EndpointSpec.class).resolveGenerics()[1];
this.endpointFactoryBean = (F) BeanUtils.instantiateClass(fClass);
this.handler = handler;
}
@Override

View File

@@ -179,14 +179,14 @@ public abstract class IntegrationFlowAdapter implements IntegrationFlow, SmartLi
return IntegrationFlows.from(inboundGatewaySpec);
}
protected <T> IntegrationFlowBuilder from(Supplier<T> messageSource) {
return IntegrationFlows.from(messageSource);
protected <T> IntegrationFlowBuilder fromSupplier(Supplier<T> messageSource) {
return IntegrationFlows.fromSupplier(messageSource);
}
protected <T> IntegrationFlowBuilder from(Supplier<T> messageSource,
protected <T> IntegrationFlowBuilder fromSupplier(Supplier<T> messageSource,
Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer) {
return IntegrationFlows.from(messageSource, endpointConfigurer);
return IntegrationFlows.fromSupplier(messageSource, endpointConfigurer);
}
protected IntegrationFlowBuilder from(Class<?> serviceInterface) {

View File

@@ -141,8 +141,8 @@ public final class IntegrationFlows {
* @return new {@link IntegrationFlowBuilder}.
* @see Supplier
*/
public static <T> IntegrationFlowBuilder from(Supplier<T> messageSource) {
return from(messageSource, null);
public static <T> IntegrationFlowBuilder fromSupplier(Supplier<T> messageSource) {
return fromSupplier(messageSource, null);
}
/**
@@ -156,7 +156,7 @@ public final class IntegrationFlows {
* @return new {@link IntegrationFlowBuilder}.
* @see Supplier
*/
public static <T> IntegrationFlowBuilder from(Supplier<T> messageSource,
public static <T> IntegrationFlowBuilder fromSupplier(Supplier<T> messageSource,
Consumer<SourcePollingChannelAdapterSpec> endpointConfigurer) {
Assert.notNull(messageSource, "'messageSource' must not be null");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -27,7 +27,7 @@ import org.springframework.messaging.Message;
* <p>
* The BridgeHandler can be used as a stopper at the end of an assembly line of
* channels. In this setup the output channel doesn't have to be set, but if the
* output channel is omitted the <tt>REPLY_CHANNEL</tt> MUST be set on the
* output channel is omitted the {@code REPLY_CHANNEL} MUST be set on the
* message. Otherwise, a MessagingException will be thrown at runtime.
*
* @author Mark Fisher

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -52,8 +52,8 @@ public interface MetadataStore {
/**
* Remove a value for the given key from this MetadataStore.
* @param key The key.
* @return The previous value associated with <tt>key</tt>, or
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
* @return The previous value associated with key, or
* null if there was no mapping for key.
*/
@ManagedAttribute
String remove(String key);

View File

@@ -106,7 +106,7 @@ fun integrationFlow(messageSource: MessageSourceSpec<*, out MessageSource<*>>,
fun integrationFlow(source: () -> Any,
options: SourcePollingChannelAdapterSpec.() -> Unit = {},
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(source, options), flow)
buildIntegrationFlow(IntegrationFlows.fromSupplier(source, options), flow)
/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -63,13 +63,13 @@ public class DelayerParserTests {
DelayHandler delayHandler = context.getBean("delayerWithDefaultScheduler.handler", DelayHandler.class);
assertThat(delayHandler.getOrder()).isEqualTo(99);
assertThat(delayHandler.getOutputChannel()).isSameAs(this.context.getBean("output"));
assertThat(TestUtils.getPropertyValue(delayHandler, "defaultDelay", Long.class)).isEqualTo(new Long(1234));
assertThat(TestUtils.getPropertyValue(delayHandler, "defaultDelay", Long.class)).isEqualTo(1234L);
//INT-2243
assertThat(TestUtils.getPropertyValue(delayHandler, "delayExpression")).isNotNull();
assertThat(TestUtils.getPropertyValue(delayHandler, "delayExpression", Expression.class).getExpressionString())
.isEqualTo("headers.foo");
assertThat(TestUtils.getPropertyValue(delayHandler, "messagingTemplate.sendTimeout", Long.class))
.isEqualTo(new Long(987));
.isEqualTo(987L);
assertThat(TestUtils.getPropertyValue(delayHandler, "taskScheduler")).isNull();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -159,7 +159,7 @@ public class HeaderEnricherOverwriteTests {
template.setDefaultDestination(channel);
Message<?> result = template.sendAndReceive(new GenericMessage<String>("test"));
assertThat(result).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(result).getPriority()).isEqualTo(new Integer(42));
assertThat(new IntegrationMessageHeaderAccessor(result).getPriority()).isEqualTo(42);
}
@Test
@@ -173,7 +173,7 @@ public class HeaderEnricherOverwriteTests {
input.send(message);
Message<?> result = replyChannel.receive(0);
assertThat(result).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(result).getPriority()).isEqualTo(new Integer(77));
assertThat(new IntegrationMessageHeaderAccessor(result).getPriority()).isEqualTo(77);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -137,7 +138,7 @@ public class HeaderEnricherTests {
MessageChannel channel = context.getBean("expirationDateValueInput", MessageChannel.class);
Message<?> result = template.sendAndReceive(channel, new GenericMessage<>("test"));
assertThat(result).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(result).getExpirationDate()).isEqualTo(new Long(1111));
assertThat(new IntegrationMessageHeaderAccessor(result).getExpirationDate()).isEqualTo(1111L);
}
@Test
@@ -146,7 +147,7 @@ public class HeaderEnricherTests {
MessageChannel channel = context.getBean("expirationDateRefInput", MessageChannel.class);
Message<?> result = template.sendAndReceive(channel, new GenericMessage<>("test"));
assertThat(result).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(result).getExpirationDate()).isEqualTo(new Long(9999));
assertThat(new IntegrationMessageHeaderAccessor(result).getExpirationDate()).isEqualTo(9999);
}
@Test
@@ -155,7 +156,7 @@ public class HeaderEnricherTests {
MessageChannel channel = context.getBean("priorityInput", MessageChannel.class);
Message<?> result = template.sendAndReceive(channel, new GenericMessage<>("test"));
assertThat(result).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(result).getPriority()).isEqualTo(new Integer(42));
assertThat(new IntegrationMessageHeaderAccessor(result).getPriority()).isEqualTo(42);
}
@Test
@@ -165,7 +166,7 @@ public class HeaderEnricherTests {
Message<?> result = template.sendAndReceive(channel,
new GenericMessage<>(Collections.singletonMap("priority", "-10")));
assertThat(result).isNotNull();
assertThat(new IntegrationMessageHeaderAccessor(result).getPriority()).isEqualTo(new Integer(-10));
assertThat(new IntegrationMessageHeaderAccessor(result).getPriority()).isEqualTo(-10);
}
@Test
@@ -300,7 +301,7 @@ public class HeaderEnricherTests {
TestBean testBean = (TestBean) o;
return !(name != null ? !name.equals(testBean.name) : testBean.name != null);
return Objects.equals(name, testBean.name);
}

View File

@@ -540,7 +540,7 @@ public class IntegrationFlowTests {
@Bean
public IntegrationFlow supplierFlow() {
return IntegrationFlows.from(stringSupplier())
return IntegrationFlows.fromSupplier(stringSupplier())
.transform(toUpperCaseFunction())
.channel("suppliedChannel")
.get();
@@ -572,7 +572,8 @@ public class IntegrationFlowTests {
@Bean
public IntegrationFlow supplierFlow2() {
return IntegrationFlows.from(() -> "foo", c -> c.poller(Pollers.fixedDelay(100).maxMessagesPerPoll(1)))
return IntegrationFlows.fromSupplier(() -> "foo",
c -> c.poller(Pollers.fixedDelay(100).maxMessagesPerPoll(1)))
.<String, String>transform(String::toUpperCase)
.channel("suppliedChannel2")
.get();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2020 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.
@@ -25,8 +25,7 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
@@ -60,7 +59,7 @@ import org.springframework.messaging.handler.annotation.Header;
import org.springframework.scheduling.TriggerContext;
import org.springframework.stereotype.Component;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.StringUtils;
/**
@@ -68,7 +67,7 @@ import org.springframework.util.StringUtils;
*
* @since 5.0
*/
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class FlowServiceTests {
@@ -174,7 +173,7 @@ public class FlowServiceTests {
@Override
protected IntegrationFlowDefinition<?> buildFlow() {
return from(this::messageSource, e -> e.poller(p -> p.trigger(this::nextExecutionTime)))
return fromSupplier(this::messageSource, e -> e.poller(p -> p.trigger(this::nextExecutionTime)))
.split(this, null, e -> e.applySequence(false))
.transform(this)
.aggregate(a -> a.processor(this, null))

View File

@@ -34,8 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanCreationNotAllowedException;
@@ -87,7 +86,7 @@ import org.springframework.messaging.support.GenericMessage;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.ReflectionUtils;
import reactor.core.publisher.Flux;
@@ -100,7 +99,7 @@ import reactor.core.publisher.Flux;
*/
@ContextConfiguration(loader = NoBeansOverrideAnnotationConfigContextLoader.class,
classes = ManualFlowTests.RootConfiguration.class)
@RunWith(SpringRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class ManualFlowTests {
@@ -537,7 +536,7 @@ public class ManualFlowTests {
.withCauseExactlyInstanceOf(IllegalStateException.class)
.withRootCauseInstanceOf(ClassCastException.class)
.withMessageContaining("from source: '" + source + "'")
.withStackTraceContaining("java.util.Date cannot be cast to java.lang.String");
.withStackTraceContaining("java.util.Date cannot be cast to");
flowRegistration.destroy();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -58,9 +58,9 @@ public class ProducerAndConsumerAutoStartupTests {
received.add(this.consumer.poll(10000));
}
this.context.stop();
assertThat(received.get(0)).isEqualTo(new Integer(1));
assertThat(received.get(1)).isEqualTo(new Integer(2));
assertThat(received.get(2)).isEqualTo(new Integer(3));
assertThat(received.get(0)).isEqualTo(1);
assertThat(received.get(1)).isEqualTo(2);
assertThat(received.get(2)).isEqualTo(3);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -18,21 +18,19 @@ package org.springframework.integration.filter;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Mark Fisher
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
public class DynamicExpressionFilterIntegrationTests {
@Autowired
@@ -46,15 +44,15 @@ public class DynamicExpressionFilterIntegrationTests {
@Test
public void simpleExpressionBasedFilter() {
this.input.send(new GenericMessage<Integer>(1));
this.input.send(new GenericMessage<Integer>(0));
this.input.send(new GenericMessage<Integer>(99));
this.input.send(new GenericMessage<Integer>(-99));
assertThat(positives.receive(0).getPayload()).isEqualTo(new Integer(1));
assertThat(positives.receive(0).getPayload()).isEqualTo(new Integer(99));
assertThat(negatives.receive(0).getPayload()).isEqualTo(new Integer(0));
assertThat(negatives.receive(0).getPayload()).isEqualTo(new Integer(-99));
void simpleExpressionBasedFilter() {
this.input.send(new GenericMessage<>(1));
this.input.send(new GenericMessage<>(0));
this.input.send(new GenericMessage<>(99));
this.input.send(new GenericMessage<>(-99));
assertThat(positives.receive(0).getPayload()).isEqualTo(1);
assertThat(positives.receive(0).getPayload()).isEqualTo(99);
assertThat(negatives.receive(0).getPayload()).isEqualTo(0);
assertThat(negatives.receive(0).getPayload()).isEqualTo(-99);
assertThat(positives.receive(0)).isNull();
assertThat(negatives.receive(0)).isNull();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -18,21 +18,19 @@ package org.springframework.integration.filter;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Mark Fisher
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
public class SpelFilterIntegrationTests {
@Autowired
@@ -56,28 +54,28 @@ public class SpelFilterIntegrationTests {
@Test
public void simpleExpressionBasedFilter() {
this.simpleInput.send(new GenericMessage<Integer>(1));
this.simpleInput.send(new GenericMessage<Integer>(0));
this.simpleInput.send(new GenericMessage<Integer>(99));
this.simpleInput.send(new GenericMessage<Integer>(-99));
assertThat(positives.receive(0).getPayload()).isEqualTo(new Integer(1));
assertThat(positives.receive(0).getPayload()).isEqualTo(new Integer(99));
assertThat(negatives.receive(0).getPayload()).isEqualTo(new Integer(0));
assertThat(negatives.receive(0).getPayload()).isEqualTo(new Integer(-99));
this.simpleInput.send(new GenericMessage<>(1));
this.simpleInput.send(new GenericMessage<>(0));
this.simpleInput.send(new GenericMessage<>(99));
this.simpleInput.send(new GenericMessage<>(-99));
assertThat(positives.receive(0).getPayload()).isEqualTo(1);
assertThat(positives.receive(0).getPayload()).isEqualTo(99);
assertThat(negatives.receive(0).getPayload()).isEqualTo(0);
assertThat(negatives.receive(0).getPayload()).isEqualTo(-99);
assertThat(positives.receive(0)).isNull();
assertThat(negatives.receive(0)).isNull();
}
@Test
public void beanResolvingExpressionBasedFilter() {
this.beanResolvingInput.send(new GenericMessage<Integer>(1));
this.beanResolvingInput.send(new GenericMessage<Integer>(2));
this.beanResolvingInput.send(new GenericMessage<Integer>(9));
this.beanResolvingInput.send(new GenericMessage<Integer>(22));
assertThat(odds.receive(0).getPayload()).isEqualTo(new Integer(1));
assertThat(odds.receive(0).getPayload()).isEqualTo(new Integer(9));
assertThat(evens.receive(0).getPayload()).isEqualTo(new Integer(2));
assertThat(evens.receive(0).getPayload()).isEqualTo(new Integer(22));
this.beanResolvingInput.send(new GenericMessage<>(1));
this.beanResolvingInput.send(new GenericMessage<>(2));
this.beanResolvingInput.send(new GenericMessage<>(9));
this.beanResolvingInput.send(new GenericMessage<>(22));
assertThat(odds.receive(0).getPayload()).isEqualTo(1);
assertThat(odds.receive(0).getPayload()).isEqualTo(9);
assertThat(evens.receive(0).getPayload()).isEqualTo(2);
assertThat(evens.receive(0).getPayload()).isEqualTo(22);
assertThat(odds.receive(0)).isNull();
assertThat(evens.receive(0)).isNull();
}
@@ -89,6 +87,7 @@ public class SpelFilterIntegrationTests {
public boolean isEven(int number) {
return number % 2 == 0;
}
}
}

View File

@@ -209,7 +209,7 @@ public class GatewayProxyFactoryBeanTests {
proxyFactory.afterPropertiesSet();
TestService service = (TestService) proxyFactory.getObject();
Integer result = service.requestReplyWithIntegers(123);
assertThat(result).isEqualTo(new Integer(123456));
assertThat(result).isEqualTo(123456);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -255,8 +255,8 @@ public class MethodInvokingMessageProcessorAnnotationTests {
.setHeader("attrib2", 456).build();
Map<String, Integer> result = (Map<String, Integer>) processor.processMessage(message);
assertThat(result.size()).isEqualTo(2);
assertThat(result.get("attrib1")).isEqualTo(new Integer(88));
assertThat(result.get("attrib2")).isEqualTo(new Integer(99));
assertThat(result.get("attrib1")).isEqualTo(88);
assertThat(result.get("attrib2")).isEqualTo(99);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -77,7 +77,7 @@ public class MessageBuilderTests {
.setHeader("count", 123)
.build();
assertThat(message.getHeaders().get("foo", String.class)).isEqualTo("bar");
assertThat(message.getHeaders().get("count", Integer.class)).isEqualTo(new Integer(123));
assertThat(message.getHeaders().get("count", Integer.class)).isEqualTo(123);
}
@Test
@@ -189,7 +189,7 @@ public class MessageBuilderTests {
public void testPriority() {
Message<Integer> importantMessage = MessageBuilder.withPayload(1)
.setPriority(123).build();
assertThat(new IntegrationMessageHeaderAccessor(importantMessage).getPriority()).isEqualTo(new Integer(123));
assertThat(new IntegrationMessageHeaderAccessor(importantMessage).getPriority()).isEqualTo(123);
}
@Test
@@ -199,7 +199,7 @@ public class MessageBuilderTests {
Message<Integer> message2 = MessageBuilder.fromMessage(message1)
.setHeaderIfAbsent(IntegrationMessageHeaderAccessor.PRIORITY, 13)
.build();
assertThat(new IntegrationMessageHeaderAccessor(message2).getPriority()).isEqualTo(new Integer(42));
assertThat(new IntegrationMessageHeaderAccessor(message2).getPriority()).isEqualTo(42);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -17,6 +17,7 @@
package org.springframework.integration.message;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -26,12 +27,13 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.messaging.MessageHeaders;
/**
* @author Mark Fisher
* @author Artem Bilan
*/
public class MessageHeadersTests {
@@ -50,7 +52,7 @@ public class MessageHeadersTests {
}
@Test
public void testIdOverwritten() throws Exception {
public void testIdOverwritten() {
MessageHeaders headers1 = new MessageHeaders(null);
MessageHeaders headers2 = new MessageHeaders(headers1);
assertThat(headers2.getId()).isNotSameAs(headers1.getId());
@@ -64,8 +66,8 @@ public class MessageHeadersTests {
@Test
public void testNonTypedAccessOfHeaderValue() {
Integer value = new Integer(123);
Map<String, Object> map = new HashMap<String, Object>();
int value = 123;
Map<String, Object> map = new HashMap<>();
map.put("test", value);
MessageHeaders headers = new MessageHeaders(map);
assertThat(headers.get("test")).isEqualTo(value);
@@ -73,41 +75,44 @@ public class MessageHeadersTests {
@Test
public void testTypedAccessOfHeaderValue() {
Integer value = new Integer(123);
Map<String, Object> map = new HashMap<String, Object>();
int value = 123;
Map<String, Object> map = new HashMap<>();
map.put("test", value);
MessageHeaders headers = new MessageHeaders(map);
assertThat(headers.get("test", Integer.class)).isEqualTo(value);
}
@Test(expected = IllegalArgumentException.class)
@Test
public void testHeaderValueAccessWithIncorrectType() {
Integer value = new Integer(123);
Map<String, Object> map = new HashMap<String, Object>();
int value = 123;
Map<String, Object> map = new HashMap<>();
map.put("test", value);
MessageHeaders headers = new MessageHeaders(map);
assertThat(headers.get("test", String.class)).isEqualTo(value);
assertThatIllegalArgumentException()
.isThrownBy(() -> headers.get("test", String.class))
.withMessageContaining(
"Expected [class java.lang.String] but actual type is [class java.lang.Integer]");
}
@Test
public void testNullHeaderValue() {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
MessageHeaders headers = new MessageHeaders(map);
assertThat(headers.get("nosuchattribute")).isNull();
}
@Test
public void testNullHeaderValueWithTypedAccess() {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
MessageHeaders headers = new MessageHeaders(map);
assertThat(headers.get("nosuchattribute", String.class)).isNull();
}
@Test
public void testHeaderKeys() {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("key1", "val1");
map.put("key2", new Integer(123));
map.put("key2", 123);
MessageHeaders headers = new MessageHeaders(map);
Set<String> keys = headers.keySet();
assertThat(keys.contains("key1")).isTrue();
@@ -116,7 +121,7 @@ public class MessageHeadersTests {
@Test
public void serializeWithAllSerializableHeaders() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("name", "joe");
map.put("age", 42);
MessageHeaders input = new MessageHeaders(map);
@@ -128,7 +133,7 @@ public class MessageHeadersTests {
@Test
public void serializeWithNonSerializableHeader() throws Exception {
Object address = new Object();
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("name", "joe");
map.put("address", address);
MessageHeaders input = new MessageHeaders(map);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -17,16 +17,18 @@
package org.springframework.integration.message;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.integration.handler.ServiceActivatingHandler;
@@ -44,24 +46,24 @@ import org.springframework.messaging.handler.annotation.Payload;
*
* @since 1.0.3
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public class PayloadAndHeaderMappingTests {
private static final ConfigurableApplicationContext applicationContext = TestUtils.createTestApplicationContext();
private TestBean bean;
@BeforeClass
@BeforeAll
public static void start() {
applicationContext.refresh();
}
@AfterClass
@AfterAll
public static void stop() {
applicationContext.close();
}
@Before
@BeforeEach
public void setup() {
bean = new TestBean();
}
@@ -71,7 +73,7 @@ public class PayloadAndHeaderMappingTests {
public void headerPropertiesAndObjectPayload() throws Exception {
MessageHandler handler = this.getHandler("headerPropertiesAndObjectPayload", Properties.class, Object.class);
Object payload = "test";
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -87,7 +89,7 @@ public class PayloadAndHeaderMappingTests {
public void stringPayloadAndHeaderProperties() throws Exception {
MessageHandler handler = this.getHandler("stringPayloadAndHeaderProperties", String.class, Properties.class);
Object payload = "test";
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -103,7 +105,7 @@ public class PayloadAndHeaderMappingTests {
public void headerMapAndObjectPayload() throws Exception {
MessageHandler handler = this.getHandler("headerMapAndObjectPayload", Map.class, Object.class);
Object payload = "test";
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -119,7 +121,7 @@ public class PayloadAndHeaderMappingTests {
public void objectPayloadAndHeaderMap() throws Exception {
MessageHandler handler = this.getHandler("objectPayloadAndHeaderMap", Object.class, Map.class);
Object payload = "test";
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -134,10 +136,10 @@ public class PayloadAndHeaderMappingTests {
@Test
public void payloadMapAndHeaderString() throws Exception {
MessageHandler handler = this.getHandler("payloadMapAndHeaderString", Map.class, String.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("abc", 1);
payload.put("xyz", "test");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Message<?> message = MessageBuilder.withPayload(payload).copyHeaders(headers).build();
@@ -150,10 +152,10 @@ public class PayloadAndHeaderMappingTests {
@Test
public void payloadMapAndHeaderStrings() throws Exception {
MessageHandler handler = this.getHandler("payloadMapAndHeaderStrings", Map.class, String.class, String.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("abc", 1);
payload.put("xyz", "test");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", "3");
@@ -170,7 +172,7 @@ public class PayloadAndHeaderMappingTests {
MessageHandler handler = this.getHandler("objectPayloadHeaderMapAndStringHeaders",
String.class, Map.class, String.class, Object.class);
Object payload = "test";
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -191,10 +193,10 @@ public class PayloadAndHeaderMappingTests {
@Test
public void payloadMapAndHeaderMap() throws Exception {
MessageHandler handler = this.getHandler("payloadMapAndHeaderMap", Map.class, Map.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("abc", 1);
payload.put("xyz", "test");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -209,10 +211,10 @@ public class PayloadAndHeaderMappingTests {
@Test
public void headerMapAndPayloadMap() throws Exception {
MessageHandler handler = this.getHandler("headerMapAndPayloadMap", Map.class, Map.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("abc", 1);
payload.put("xyz", "test");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -228,7 +230,7 @@ public class PayloadAndHeaderMappingTests {
public void headerMapOnlyWithStringPayload() throws Exception {
MessageHandler handler = this.getHandler("headerMapOnly", Map.class);
String payload = "test";
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -243,10 +245,10 @@ public class PayloadAndHeaderMappingTests {
@Test
public void headerMapOnlyWithMapPayload() throws Exception {
MessageHandler handler = this.getHandler("headerMapOnly", Map.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("abc", 1);
payload.put("xyz", "test");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -261,9 +263,9 @@ public class PayloadAndHeaderMappingTests {
@Test
public void mapOnlyNoAnnotationsWithMapPayload() throws Exception {
MessageHandler handler = this.getHandler("mapOnlyNoAnnotations", Map.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("payload", 1);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
Message<?> message = MessageBuilder.withPayload(payload).copyHeaders(headers).build();
handler.handleMessage(message);
assertThat(bean.lastPayload).isEqualTo(payload);
@@ -274,7 +276,7 @@ public class PayloadAndHeaderMappingTests {
public void mapOnlyNoAnnotationsWithStringPayload() throws Exception {
MessageHandler handler = this.getHandler("mapOnlyNoAnnotations", Map.class);
String payload = "test";
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -289,8 +291,8 @@ public class PayloadAndHeaderMappingTests {
@Test
public void mapOnlyNoAnnotationsWithIntegerPayload() throws Exception {
MessageHandler handler = this.getHandler("mapOnlyNoAnnotations", Map.class);
Integer payload = new Integer(123);
Map<String, Object> headers = new HashMap<String, Object>();
int payload = 123;
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -307,7 +309,7 @@ public class PayloadAndHeaderMappingTests {
MessageHandler handler = this.getHandler("propertiesOnlyNoAnnotations", Properties.class);
Properties payload = new Properties();
payload.setProperty("payload", "1");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
Message<?> message = MessageBuilder.withPayload(payload).copyHeaders(headers).build();
handler.handleMessage(message);
assertThat(bean.lastPayload).isEqualTo(payload);
@@ -317,9 +319,9 @@ public class PayloadAndHeaderMappingTests {
@Test
public void propertiesOnlyNoAnnotationsWithMapPayload() throws Exception {
MessageHandler handler = this.getHandler("propertiesOnlyNoAnnotations", Properties.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("payload", 1);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
Message<?> message = MessageBuilder.withPayload(payload).copyHeaders(headers).build();
handler.handleMessage(message);
assertThat(bean.lastPayload).isEqualTo(payload);
@@ -330,7 +332,7 @@ public class PayloadAndHeaderMappingTests {
public void propertiesOnlyNoAnnotationsWithStringPayload() throws Exception {
MessageHandler handler = this.getHandler("propertiesOnlyNoAnnotations", Properties.class);
String payload = "payload=abc";
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Message<?> message = MessageBuilder.withPayload(payload).copyHeaders(headers).build();
@@ -347,8 +349,8 @@ public class PayloadAndHeaderMappingTests {
@Test
public void propertiesOnlyNoAnnotationsWithIntegerPayload() throws Exception {
MessageHandler handler = this.getHandler("propertiesOnlyNoAnnotations", Properties.class);
Integer payload = new Integer(123);
Map<String, Object> headers = new HashMap<String, Object>();
int payload = 123;
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Message<?> message = MessageBuilder.withPayload(payload).copyHeaders(headers).build();
@@ -362,7 +364,7 @@ public class PayloadAndHeaderMappingTests {
public void headerPropertiesOnlyWithStringPayload() throws Exception {
MessageHandler handler = this.getHandler("headerPropertiesOnly", Properties.class);
String payload = "test";
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -377,10 +379,10 @@ public class PayloadAndHeaderMappingTests {
@Test
public void headerPropertiesOnlyWithMapPayload() throws Exception {
MessageHandler handler = this.getHandler("headerPropertiesOnly", Properties.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("abc", 1);
payload.put("xyz", "test");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -398,7 +400,7 @@ public class PayloadAndHeaderMappingTests {
Properties payload = new Properties();
payload.setProperty("abc", "1");
payload.setProperty("xyz", "2");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -413,10 +415,10 @@ public class PayloadAndHeaderMappingTests {
@Test
public void payloadMapAndHeaderProperties() throws Exception {
MessageHandler handler = this.getHandler("payloadMapAndHeaderProperties", Map.class, Properties.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("abc", 1);
payload.put("xyz", "test");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -432,10 +434,10 @@ public class PayloadAndHeaderMappingTests {
public void headerPropertiesPayloadMapAndStringHeader() throws Exception {
MessageHandler handler = this.getHandler("headerPropertiesPayloadMapAndStringHeader",
Properties.class, Map.class, String.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("abc", 1);
payload.put("xyz", "test");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
headers.put("baz", 99);
@@ -450,15 +452,16 @@ public class PayloadAndHeaderMappingTests {
//assertFalse(bean.lastHeaders.containsKey("baz"));
}
@Test(expected = IllegalArgumentException.class)
public void twoMapsNoAnnotations() throws Exception {
this.getHandler("twoMapsNoAnnotations", Map.class, Map.class);
@Test
public void twoMapsNoAnnotations() {
assertThatIllegalArgumentException()
.isThrownBy(() -> getHandler("twoMapsNoAnnotations", Map.class, Map.class));
}
@Test
public void twoMapsWithAnnotationsWithStringPayload() throws Exception {
MessageHandler handler = this.getHandler("twoMapsWithAnnotations", Map.class, Map.class);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Message<?> message = MessageBuilder.withPayload("test").copyHeaders(headers).build();
@@ -473,10 +476,10 @@ public class PayloadAndHeaderMappingTests {
@Test
public void twoMapsWithAnnotationsWithMapPayload() throws Exception {
MessageHandler handler = this.getHandler("twoMapsWithAnnotations", Map.class, Map.class);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Map<String, Object> payloadMap = new HashMap<String, Object>();
Map<String, Object> payloadMap = new HashMap<>();
payloadMap.put("baz", "99");
Message<?> message = MessageBuilder.withPayload(payloadMap).copyHeaders(headers).build();
handler.handleMessage(message);
@@ -487,33 +490,35 @@ public class PayloadAndHeaderMappingTests {
assertThat(bean.lastHeaders.get("baz")).isEqualTo(null);
}
@Test(expected = IllegalStateException.class)
public void twoStringsAmbiguousUsingMethodName() throws Exception {
SingleAmbiguousMethodTestBean bean = new SingleAmbiguousMethodTestBean();
new ServiceActivatingHandler(bean, "twoStrings");
@Test
public void twoStringsAmbiguousUsingMethodName() {
assertThatIllegalStateException()
.isThrownBy(() -> new ServiceActivatingHandler(new SingleAmbiguousMethodTestBean(), "twoStrings"));
}
@Test(expected = IllegalStateException.class)
public void twoStringsAmbiguousWithoutMethodName() throws Exception {
SingleAmbiguousMethodTestBean bean = new SingleAmbiguousMethodTestBean();
new ServiceActivatingHandler(bean);
@Test
public void twoStringsAmbiguousWithoutMethodName() {
assertThatIllegalStateException()
.isThrownBy(() -> new ServiceActivatingHandler(new SingleAmbiguousMethodTestBean()));
}
@Test(expected = IllegalArgumentException.class)
public void twoStringsNoAnnotations() throws Exception {
this.getHandler("twoStringsNoAnnotations", String.class, String.class);
@Test
public void twoStringsNoAnnotations() {
assertThatIllegalArgumentException()
.isThrownBy(() -> getHandler("twoStringsNoAnnotations", String.class, String.class));
}
@Test(expected = IllegalArgumentException.class)
public void twoMapsNoAnnotationsAndObject() throws Exception {
this.getHandler("twoMapsNoAnnotationsAndObject", Map.class, Object.class, Map.class);
@Test
public void twoMapsNoAnnotationsAndObject() {
assertThatIllegalArgumentException()
.isThrownBy(() -> getHandler("twoMapsNoAnnotationsAndObject", Map.class, Object.class, Map.class));
}
@Test
public void mapAndAnnotatedStringHeaderWithStringPayload() throws Exception {
MessageHandler handler = this.getHandler(
"mapAndAnnotatedStringHeaderExpectingMapAsHeaders", Map.class, String.class);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Message<?> message = MessageBuilder.withPayload("test")
@@ -529,9 +534,9 @@ public class PayloadAndHeaderMappingTests {
public void mapAndAnnotatedStringHeaderWithMapPayload() throws Exception {
MessageHandler handler = this.getHandler(
"mapAndAnnotatedStringHeaderExpectingMapAsPayload", Map.class, String.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("test", "0");
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Message<?> message = MessageBuilder.withPayload(payload)
@@ -546,7 +551,7 @@ public class PayloadAndHeaderMappingTests {
@Test
public void singleStringHeaderOnlyWithStringPayload() throws Exception {
MessageHandler handler = this.getHandler("singleStringHeaderOnly", String.class);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Message<?> message = MessageBuilder.withPayload("test")
@@ -560,10 +565,10 @@ public class PayloadAndHeaderMappingTests {
@Test
public void singleStringHeaderOnlyWithIntegerPayload() throws Exception {
MessageHandler handler = this.getHandler("singleStringHeaderOnly", String.class);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Message<?> message = MessageBuilder.withPayload(new Integer(123))
Message<?> message = MessageBuilder.withPayload(123)
.copyHeaders(headers).build();
handler.handleMessage(message);
assertThat(bean.lastPayload).isNull();
@@ -574,9 +579,9 @@ public class PayloadAndHeaderMappingTests {
@Test
public void singleStringHeaderOnlyWithMapPayload() throws Exception {
MessageHandler handler = this.getHandler("singleStringHeaderOnly", String.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("foo", 99);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "1");
headers.put("bar", "2");
Message<?> message = MessageBuilder.withPayload(payload)
@@ -590,49 +595,49 @@ public class PayloadAndHeaderMappingTests {
@Test
public void singleIntegerHeaderOnlyWithIntegerPayload() throws Exception {
MessageHandler handler = this.getHandler("singleIntegerHeaderOnly", Integer.class);
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("foo", new Integer(123));
headers.put("bar", new Integer(456));
Message<?> message = MessageBuilder.withPayload(new Integer(789))
Map<String, Object> headers = new HashMap<>();
headers.put("foo", 123);
headers.put("bar", 456);
Message<?> message = MessageBuilder.withPayload(789)
.copyHeaders(headers).build();
handler.handleMessage(message);
assertThat(bean.lastPayload).isNull();
assertThat(bean.lastHeaders.get("foo")).isEqualTo(new Integer(123));
assertThat(bean.lastHeaders.get("foo")).isEqualTo(123);
assertThat(bean.lastHeaders.get("bar")).isNull();
}
@Test
public void singleIntegerHeaderOnlyWithIntegerPayloadAndStringHeader() throws Exception {
MessageHandler handler = this.getHandler("singleIntegerHeaderOnly", Integer.class);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "999");
headers.put("bar", new Integer(456));
Message<?> message = MessageBuilder.withPayload(new Integer(789))
headers.put("bar", 456);
Message<?> message = MessageBuilder.withPayload(789)
.copyHeaders(headers).build();
handler.handleMessage(message);
assertThat(bean.lastPayload).isNull();
assertThat(bean.lastHeaders.get("foo")).isEqualTo(new Integer(999));
assertThat(bean.lastHeaders.get("foo")).isEqualTo(999);
assertThat(bean.lastHeaders.get("bar")).isNull();
}
@Test
public void singleIntegerHeaderOnlyWithStringPayload() throws Exception {
MessageHandler handler = this.getHandler("singleIntegerHeaderOnly", Integer.class);
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("foo", new Integer(123));
headers.put("bar", new Integer(456));
Map<String, Object> headers = new HashMap<>();
headers.put("foo", 123);
headers.put("bar", 456);
Message<?> message = MessageBuilder.withPayload("test")
.copyHeaders(headers).build();
handler.handleMessage(message);
assertThat(bean.lastPayload).isNull();
assertThat(bean.lastHeaders.get("foo")).isEqualTo(new Integer(123));
assertThat(bean.lastHeaders.get("foo")).isEqualTo(123);
assertThat(bean.lastHeaders.get("bar")).isNull();
}
@Test
public void singleObjectHeaderOnlyWithStringPayload() throws Exception {
MessageHandler handler = this.getHandler("singleObjectHeaderOnly", Object.class);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "123");
headers.put("bar", "456");
Message<?> message = MessageBuilder.withPayload("test")
@@ -646,7 +651,7 @@ public class PayloadAndHeaderMappingTests {
@Test
public void singleObjectHeaderOnlyWithObjectPayload() throws Exception {
MessageHandler handler = this.getHandler("singleObjectHeaderOnly", Object.class);
Map<String, Object> headers = new HashMap<String, Object>();
Map<String, Object> headers = new HashMap<>();
headers.put("foo", "123");
headers.put("bar", "456");
Message<?> message = MessageBuilder.withPayload(new Object())
@@ -660,37 +665,37 @@ public class PayloadAndHeaderMappingTests {
@Test
public void singleObjectHeaderOnlyWithIntegerPayload() throws Exception {
MessageHandler handler = this.getHandler("singleObjectHeaderOnly", Object.class);
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("foo", new Integer(123));
headers.put("bar", new Integer(456));
Message<?> message = MessageBuilder.withPayload(new Integer(789))
Map<String, Object> headers = new HashMap<>();
headers.put("foo", 123);
headers.put("bar", 456);
Message<?> message = MessageBuilder.withPayload(789)
.copyHeaders(headers).build();
handler.handleMessage(message);
assertThat(bean.lastPayload).isNull();
assertThat(bean.lastHeaders.get("foo")).isEqualTo(new Integer(123));
assertThat(bean.lastHeaders.get("foo")).isEqualTo(123);
assertThat(bean.lastHeaders.get("bar")).isNull();
}
@Test
public void singleObjectHeaderOnlyWithMapPayload() throws Exception {
MessageHandler handler = this.getHandler("singleObjectHeaderOnly", Object.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("foo", 99);
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("foo", new Integer(123));
headers.put("bar", new Integer(456));
Map<String, Object> headers = new HashMap<>();
headers.put("foo", 123);
headers.put("bar", 456);
Message<?> message = MessageBuilder.withPayload(payload)
.copyHeaders(headers).build();
handler.handleMessage(message);
assertThat(bean.lastPayload).isNull();
assertThat(bean.lastHeaders.get("foo")).isEqualTo(new Integer(123));
assertThat(bean.lastHeaders.get("foo")).isEqualTo(123);
assertThat(bean.lastHeaders.get("bar")).isNull();
}
@Test
public void twoPayloadExpressions() throws Exception {
MessageHandler handler = this.getHandler("twoPayloadExpressions", String.class, String.class);
Map<String, Object> payload = new HashMap<String, Object>();
Map<String, Object> payload = new HashMap<>();
payload.put("foo", 123);
payload.put("bar", 456);
Message<?> message = MessageBuilder.withPayload(payload).build();
@@ -720,6 +725,7 @@ public class PayloadAndHeaderMappingTests {
public String concat(String s1, String s2) {
return "s1" + "s2";
}
}
@SuppressWarnings("unused")
@@ -775,7 +781,9 @@ public class PayloadAndHeaderMappingTests {
this.lastPayload = payload;
}
public void payloadMapAndHeaderStrings(Map payload, @Header("foo") String header1, @Header("bar") String header2) {
public void payloadMapAndHeaderStrings(Map payload, @Header("foo") String header1,
@Header("bar") String header2) {
this.lastHeaders = new HashMap<String, String>();
this.lastHeaders.put("foo", header1);
this.lastHeaders.put("bar", header2);
@@ -797,7 +805,9 @@ public class PayloadAndHeaderMappingTests {
this.lastPayload = payload;
}
public void headerPropertiesPayloadMapAndStringHeader(@Headers Properties headers, Map payload, @Header("foo") String header) {
public void headerPropertiesPayloadMapAndStringHeader(@Headers Properties headers, Map payload,
@Header("foo") String header) {
this.lastHeaders = headers;
this.lastHeaders.put("foo2", header);
this.lastPayload = payload;
@@ -881,6 +891,7 @@ public class PayloadAndHeaderMappingTests {
public void twoPayloadExpressions(@Payload("foo") String foo, @Payload("bar") String bar) {
this.lastPayload = foo + bar;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -17,6 +17,7 @@
package org.springframework.integration.router.config;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -24,8 +25,7 @@ import static org.mockito.Mockito.verify;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,8 +46,7 @@ import org.springframework.messaging.SubscribableChannel;
import org.springframework.messaging.core.DestinationResolutionException;
import org.springframework.messaging.core.DestinationResolver;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Mark Fisher
@@ -55,8 +54,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Gunnar Hillert
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
public class RouterParserTests {
@Autowired
@@ -64,6 +62,7 @@ public class RouterParserTests {
@Autowired
private PollableChannel output2;
@Autowired
private MessageChannel input;
@@ -121,11 +120,11 @@ public class RouterParserTests {
@Test
public void testRouter() {
this.input.send(new GenericMessage<String>("1"));
this.input.send(new GenericMessage<>("1"));
Message<?> result1 = this.output1.receive(1000);
assertThat(result1.getPayload()).isEqualTo("1");
assertThat(output2.receive(0)).isNull();
input.send(new GenericMessage<String>("2"));
input.send(new GenericMessage<>("2"));
Message<?> result2 = this.output2.receive(1000);
assertThat(result2.getPayload()).isEqualTo("2");
assertThat(output1.receive(0)).isNull();
@@ -133,7 +132,7 @@ public class RouterParserTests {
@Test
public void testRouterWithDefaultOutputChannel() {
this.inputForRouterWithDefaultOutput.send(new GenericMessage<String>("99"));
this.inputForRouterWithDefaultOutput.send(new GenericMessage<>("99"));
assertThat(this.output1.receive(0)).isNull();
assertThat(this.output2.receive(0)).isNull();
Message<?> result = this.defaultOutput.receive(0);
@@ -142,7 +141,7 @@ public class RouterParserTests {
@Test
public void refOnlyForAbstractMessageRouterImplementation() {
this.inputForAbstractMessageRouterImplementation.send(new GenericMessage<String>("test-implementation"));
this.inputForAbstractMessageRouterImplementation.send(new GenericMessage<>("test-implementation"));
Message<?> result = this.output3.receive(1000);
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo("test-implementation");
@@ -150,7 +149,7 @@ public class RouterParserTests {
@Test
public void refOnlyForAnnotatedObject() {
this.inputForAnnotatedRouter.send(new GenericMessage<String>("test-annotation"));
this.inputForAnnotatedRouter.send(new GenericMessage<>("test-annotation"));
Message<?> result = this.output4.receive(1000);
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo("test-annotation");
@@ -158,30 +157,30 @@ public class RouterParserTests {
@Test
public void testResolutionRequired() {
try {
this.inputForRouterRequiringResolution.send(new GenericMessage<Integer>(3));
}
catch (Exception e) {
assertThat(e.getCause() instanceof DestinationResolutionException).isTrue();
}
assertThatExceptionOfType(Exception.class)
.isThrownBy(() -> this.inputForRouterRequiringResolution.send(new GenericMessage<>(3)))
.withCauseInstanceOf(DestinationResolutionException.class);
}
@Test(expected = MessageDeliveryException.class)
@Test
public void testResolutionRequiredIsFalse() {
this.resolutionRequiredIsFalseInput.send(new GenericMessage<String>("channelThatDoesNotExist"));
assertThatExceptionOfType(MessageDeliveryException.class)
.isThrownBy(() ->
this.resolutionRequiredIsFalseInput.send(new GenericMessage<>("channelThatDoesNotExist")));
}
@Test
public void timeoutValueConfigured() {
assertThat(this.routerWithTimeout instanceof MethodInvokingRouter).isTrue();
MessagingTemplate template = TestUtils.getPropertyValue(this.routerWithTimeout, "messagingTemplate", MessagingTemplate.class);
MessagingTemplate template =
TestUtils.getPropertyValue(this.routerWithTimeout, "messagingTemplate", MessagingTemplate.class);
Long timeout = TestUtils.getPropertyValue(template, "sendTimeout", Long.class);
assertThat(timeout).isEqualTo(new Long(1234));
assertThat(timeout).isEqualTo(1234L);
}
@Test
public void sequence() {
Message<?> originalMessage = new GenericMessage<String>("test");
Message<?> originalMessage = new GenericMessage<>("test");
this.sequenceRouter.send(originalMessage);
Message<?> message1 = this.sequenceOut1.receive(1000);
Message<?> message2 = this.sequenceOut2.receive(1000);
@@ -202,11 +201,11 @@ public class RouterParserTests {
@Test
public void testInt2893RouterNestedBean() {
this.routerNestedBeanChannel.send(new GenericMessage<String>("1"));
this.routerNestedBeanChannel.send(new GenericMessage<>("1"));
Message<?> result1 = this.output1.receive(1000);
assertThat(result1.getPayload()).isEqualTo("1");
assertThat(this.output2.receive(0)).isNull();
this.routerNestedBeanChannel.send(new GenericMessage<String>("2"));
this.routerNestedBeanChannel.send(new GenericMessage<>("2"));
Message<?> result2 = this.output2.receive(1000);
assertThat(result2.getPayload()).isEqualTo("2");
assertThat(this.output1.receive(0)).isNull();
@@ -214,11 +213,11 @@ public class RouterParserTests {
@Test
public void testInt2893RouterNestedBeanWithinChain() {
this.chainRouterNestedBeanChannel.send(new GenericMessage<String>("1"));
this.chainRouterNestedBeanChannel.send(new GenericMessage<>("1"));
Message<?> result1 = this.output1.receive(1000);
assertThat(result1.getPayload()).isEqualTo("1");
assertThat(this.output2.receive(0)).isNull();
this.chainRouterNestedBeanChannel.send(new GenericMessage<String>("2"));
this.chainRouterNestedBeanChannel.send(new GenericMessage<>("2"));
Message<?> result2 = this.output2.receive(1000);
assertThat(result2.getPayload()).isEqualTo("2");
assertThat(this.output1.receive(0)).isNull();
@@ -228,7 +227,7 @@ public class RouterParserTests {
public void testErrorChannel() {
MessageHandler handler = mock(MessageHandler.class);
this.errorChannel.subscribe(handler);
this.routerAndErrorChannelInputChannel.send(new GenericMessage<String>("fail"));
this.routerAndErrorChannelInputChannel.send(new GenericMessage<>("fail"));
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
@@ -239,9 +238,11 @@ public class RouterParserTests {
public static class NonExistingChannelRouter {
public String route(String payload) {
return "foo";
}
}
public static class TestRouterImplementation extends AbstractMappingMessageRouter {
@@ -257,6 +258,7 @@ public class RouterParserTests {
protected List<Object> getChannelKeys(Message<?> message) {
return Collections.singletonList((Object) this.channel);
}
}
@@ -272,6 +274,7 @@ public class RouterParserTests {
public MessageChannel test(String payload) {
return this.channel;
}
}
public static class ReturnStringPassedInAsChannelNameRouter {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@@ -23,8 +23,7 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.IntegrationMessageHeaderAccessor;
@@ -33,16 +32,14 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Mark Fisher
* @author Artem Bilan
* @author Gary Russell
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
public class SpelSplitterIntegrationTests {
@Autowired
@@ -83,13 +80,13 @@ public class SpelSplitterIntegrationTests {
Message<?> two = output.receive(0);
Message<?> three = output.receive(0);
Message<?> four = output.receive(0);
assertThat(one.getPayload()).isEqualTo(new Integer(1));
assertThat(one.getPayload()).isEqualTo(1);
assertThat(one.getHeaders().get("foo")).isEqualTo("foo");
assertThat(two.getPayload()).isEqualTo(new Integer(2));
assertThat(two.getPayload()).isEqualTo(2);
assertThat(two.getHeaders().get("foo")).isEqualTo("foo");
assertThat(three.getPayload()).isEqualTo(new Integer(3));
assertThat(three.getPayload()).isEqualTo(3);
assertThat(three.getHeaders().get("foo")).isEqualTo("foo");
assertThat(four.getPayload()).isEqualTo(new Integer(4));
assertThat(four.getPayload()).isEqualTo(4);
assertThat(four.getHeaders().get("foo")).isEqualTo("foo");
assertThat(output.receive(0)).isNull();
}
@@ -111,7 +108,7 @@ public class SpelSplitterIntegrationTests {
@Test
public void iteratorSplitter() {
this.iteratorInput.send(new GenericMessage<String>("a,b,c,d"));
this.iteratorInput.send(new GenericMessage<>("a,b,c,d"));
Message<?> a = output.receive(0);
Message<?> b = output.receive(0);
Message<?> c = output.receive(0);
@@ -133,7 +130,7 @@ public class SpelSplitterIntegrationTests {
@Test
public void spelIteratorSplitter() {
this.spelIteratorInput.send(new GenericMessage<String>("a,b,c,d"));
this.spelIteratorInput.send(new GenericMessage<>("a,b,c,d"));
Message<?> a = output.receive(0);
Message<?> b = output.receive(0);
Message<?> c = output.receive(0);

View File

@@ -154,8 +154,8 @@ class KotlinDslTests {
val verifyLater =
StepVerifier
.create(Flux.from(fluxChannel).map { it.payload }.cast(Integer::class.java))
.expectNext(Integer(4), Integer(6))
.create(Flux.from(fluxChannel).map { it.payload }.map { it.toString().toInt() })
.expectNext(4, 6)
.thenCancel()
.verifyLater()