Migrate ReturnAddressTests to JUnit 5
Looks like `ApplicaitonContext.stop()` is note called on `close()`. This might cause an `OutOfMemoryError` on the CI * Use Spring context configuration for the test environment
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
package org.springframework.integration.endpoint;
|
package org.springframework.integration.endpoint;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.integration.support.MessageBuilder;
|
import org.springframework.integration.support.MessageBuilder;
|
||||||
import org.springframework.messaging.Message;
|
import org.springframework.messaging.Message;
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
@@ -26,54 +27,52 @@ import org.springframework.messaging.MessagingException;
|
|||||||
import org.springframework.messaging.PollableChannel;
|
import org.springframework.messaging.PollableChannel;
|
||||||
import org.springframework.messaging.core.DestinationResolutionException;
|
import org.springframework.messaging.core.DestinationResolutionException;
|
||||||
import org.springframework.messaging.support.GenericMessage;
|
import org.springframework.messaging.support.GenericMessage;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
|
* @author Artem Bilan
|
||||||
*/
|
*/
|
||||||
|
@SpringJUnitConfig
|
||||||
|
@DirtiesContext
|
||||||
public class ReturnAddressTests {
|
public class ReturnAddressTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ApplicationContext context;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returnAddressFallbackWithChannelReference() {
|
public void returnAddressFallbackWithChannelReference() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
|
||||||
"returnAddressTests.xml", this.getClass());
|
|
||||||
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
||||||
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
|
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
|
||||||
context.start();
|
|
||||||
Message<String> message = MessageBuilder.withPayload("*")
|
Message<String> message = MessageBuilder.withPayload("*")
|
||||||
.setReplyChannel(channel5).build();
|
.setReplyChannel(channel5).build();
|
||||||
channel3.send(message);
|
channel3.send(message);
|
||||||
Message<?> response = channel5.receive(3000);
|
Message<?> response = channel5.receive(3000);
|
||||||
assertThat(response).isNotNull();
|
assertThat(response).isNotNull();
|
||||||
assertThat(response.getPayload()).isEqualTo("**");
|
assertThat(response.getPayload()).isEqualTo("**");
|
||||||
context.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returnAddressFallbackWithChannelName() {
|
public void returnAddressFallbackWithChannelName() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
|
||||||
"returnAddressTests.xml", this.getClass());
|
|
||||||
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
||||||
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
|
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
|
||||||
context.start();
|
|
||||||
Message<String> message = MessageBuilder.withPayload("*")
|
Message<String> message = MessageBuilder.withPayload("*")
|
||||||
.setReplyChannelName("channel5").build();
|
.setReplyChannelName("channel5").build();
|
||||||
channel3.send(message);
|
channel3.send(message);
|
||||||
Message<?> response = channel5.receive(3000);
|
Message<?> response = channel5.receive(3000);
|
||||||
assertThat(response).isNotNull();
|
assertThat(response).isNotNull();
|
||||||
assertThat(response.getPayload()).isEqualTo("**");
|
assertThat(response.getPayload()).isEqualTo("**");
|
||||||
context.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returnAddressWithChannelReferenceAfterMultipleEndpoints() {
|
public void returnAddressWithChannelReferenceAfterMultipleEndpoints() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
|
||||||
"returnAddressTests.xml", this.getClass());
|
|
||||||
MessageChannel channel1 = (MessageChannel) context.getBean("channel1");
|
MessageChannel channel1 = (MessageChannel) context.getBean("channel1");
|
||||||
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
||||||
context.start();
|
|
||||||
Message<String> message = MessageBuilder.withPayload("*")
|
Message<String> message = MessageBuilder.withPayload("*")
|
||||||
.setReplyChannel(replyChannel).build();
|
.setReplyChannel(replyChannel).build();
|
||||||
channel1.send(message);
|
channel1.send(message);
|
||||||
@@ -82,16 +81,12 @@ public class ReturnAddressTests {
|
|||||||
assertThat(response.getPayload()).isEqualTo("********");
|
assertThat(response.getPayload()).isEqualTo("********");
|
||||||
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
|
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
|
||||||
assertThat(channel2.receive(0)).isNull();
|
assertThat(channel2.receive(0)).isNull();
|
||||||
context.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returnAddressWithChannelNameAfterMultipleEndpoints() {
|
public void returnAddressWithChannelNameAfterMultipleEndpoints() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
|
||||||
"returnAddressTests.xml", this.getClass());
|
|
||||||
MessageChannel channel1 = (MessageChannel) context.getBean("channel1");
|
MessageChannel channel1 = (MessageChannel) context.getBean("channel1");
|
||||||
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
||||||
context.start();
|
|
||||||
Message<String> message = MessageBuilder.withPayload("*")
|
Message<String> message = MessageBuilder.withPayload("*")
|
||||||
.setReplyChannelName("replyChannel").build();
|
.setReplyChannelName("replyChannel").build();
|
||||||
channel1.send(message);
|
channel1.send(message);
|
||||||
@@ -100,47 +95,32 @@ public class ReturnAddressTests {
|
|||||||
assertThat(response.getPayload()).isEqualTo("********");
|
assertThat(response.getPayload()).isEqualTo("********");
|
||||||
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
|
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
|
||||||
assertThat(channel2.receive(0)).isNull();
|
assertThat(channel2.receive(0)).isNull();
|
||||||
context.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void returnAddressFallbackButNotAvailable() {
|
public void returnAddressFallbackButNotAvailable() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
|
||||||
"returnAddressTests.xml", this.getClass());
|
|
||||||
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
||||||
context.start();
|
GenericMessage<String> message = new GenericMessage<>("*");
|
||||||
GenericMessage<String> message = new GenericMessage<String>("*");
|
assertThatExceptionOfType(MessagingException.class)
|
||||||
try {
|
.isThrownBy(() -> channel3.send(message))
|
||||||
channel3.send(message);
|
.withCauseInstanceOf(DestinationResolutionException.class);
|
||||||
}
|
|
||||||
catch (MessagingException e) {
|
|
||||||
assertThat(e.getCause() instanceof DestinationResolutionException).isTrue();
|
|
||||||
}
|
|
||||||
context.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outputChannelWithNoReturnAddress() {
|
public void outputChannelWithNoReturnAddress() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
|
||||||
"returnAddressTests.xml", this.getClass());
|
|
||||||
MessageChannel channel4 = (MessageChannel) context.getBean("channel4");
|
MessageChannel channel4 = (MessageChannel) context.getBean("channel4");
|
||||||
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
||||||
context.start();
|
GenericMessage<String> message = new GenericMessage<>("*");
|
||||||
GenericMessage<String> message = new GenericMessage<String>("*");
|
|
||||||
channel4.send(message);
|
channel4.send(message);
|
||||||
Message<?> response = replyChannel.receive(3000);
|
Message<?> response = replyChannel.receive(3000);
|
||||||
assertThat(response).isNotNull();
|
assertThat(response).isNotNull();
|
||||||
assertThat(response.getPayload()).isEqualTo("**");
|
assertThat(response.getPayload()).isEqualTo("**");
|
||||||
context.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void outputChannelTakesPrecedence() {
|
public void outputChannelTakesPrecedence() {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
|
||||||
"returnAddressTests.xml", this.getClass());
|
|
||||||
MessageChannel channel4 = (MessageChannel) context.getBean("channel4");
|
MessageChannel channel4 = (MessageChannel) context.getBean("channel4");
|
||||||
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
||||||
context.start();
|
|
||||||
Message<String> message = MessageBuilder.withPayload("*")
|
Message<String> message = MessageBuilder.withPayload("*")
|
||||||
.setReplyChannelName("channel5").build();
|
.setReplyChannelName("channel5").build();
|
||||||
channel4.send(message);
|
channel4.send(message);
|
||||||
@@ -149,7 +129,6 @@ public class ReturnAddressTests {
|
|||||||
assertThat(response.getPayload()).isEqualTo("**");
|
assertThat(response.getPayload()).isEqualTo("**");
|
||||||
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
|
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
|
||||||
assertThat(channel5.receive(0)).isNull();
|
assertThat(channel5.receive(0)).isNull();
|
||||||
context.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user