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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,9 +16,10 @@
|
||||
|
||||
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.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -26,54 +27,52 @@ import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.core.DestinationResolutionException;
|
||||
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.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class ReturnAddressTests {
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void returnAddressFallbackWithChannelReference() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"returnAddressTests.xml", this.getClass());
|
||||
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
||||
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
|
||||
context.start();
|
||||
Message<String> message = MessageBuilder.withPayload("*")
|
||||
.setReplyChannel(channel5).build();
|
||||
channel3.send(message);
|
||||
Message<?> response = channel5.receive(3000);
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getPayload()).isEqualTo("**");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnAddressFallbackWithChannelName() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"returnAddressTests.xml", this.getClass());
|
||||
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
||||
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
|
||||
context.start();
|
||||
Message<String> message = MessageBuilder.withPayload("*")
|
||||
.setReplyChannelName("channel5").build();
|
||||
channel3.send(message);
|
||||
Message<?> response = channel5.receive(3000);
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getPayload()).isEqualTo("**");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnAddressWithChannelReferenceAfterMultipleEndpoints() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"returnAddressTests.xml", this.getClass());
|
||||
MessageChannel channel1 = (MessageChannel) context.getBean("channel1");
|
||||
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
||||
context.start();
|
||||
Message<String> message = MessageBuilder.withPayload("*")
|
||||
.setReplyChannel(replyChannel).build();
|
||||
channel1.send(message);
|
||||
@@ -82,16 +81,12 @@ public class ReturnAddressTests {
|
||||
assertThat(response.getPayload()).isEqualTo("********");
|
||||
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
|
||||
assertThat(channel2.receive(0)).isNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnAddressWithChannelNameAfterMultipleEndpoints() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"returnAddressTests.xml", this.getClass());
|
||||
MessageChannel channel1 = (MessageChannel) context.getBean("channel1");
|
||||
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
||||
context.start();
|
||||
Message<String> message = MessageBuilder.withPayload("*")
|
||||
.setReplyChannelName("replyChannel").build();
|
||||
channel1.send(message);
|
||||
@@ -100,47 +95,32 @@ public class ReturnAddressTests {
|
||||
assertThat(response.getPayload()).isEqualTo("********");
|
||||
PollableChannel channel2 = (PollableChannel) context.getBean("channel2");
|
||||
assertThat(channel2.receive(0)).isNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void returnAddressFallbackButNotAvailable() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"returnAddressTests.xml", this.getClass());
|
||||
MessageChannel channel3 = (MessageChannel) context.getBean("channel3");
|
||||
context.start();
|
||||
GenericMessage<String> message = new GenericMessage<String>("*");
|
||||
try {
|
||||
channel3.send(message);
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
assertThat(e.getCause() instanceof DestinationResolutionException).isTrue();
|
||||
}
|
||||
context.close();
|
||||
GenericMessage<String> message = new GenericMessage<>("*");
|
||||
assertThatExceptionOfType(MessagingException.class)
|
||||
.isThrownBy(() -> channel3.send(message))
|
||||
.withCauseInstanceOf(DestinationResolutionException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputChannelWithNoReturnAddress() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"returnAddressTests.xml", this.getClass());
|
||||
MessageChannel channel4 = (MessageChannel) context.getBean("channel4");
|
||||
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
||||
context.start();
|
||||
GenericMessage<String> message = new GenericMessage<String>("*");
|
||||
GenericMessage<String> message = new GenericMessage<>("*");
|
||||
channel4.send(message);
|
||||
Message<?> response = replyChannel.receive(3000);
|
||||
assertThat(response).isNotNull();
|
||||
assertThat(response.getPayload()).isEqualTo("**");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputChannelTakesPrecedence() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"returnAddressTests.xml", this.getClass());
|
||||
MessageChannel channel4 = (MessageChannel) context.getBean("channel4");
|
||||
PollableChannel replyChannel = (PollableChannel) context.getBean("replyChannel");
|
||||
context.start();
|
||||
Message<String> message = MessageBuilder.withPayload("*")
|
||||
.setReplyChannelName("channel5").build();
|
||||
channel4.send(message);
|
||||
@@ -149,7 +129,6 @@ public class ReturnAddressTests {
|
||||
assertThat(response.getPayload()).isEqualTo("**");
|
||||
PollableChannel channel5 = (PollableChannel) context.getBean("channel5");
|
||||
assertThat(channel5.receive(0)).isNull();
|
||||
context.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user