Upgrade dependencies and various fixes
* Remove usage of removed `org.springframework.util.SocketUtils` in favor of OS-selected port * Migrate mail tests to Greenmail instead of already obsolete (and soon to be removed) `org.springframework.integration.test.mail.TestMailServer`
This commit is contained in:
@@ -126,14 +126,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -126,14 +126,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -126,14 +126,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -126,14 +126,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -143,14 +143,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -1,236 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.samples.mailattachments;
|
||||
|
||||
import org.springframework.integration.samples.mailattachments.support.EmailFragment;
|
||||
|
||||
/**
|
||||
* Test to verify the correct parsing of Email Messages.
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
public class MimeMessageParsingTest {
|
||||
|
||||
/*
|
||||
private static final Log LOGGER = LogFactory.getLog(MimeMessageParsingTest.class);
|
||||
|
||||
private Wiser wiser;
|
||||
|
||||
private int wiserPort;
|
||||
|
||||
@Before
|
||||
public void startWiser() {
|
||||
|
||||
this.wiserPort = SocketUtils.findAvailableTcpPort(2500);
|
||||
|
||||
wiser = new Wiser();
|
||||
wiser.setPort(this.wiserPort);
|
||||
wiser.start();
|
||||
LOGGER.info("Wiser was started.");
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* This test will create a Mime Message that contains an Attachment, send it
|
||||
* to an SMTP Server (Using Wiser) and retrieve and process the Mime Message.
|
||||
*
|
||||
* This test verifies that the parsing of the retrieved Mime Message is
|
||||
* successful and that the correct number of {@link EmailFragment}s is created.
|
||||
*//*
|
||||
|
||||
@Test
|
||||
public void testProcessingOfEmailAttachments() {
|
||||
|
||||
final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||
mailSender.setPort(this.wiserPort);
|
||||
|
||||
final MimeMessage message = mailSender.createMimeMessage();
|
||||
final String pictureName = "picture.png";
|
||||
|
||||
final ByteArrayResource byteArrayResource = getFileData(pictureName);
|
||||
|
||||
try {
|
||||
|
||||
final MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
||||
|
||||
helper.setFrom("testfrom@springintegration.org");
|
||||
helper.setTo("testto@springintegration.org");
|
||||
helper.setSubject("Parsing of Attachments");
|
||||
helper.setText("Spring Integration Rocks!");
|
||||
|
||||
helper.addAttachment(pictureName, byteArrayResource, "image/png");
|
||||
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
throw new MailParseException(e);
|
||||
}
|
||||
|
||||
mailSender.send(message);
|
||||
|
||||
final List<WiserMessage> wiserMessages = wiser.getMessages();
|
||||
|
||||
Assert.assertTrue(wiserMessages.size() == 1);
|
||||
|
||||
boolean foundTextMessage = false;
|
||||
boolean foundPicture = false;
|
||||
|
||||
for (WiserMessage wiserMessage : wiserMessages) {
|
||||
|
||||
final List<EmailFragment> emailFragments = new ArrayList<>();
|
||||
|
||||
try {
|
||||
final MimeMessage mailMessage = wiserMessage.getMimeMessage();
|
||||
EmailParserUtils.handleMessage(null, mailMessage, emailFragments);
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
throw new IllegalStateException("Error while retrieving Mime Message.");
|
||||
}
|
||||
|
||||
Assert.assertTrue(emailFragments.size() == 2);
|
||||
|
||||
for (EmailFragment emailFragment : emailFragments) {
|
||||
if ("picture.png".equals(emailFragment.getFilename())) {
|
||||
foundPicture = true;
|
||||
}
|
||||
|
||||
if ("message.txt".equals(emailFragment.getFilename())) {
|
||||
foundTextMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertTrue(foundPicture);
|
||||
Assert.assertTrue(foundTextMessage);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
/**
|
||||
* This test will create a Mime Message that in return contains another
|
||||
* mime message. The nested mime message contains an attachment.
|
||||
*
|
||||
* The root message consist of both HTML and Text message.
|
||||
*
|
||||
*//*
|
||||
|
||||
@Test
|
||||
public void testProcessingOfNestedEmailAttachments() {
|
||||
|
||||
final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
||||
mailSender.setPort(this.wiserPort);
|
||||
|
||||
final MimeMessage rootMessage = mailSender.createMimeMessage();
|
||||
|
||||
try {
|
||||
|
||||
final MimeMessageHelper messageHelper = new MimeMessageHelper(rootMessage, true);
|
||||
|
||||
messageHelper.setFrom("testfrom@springintegration.org");
|
||||
messageHelper.setTo("testto@springintegration.org");
|
||||
messageHelper.setSubject("Parsing of Attachments");
|
||||
messageHelper.setText("Spring Integration Rocks!", "Spring Integration <b>Rocks</b>!");
|
||||
|
||||
final String pictureName = "picture.png";
|
||||
|
||||
final ByteArrayResource byteArrayResource = getFileData(pictureName);
|
||||
|
||||
messageHelper.addInline("picture12345", byteArrayResource, "image/png");
|
||||
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
throw new MailParseException(e);
|
||||
}
|
||||
|
||||
mailSender.send(rootMessage);
|
||||
|
||||
final List<WiserMessage> wiserMessages = wiser.getMessages();
|
||||
|
||||
Assert.assertTrue(wiserMessages.size() == 1);
|
||||
|
||||
boolean foundTextMessage = false;
|
||||
boolean foundPicture = false;
|
||||
boolean foundHtmlMessage = false;
|
||||
|
||||
for (WiserMessage wiserMessage : wiserMessages) {
|
||||
|
||||
List<EmailFragment> emailFragments = new ArrayList<>();
|
||||
|
||||
try {
|
||||
|
||||
final MimeMessage mailMessage = wiserMessage.getMimeMessage();
|
||||
EmailParserUtils.handleMessage(null, mailMessage, emailFragments);
|
||||
|
||||
} catch (MessagingException e) {
|
||||
throw new IllegalStateException("Error while retrieving Mime Message.");
|
||||
}
|
||||
|
||||
Assert.assertTrue(emailFragments.size() == 3);
|
||||
|
||||
for (EmailFragment emailFragment : emailFragments) {
|
||||
if ("<picture12345>".equals(emailFragment.getFilename())) {
|
||||
foundPicture = true;
|
||||
}
|
||||
|
||||
if ("message.txt".equals(emailFragment.getFilename())) {
|
||||
foundTextMessage = true;
|
||||
}
|
||||
|
||||
if ("message.html".equals(emailFragment.getFilename())) {
|
||||
foundHtmlMessage = true;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertTrue(foundPicture);
|
||||
Assert.assertTrue(foundTextMessage);
|
||||
Assert.assertTrue(foundHtmlMessage);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private ByteArrayResource getFileData(String filename) {
|
||||
|
||||
final InputStream attachmentInputStream = MimeMessageParsingTest.class.getResourceAsStream(filename);
|
||||
|
||||
Assert.assertNotNull("Resource not found: " + filename, attachmentInputStream);
|
||||
|
||||
ByteArrayResource byteArrayResource = null;
|
||||
|
||||
try {
|
||||
byteArrayResource = new ByteArrayResource(IOUtils.toByteArray(attachmentInputStream));
|
||||
attachmentInputStream.close();
|
||||
}
|
||||
catch (IOException e1) {
|
||||
Assert.fail();
|
||||
}
|
||||
|
||||
return byteArrayResource;
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void stopWiser() {
|
||||
wiser.stop();
|
||||
LOGGER.info("Wiser stopped.");
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -180,14 +180,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -180,14 +180,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -95,13 +95,13 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -211,14 +211,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -159,14 +159,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -126,14 +126,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -132,14 +132,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -138,14 +138,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -132,14 +132,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -144,14 +144,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -138,14 +138,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
* Copyright 2020-2022 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,11 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.ChannelInterceptor;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
@SpringBootTest
|
||||
@SpringIntegrationTest(noAutoStartup = { "client1Adapter", "client2Adapter" })
|
||||
@DirtiesContext
|
||||
class TcpAsyncBiDirectionalApplicationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -126,14 +126,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<ip:tcp-connection-factory id="client"
|
||||
type="client"
|
||||
host="localhost"
|
||||
port="${availableServerSocket}"
|
||||
port="#{server.port}"
|
||||
single-use="false"
|
||||
serializer="fastestWireFormatSerializer"
|
||||
deserializer="fastestWireFormatSerializer"
|
||||
@@ -47,6 +47,7 @@
|
||||
<ip:tcp-outbound-channel-adapter id="outAdapter.client"
|
||||
order="2"
|
||||
channel="input"
|
||||
auto-startup="false"
|
||||
connection-factory="client" /> <!-- Collaborator -->
|
||||
|
||||
<!-- Also send a copy to the custom aggregator for correlation and
|
||||
@@ -56,9 +57,10 @@
|
||||
<bridge input-channel="input" output-channel="toAggregator.client"
|
||||
order="1"/>
|
||||
|
||||
<!-- Asynch receive reply -->
|
||||
<!-- Async receive reply -->
|
||||
<ip:tcp-inbound-channel-adapter id="inAdapter.client"
|
||||
channel="toAggregator.client"
|
||||
auto-startup="false"
|
||||
connection-factory="client" /> <!-- Collaborator -->
|
||||
|
||||
<!-- dataType attribute invokes the conversion service, if necessary -->
|
||||
@@ -84,7 +86,7 @@
|
||||
|
||||
<ip:tcp-connection-factory id="server"
|
||||
type="server"
|
||||
port="${availableServerSocket}"
|
||||
port="0"
|
||||
using-nio="true"
|
||||
serializer="fastestWireFormatSerializer"
|
||||
deserializer="fastestWireFormatSerializer" />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2022 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,31 +16,28 @@
|
||||
|
||||
package org.springframework.integration.samples.tcpclientserver;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
|
||||
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
|
||||
import org.springframework.integration.ip.util.TestingUtilities;
|
||||
import org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
|
||||
/**
|
||||
@@ -56,9 +53,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @since 2.1
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration(loader = CustomTestContextLoader.class,
|
||||
locations = { "/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml" })
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig(locations = "/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml")
|
||||
@DirtiesContext
|
||||
public class TcpClientServerDemoTest {
|
||||
|
||||
@@ -68,15 +63,31 @@ public class TcpClientServerDemoTest {
|
||||
@Autowired
|
||||
AbstractServerConnectionFactory crLfServer;
|
||||
|
||||
@Before
|
||||
@Autowired
|
||||
AbstractClientConnectionFactory client;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("outAdapter.client")
|
||||
AbstractEndpoint outAdapterClient;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("inAdapter.client")
|
||||
AbstractEndpoint inAdapterClient;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
TestingUtilities.waitListening(this.crLfServer, 10000L);
|
||||
if (!this.outAdapterClient.isRunning()) {
|
||||
TestingUtilities.waitListening(this.crLfServer, 10000L);
|
||||
this.client.setPort(this.crLfServer.getPort());
|
||||
this.outAdapterClient.start();
|
||||
this.inAdapterClient.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHappyDay() {
|
||||
String result = gw.send("999Hello world!"); // first 3 bytes is correlationid
|
||||
assertEquals("999Hello world!:echo", result);
|
||||
assertThat(result).isEqualTo("999Hello world!:echo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,36 +99,28 @@ public class TcpClientServerDemoTest {
|
||||
results.add(i);
|
||||
final int j = i;
|
||||
executor.execute(() -> {
|
||||
String result = gw.send(j + "Hello world!"); // first 3 bytes is correlationid
|
||||
assertEquals(j + "Hello world!:echo", result);
|
||||
String result = gw.send(j + "Hello world!"); // first 3 bytes is correlationId
|
||||
assertThat(result).isEqualTo(j + "Hello world!:echo");
|
||||
results.remove(j);
|
||||
latch.countDown();
|
||||
});
|
||||
}
|
||||
assertTrue(latch.await(60, TimeUnit.SECONDS));
|
||||
assertEquals(0, results.size());
|
||||
assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
|
||||
assertThat(results).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeoutThrow() {
|
||||
try {
|
||||
gw.send("TIMEOUT_TEST_THROW");
|
||||
fail("expected exception");
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
assertThat(e.getMessage(), containsString("No response received for TIMEOUT_TEST"));
|
||||
}
|
||||
assertThatExceptionOfType(MessagingException.class)
|
||||
.isThrownBy(() -> gw.send("TIMEOUT_TEST_THROW"))
|
||||
.withMessageContaining("No response received for TIMEOUT_TEST");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeoutReturn() {
|
||||
try {
|
||||
gw.send("TIMEOUT_TEST_RETURN");
|
||||
fail("expected exception");
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
assertThat(e.getMessage(), containsString("No response received for TIMEOUT_TEST"));
|
||||
}
|
||||
assertThatExceptionOfType(MessagingException.class)
|
||||
.isThrownBy(() -> gw.send("TIMEOUT_TEST_RETURN"))
|
||||
.withMessageContaining("No response received for TIMEOUT_TEST");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.samples.tcpclientserver.support;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.util.SocketUtils;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
import org.springframework.test.context.support.GenericXmlContextLoader;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
*/
|
||||
public class CustomTestContextLoader extends GenericXmlContextLoader {
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(CustomTestContextLoader.class);
|
||||
|
||||
@Override
|
||||
protected void loadBeanDefinitions(GenericApplicationContext context,
|
||||
MergedContextConfiguration mergedConfig) {
|
||||
|
||||
int availableServerSocket = SocketUtils.findAvailableTcpPort(5678);
|
||||
|
||||
final Map<String, Object> sockets = new HashMap<String, Object>();
|
||||
sockets.put("availableServerSocket", availableServerSocket);
|
||||
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info("Available Server Socket: " + availableServerSocket);
|
||||
}
|
||||
|
||||
final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);
|
||||
|
||||
context.getEnvironment().getPropertySources().addLast(propertySource);
|
||||
super.loadBeanDefinitions(context, mergedConfig);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -172,14 +172,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -136,14 +136,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@@ -137,14 +137,14 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>6.0.0-M2</version>
|
||||
<version>6.0.0-M3</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.integration</groupId>
|
||||
<artifactId>spring-integration-bom</artifactId>
|
||||
<version>6.0.0-M1</version>
|
||||
<version>6.0.0-M2</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
Reference in New Issue
Block a user