GH-3492: Add ImapIdleChAdapterSpec.simpleContent

Fixes https://github.com/spring-projects/spring-integration/issues/3492

The `simpleContent` option is missed on the `ImapIdleChannelAdapterSpec`

* Add `ImapIdleChannelAdapterSpec.simpleContent(boolean)` option with
delegation to its internal `ImapMailReceiver`
* Convert all the `mail` tests to JUnit 5
This commit is contained in:
Artem Bilan
2021-02-10 11:26:24 -05:00
parent 43f90c4604
commit b4290dd2a5
20 changed files with 197 additions and 200 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2020 the original author or authors.
* Copyright 2014-2021 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.
@@ -383,6 +383,19 @@ public class ImapIdleChannelAdapterSpec
return this;
}
/**
* Determine how the content is rendered.
* @param simpleContent true for simple content.
* @return the spec.
* @see ImapMailReceiver#setSimpleContent(boolean)
* @since 5.5
*/
public ImapIdleChannelAdapterSpec simpleContent(boolean simpleContent) {
assertReceiver();
this.receiver.setSimpleContent(simpleContent);
return _this();
}
@Override
public Map<Object, String> getComponentsToRegister() {
return this.componentsToRegister;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ import javax.mail.search.FlagTerm;
import javax.mail.search.NotTerm;
import javax.mail.search.SearchTerm;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.util.ReflectionUtils;
@@ -40,6 +40,7 @@ import org.springframework.util.ReflectionUtils;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*
*/
public class ImapMailSearchTermsTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2021 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.
@@ -28,17 +28,18 @@ import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.URLName;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 3.0.6
*
*/
@@ -49,9 +50,10 @@ public class MailReceiverTests {
AbstractMailReceiver receiver = new AbstractMailReceiver() {
@Override
protected Message[] searchForNewMessages() throws MessagingException {
protected Message[] searchForNewMessages() {
return null;
}
};
Properties props = new Properties();
Session session = Session.getInstance(props);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,11 +18,13 @@ package org.springframework.integration.mail;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.mail.Message;
import javax.mail.internet.MimeMessage;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
/**
@@ -41,9 +43,9 @@ public class MailReceivingMessageSourceTests {
MimeMessage message3 = Mockito.mock(MimeMessage.class);
MimeMessage message4 = Mockito.mock(MimeMessage.class);
mailReceiver.messages.add(new javax.mail.Message[] { message1 });
mailReceiver.messages.add(new javax.mail.Message[] { message2, message3 });
mailReceiver.messages.add(new javax.mail.Message[] { message4 });
mailReceiver.messages.add(new javax.mail.Message[]{ message1 });
mailReceiver.messages.add(new javax.mail.Message[]{ message2, message3 });
mailReceiver.messages.add(new javax.mail.Message[]{ message4 });
MailReceivingMessageSource source = new MailReceivingMessageSource(mailReceiver);
assertThat(source.receive().getPayload()).as("Wrong message for number 1").isEqualTo(message1);
@@ -57,7 +59,7 @@ public class MailReceivingMessageSourceTests {
@SuppressWarnings("unused")
private static class StubMailReceiver implements MailReceiver {
private final ConcurrentLinkedQueue<javax.mail.Message[]> messages = new ConcurrentLinkedQueue<javax.mail.Message[]>();
private final Queue<Message[]> messages = new ConcurrentLinkedQueue<>();
StubMailReceiver() {
super();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,7 +17,7 @@
package org.springframework.integration.mail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.io.DataInputStream;
@@ -25,9 +25,8 @@ import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.internet.MimeMessage;
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.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,15 +37,13 @@ import org.springframework.mail.SimpleMailMessage;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHandlingException;
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 Marius Bogoevici
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SpringJUnitConfig
public class MailSendingMessageHandlerContextTests {
@Autowired
@@ -69,7 +66,7 @@ public class MailSendingMessageHandlerContextTests {
private BeanFactory beanFactory;
@Before
@BeforeEach
public void reset() {
this.mailSender.reset();
}
@@ -88,12 +85,12 @@ public class MailSendingMessageHandlerContextTests {
@Test
public void byteArrayMessage() throws Exception {
byte[] payload = {1, 2, 3};
byte[] payload = { 1, 2, 3 };
org.springframework.messaging.Message<?> message =
MessageBuilder.withPayload(payload)
.setHeader(MailHeaders.ATTACHMENT_FILENAME, "attachment.txt")
.setHeader(MailHeaders.TO, MailTestsHelper.TO)
.build();
.setHeader(MailHeaders.ATTACHMENT_FILENAME, "attachment.txt")
.setHeader(MailHeaders.TO, MailTestsHelper.TO)
.build();
this.handler.handleMessage(message);
assertThat(this.mailSender.getSentMimeMessages().size()).as("no mime message should have been sent")
.isEqualTo(1);
@@ -102,7 +99,8 @@ public class MailSendingMessageHandlerContextTests {
byte[] buffer = new byte[1024];
MimeMessage mimeMessage = this.mailSender.getSentMimeMessages().get(0);
assertThat(mimeMessage.getContent() instanceof Multipart).as("message must be multipart").isTrue();
int size = new DataInputStream(((Multipart) mimeMessage.getContent()).getBodyPart(0).getInputStream()).read(buffer);
int size = new DataInputStream(((Multipart) mimeMessage.getContent()).getBodyPart(0).getInputStream())
.read(buffer);
assertThat(size).as("buffer size does not match").isEqualTo(payload.length);
byte[] messageContent = new byte[size];
System.arraycopy(buffer, 0, messageContent, 0, payload.length);
@@ -110,10 +108,11 @@ public class MailSendingMessageHandlerContextTests {
assertThat(MailTestsHelper.TO.length).isEqualTo(mimeMessage.getRecipients(Message.RecipientType.TO).length);
}
@Test(expected = MessageMappingException.class)
public void byteArrayMessageWithoutAttachmentFileName() throws Exception {
byte[] payload = {1, 2, 3};
this.handler.handleMessage(new GenericMessage<byte[]>(payload));
@Test
public void byteArrayMessageWithoutAttachmentFileName() {
byte[] payload = { 1, 2, 3 };
assertThatExceptionOfType(MessageMappingException.class)
.isThrownBy(() -> this.handler.handleMessage(new GenericMessage<>(payload)));
}
@Test //INT-2275
@@ -138,38 +137,25 @@ public class MailSendingMessageHandlerContextTests {
assertThat(this.simpleMailSender.getSentMessages().size()).isEqualTo(1);
assertThat(this.simpleMailSender.getSentMessages().get(0)).isEqualTo(MailTestsHelper.createSimpleMailMessage());
try {
this.simpleEmailChannel.send(new GenericMessage<byte[]>(new byte[0]));
fail("IllegalStateException expected");
}
catch (Exception e) {
assertThat(e).isInstanceOf(MessageHandlingException.class);
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("this adapter requires a 'JavaMailSender' to send a 'MimeMailMessage'");
}
assertThatExceptionOfType(MessageHandlingException.class)
.isThrownBy(() -> this.simpleEmailChannel.send(new GenericMessage<>(new byte[0])))
.withCauseInstanceOf(IllegalStateException.class)
.withMessageContaining("this adapter requires a 'JavaMailSender' to send a 'MimeMailMessage'");
try {
this.simpleEmailChannel.send(MessageBuilder.withPayload("foo")
.setHeader(MailHeaders.CONTENT_TYPE, "text/plain")
.setHeader(MailHeaders.TO, "foo@com.foo")
.build());
fail("IllegalStateException expected");
}
catch (Exception e) {
assertThat(e).isInstanceOf(MessageHandlingException.class);
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("this adapter requires a 'JavaMailSender' to send a 'MimeMailMessage'");
}
assertThatExceptionOfType(MessageHandlingException.class)
.isThrownBy(() ->
this.simpleEmailChannel.send(MessageBuilder.withPayload("foo")
.setHeader(MailHeaders.CONTENT_TYPE, "text/plain")
.setHeader(MailHeaders.TO, "foo@com.foo")
.build()))
.withCauseInstanceOf(IllegalStateException.class)
.withMessageContaining("this adapter requires a 'JavaMailSender' to send a 'MimeMailMessage'");
try {
this.simpleEmailChannel.send(new GenericMessage<MimeMessage>(this.mailSender.createMimeMessage()));
fail("IllegalStateException expected");
}
catch (Exception e) {
assertThat(e).isInstanceOf(MessageHandlingException.class);
assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
assertThat(e.getMessage()).contains("this adapter requires a 'JavaMailSender' to send a 'MimeMailMessage'");
}
assertThatExceptionOfType(MessageHandlingException.class)
.isThrownBy(() ->
this.simpleEmailChannel.send(new GenericMessage<>(this.mailSender.createMimeMessage())))
.withCauseInstanceOf(IllegalStateException.class)
.withMessageContaining("this adapter requires a 'JavaMailSender' to send a 'MimeMailMessage'");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,9 +25,9 @@ import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.mail.SimpleMailMessage;
@@ -35,6 +35,7 @@ import org.springframework.mail.SimpleMailMessage;
/**
* @author Marius Bogoevici
* @author Oleg Zhurakousky
* @author Artem Bilan
*/
public class MailSendingMessageHandlerTests {
@@ -43,13 +44,13 @@ public class MailSendingMessageHandlerTests {
private StubJavaMailSender mailSender;
@Before
public void setUp() throws Exception {
@BeforeEach
public void setUp() {
this.mailSender = new StubJavaMailSender(new MimeMessage((Session) null));
this.handler = new MailSendingMessageHandler(this.mailSender);
}
@After
@AfterEach
public void reset() {
this.mailSender.reset();
}
@@ -68,17 +69,18 @@ public class MailSendingMessageHandlerTests {
@Test
public void byteArrayMessage() throws Exception {
byte[] payload = {1, 2, 3};
byte[] payload = { 1, 2, 3 };
org.springframework.messaging.Message<byte[]> message =
MessageBuilder.withPayload(payload)
.setHeader(MailHeaders.ATTACHMENT_FILENAME, "attachment.txt")
.setHeader(MailHeaders.TO, MailTestsHelper.TO)
.build();
.setHeader(MailHeaders.ATTACHMENT_FILENAME, "attachment.txt")
.setHeader(MailHeaders.TO, MailTestsHelper.TO)
.build();
this.handler.handleMessage(message);
byte[] buffer = new byte[1024];
MimeMessage mimeMessage = this.mailSender.getSentMimeMessages().get(0);
assertThat(mimeMessage.getContent() instanceof Multipart).as("message must be multipart").isTrue();
int size = new DataInputStream(((Multipart) mimeMessage.getContent()).getBodyPart(0).getInputStream()).read(buffer);
int size = new DataInputStream(((Multipart) mimeMessage.getContent()).getBodyPart(0).getInputStream())
.read(buffer);
assertThat(size).as("buffer size does not match").isEqualTo(payload.length);
byte[] messageContent = new byte[size];
System.arraycopy(buffer, 0, messageContent, 0, payload.length);
@@ -96,6 +98,7 @@ public class MailSendingMessageHandlerTests {
assertThat(mailSender.getSentSimpleMailMessages().get(0)).as("message content different from expected")
.isEqualTo(mailMessage);
}
@Test
public void simpleMailMessage() {
SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
@@ -104,18 +107,19 @@ public class MailSendingMessageHandlerTests {
assertThat(mailSender.getSentSimpleMailMessages().size()).as("only one simple message must be sent")
.isEqualTo(1);
SimpleMailMessage sentMessage = mailSender.getSentSimpleMailMessages().get(0);
assertThat(sentMessage.getTo().equals(toHeaders)).isTrue();
assertThat(sentMessage.getTo()).isEqualTo(toHeaders);
}
@Test
public void simpleMailMessageOverrideWithHeaders() {
SimpleMailMessage mailMessage = MailTestsHelper.createSimpleMailMessage();
mailMessage.getTo();
this.handler.handleMessage(MessageBuilder.withPayload(mailMessage).setHeader(MailHeaders.TO, new String[]{"foo" +
"@bar.bam"}).build());
this.handler.handleMessage(MessageBuilder.withPayload(mailMessage)
.setHeader(MailHeaders.TO, new String[]{ "foo@bar.bam" }).build());
assertThat(mailSender.getSentSimpleMailMessages().size()).as("only one simple message must be sent")
.isEqualTo(1);
SimpleMailMessage sentMessage = mailSender.getSentSimpleMailMessages().get(0);
assertThat(sentMessage.getTo()[0].equals("foo@bar.bam")).isTrue();
assertThat(sentMessage.getTo()[0]).isEqualTo("foo@bar.bam");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.internet.MimeMessage;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanFactory;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,8 +18,7 @@ package org.springframework.integration.mail.config;
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.context.ApplicationContext;
@@ -30,18 +29,17 @@ import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageChannel;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.util.ErrorHandler;
/**
* @author Mark Fisher
* @author Artem Bilan
* @author Gary Russell
*
* @since 1.0.3
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SpringJUnitConfig
public class DefaultConfigurationTests {
@Autowired

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,7 +16,9 @@
package org.springframework.integration.mail.config;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -24,21 +26,27 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*
*/
public class FailedMailConfigurationTests {
/**
* validates that if 'should-delete-messages' is not set the context fails
* Validates that if 'should-delete-messages' is not set the context fails
*/
@Test(expected = XmlBeanDefinitionStoreException.class)
@Test
public void testImapIdleWithNoDeleteMessageAttribute() {
new ClassPathXmlApplicationContext("failed-imap-config.xml", this.getClass()).close();
assertThatExceptionOfType(XmlBeanDefinitionStoreException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext("failed-imap-config.xml", getClass()));
}
/**
* validates that if 'should-delete-messages' is not set the context fails
* Validates that if 'should-delete-messages' is not set the context fails
*/
@Test(expected = XmlBeanDefinitionStoreException.class)
@Test
public void testAdapterWithNoDeleteMessageAttribute() {
new ClassPathXmlApplicationContext("failed-adapter-config.xml", this.getClass()).close();
assertThatExceptionOfType(XmlBeanDefinitionStoreException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext("failed-adapter-config.xml", getClass()));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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 javax.mail.Folder;
import javax.mail.URLName;
import javax.mail.search.SearchTerm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,8 +37,7 @@ import org.springframework.integration.mail.SearchTermStrategy;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageChannel;
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;
/**
* @author Mark Fisher
@@ -47,8 +45,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Gary Russell
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SpringJUnitConfig
@DirtiesContext
public class ImapIdleChannelAdapterParserTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import javax.mail.Folder;
import javax.mail.Message;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.mail.ImapIdleChannelAdapter;
@@ -61,7 +61,7 @@ public class ImapIdleIntegrationTests {
receiver = spy(receiver);
doAnswer(invocation -> {
// ensures that waitFornewMessages call blocks after a first execution
// ensures that waitForNewMessages call blocks after a first execution
// to emulate the behavior of IDLE
if (block.get()) {
Thread.sleep(5000);
@@ -71,7 +71,7 @@ public class ImapIdleIntegrationTests {
}).when(receiver).waitForNewMessages();
Message m1 = mock(Message.class);
doReturn(new Message[]{m1}).when(receiver).receive();
doReturn(new Message[]{ m1 }).when(receiver).receive();
Folder folder = mock(Folder.class);
when(folder.isOpen()).thenReturn(true);
@@ -102,6 +102,7 @@ public class ImapIdleIntegrationTests {
public interface PostTransactionProcessor {
void process(Message mailMessage);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,12 +17,11 @@
package org.springframework.integration.mail.config;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import javax.mail.Authenticator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.xml.sax.SAXParseException;
import org.springframework.beans.DirectFieldAccessor;
@@ -41,17 +40,17 @@ import org.springframework.integration.mail.SearchTermStrategy;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageChannel;
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;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*
* @since 1.0.5
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class InboundChannelAdapterParserTests {
@@ -61,11 +60,11 @@ public class InboundChannelAdapterParserTests {
@Autowired
private MessageChannel autoChannel;
@Autowired @Qualifier("autoChannel.adapter")
@Autowired
@Qualifier("autoChannel.adapter")
private SourcePollingChannelAdapter autoChannelAdapter;
//==================== INT-982 =====================
@Test
public void pop3ShouldDeleteTrue() {
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteTrue");
@@ -119,7 +118,6 @@ public class InboundChannelAdapterParserTests {
//==================== INT-1158 ====================
@Test
public void pop3ShouldDeleteTrueProperty() {
AbstractMailReceiver receiver = this.getReceiver("pop3ShouldDeleteTrueProperty");
@@ -155,7 +153,6 @@ public class InboundChannelAdapterParserTests {
//==================== INT-1159 ====================
@Test
public void pop3WithAuthenticator() {
AbstractMailReceiver receiver = this.getReceiver("pop3WithAuthenticator");
@@ -186,11 +183,11 @@ public class InboundChannelAdapterParserTests {
@SuppressWarnings("unused")
private static class TestAuthenticator extends Authenticator {
}
//==================== INT-1160 ====================
@Test
public void pop3WithMaxFetchSize() {
AbstractMailReceiver receiver = this.getReceiver("pop3WithMaxFetchSize");
@@ -225,7 +222,6 @@ public class InboundChannelAdapterParserTests {
//==================== INT-1161 ====================
@Test
public void pop3WithSession() {
AbstractMailReceiver receiver = this.getReceiver("pop3WithSession");
@@ -255,7 +251,6 @@ public class InboundChannelAdapterParserTests {
//==================== INT-1162 ====================
@Test
public void pop3WithoutStoreUri() {
AbstractMailReceiver receiver = this.getReceiver("pop3WithoutStoreUri");
@@ -282,23 +277,16 @@ public class InboundChannelAdapterParserTests {
//==================== INT-1163 ====================
@Test
public void inboundChannelAdapterRequiresShouldDeleteMessages() {
try {
new ClassPathXmlApplicationContext(
"org/springframework/integration/mail/config/InboundChannelAdapterParserTests-invalidContext.xml")
.close();
fail("expected a parser error");
}
catch (BeanDefinitionStoreException e) {
assertThat(e.getCause().getClass()).isEqualTo(SAXParseException.class);
}
assertThatExceptionOfType(BeanDefinitionStoreException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext(
"InboundChannelAdapterParserTests-invalidContext.xml", getClass()))
.withCauseInstanceOf(SAXParseException.class);
}
//==================== INT-2800 ====================
@Test
public void imapWithSearchTermStrategy() {
AbstractMailReceiver receiver = this.getReceiver("imapWithSearch");
@@ -312,15 +300,10 @@ public class InboundChannelAdapterParserTests {
@Test
public void pop3WithSearchTermStrategy() {
try {
new ClassPathXmlApplicationContext(
"org/springframework/integration/mail/config/InboundChannelAdapterParserTests-pop3Search-context.xml")
.close();
fail("expected a parser error");
}
catch (BeanCreationException e) {
assertThat(e.getMessage().contains("searchTermStrategy is only allowed with imap")).isTrue();
}
assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> new ClassPathXmlApplicationContext(
"InboundChannelAdapterParserTests-pop3Search-context.xml", getClass()))
.withMessageContaining("searchTermStrategy is only allowed with imap");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,8 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
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.beans.factory.annotation.Qualifier;
@@ -31,15 +30,13 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
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;
/**
* @author Mark Fisher
* @author Artem Bilan
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig
@DirtiesContext
public class MailHeaderEnricherTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,7 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Properties;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.context.ConfigurableApplicationContext;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.mail.config;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import javax.mail.internet.MimeMessage;
@@ -40,8 +41,8 @@ class MailToStringTransformerParserTests {
@Test
void topLevelTransformer() throws Exception {
try (ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("mailToStringTransformerParserTests.xml", this.getClass());) {
try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"mailToStringTransformerParserTests.xml", getClass())) {
MessageChannel input = new BeanFactoryChannelResolver(context).resolveDestination("input");
PollableChannel output =
@@ -58,8 +59,8 @@ class MailToStringTransformerParserTests {
@Test
void transformerWithinChain() throws Exception {
try (ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("mailToStringTransformerWithinChain.xml", this.getClass());) {
try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"mailToStringTransformerWithinChain.xml", getClass())) {
MessageChannel input = new BeanFactoryChannelResolver(context).resolveDestination("input");
PollableChannel output =
@@ -76,13 +77,11 @@ class MailToStringTransformerParserTests {
@Test
void topLevelTransformerMissingInput() {
try {
new ClassPathXmlApplicationContext("mailToStringTransformerWithoutInputChannel.xml", this.getClass())
.close();
}
catch (BeanDefinitionStoreException e) {
assertThat(e.getMessage().contains("input-channel")).isTrue();
}
assertThatExceptionOfType(BeanDefinitionStoreException.class)
.isThrownBy(() ->
new ClassPathXmlApplicationContext("mailToStringTransformerWithoutInputChannel.xml",
getClass()))
.withMessageContaining("input-channel");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@@ -30,8 +30,8 @@ import java.util.Properties;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.context.ConfigurableApplicationContext;
@@ -48,12 +48,13 @@ import org.springframework.util.FileCopyUtils;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
*
*/
public class MessageWithContentTypeTests {
@Test
@Ignore
@Disabled
public void testSendEmail() throws Exception {
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext(
"MessageWithContentTypeTests-context.xml", this.getClass());
@@ -61,7 +62,7 @@ public class MessageWithContentTypeTests {
StringWriter writer = new StringWriter();
FileReader reader = new FileReader("src/test/java/org/springframework/integration/mail/config/test.html");
FileCopyUtils.copy(reader, writer);
inputChannel.send(new GenericMessage<String>(writer.getBuffer().toString()));
inputChannel.send(new GenericMessage<>(writer.getBuffer().toString()));
ac.close();
}
@@ -73,10 +74,10 @@ public class MessageWithContentTypeTests {
FileReader reader = new FileReader("src/test/java/org/springframework/integration/mail/config/test.html");
FileCopyUtils.copy(reader, writer);
Message<String> message = MessageBuilder.withPayload(writer.getBuffer().toString())
.setHeader(MailHeaders.TO, "to")
.setHeader(MailHeaders.FROM, "from")
.setHeader(MailHeaders.CONTENT_TYPE, "text/html")
.build();
.setHeader(MailHeaders.TO, "to")
.setHeader(MailHeaders.FROM, "from")
.setHeader(MailHeaders.CONTENT_TYPE, "text/html")
.build();
MimeMessage mMessage = new TestMimeMessage();
// MOCKS
when(sender.createMimeMessage()).thenReturn(mMessage);
@@ -93,9 +94,11 @@ public class MessageWithContentTypeTests {
}
private static class TestMimeMessage extends MimeMessage {
TestMimeMessage() {
super(Session.getDefaultInstance(new Properties()));
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,8 +22,7 @@ import java.util.Properties;
import javax.mail.URLName;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,15 +31,14 @@ import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.mail.ImapMailReceiver;
import org.springframework.integration.mail.MailReceivingMessageSource;
import org.springframework.integration.mail.Pop3MailReceiver;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Jonas Partner
* @author Mark Fisher
* @author Artem Bilan
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SpringJUnitConfig
public class PollingMailSourceParserTests {
@Autowired

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2021 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,9 +20,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import org.junit.AfterClass;
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.Test;
import org.springframework.integration.mail.MailHeaders;
import org.springframework.integration.mail.MailReceivingMessageSource;
@@ -35,6 +35,8 @@ import org.springframework.messaging.MessageHeaders;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.0
*
*/
@@ -42,7 +44,7 @@ public class Pop3Tests {
private static final Pop3Server pop3Server = TestMailServer.pop3(0);
@BeforeClass
@BeforeAll
public static void setup() throws InterruptedException {
int n = 0;
while (n++ < 100 && (!pop3Server.isListening())) {
@@ -51,13 +53,13 @@ public class Pop3Tests {
assertThat(n < 100).isTrue();
}
@AfterClass
@AfterAll
public static void tearDown() {
pop3Server.stop();
}
@Test
public void testPop3() throws Exception {
public void testPop3() {
Pop3MailReceiver receiver = new Pop3MailReceiver("localhost", pop3Server.getPort(), "user", "pw");
receiver.setHeaderMapper(new DefaultMailHeaderMapper());
MailReceivingMessageSource source = new MailReceivingMessageSource(receiver);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-2021 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,9 +18,9 @@ package org.springframework.integration.mail.config;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.AfterClass;
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.Test;
import org.springframework.integration.mail.MailHeaders;
import org.springframework.integration.mail.MailSendingMessageHandler;
@@ -31,6 +31,8 @@ import org.springframework.mail.javamail.JavaMailSenderImpl;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.0
*
*/
@@ -38,7 +40,7 @@ public class SmtpTests {
private static final SmtpServer smtpServer = TestMailServer.smtp(0);
@BeforeClass
@BeforeAll
public static void setup() throws InterruptedException {
int n = 0;
while (n++ < 100 && (!smtpServer.isListening())) {
@@ -47,7 +49,7 @@ public class SmtpTests {
assertThat(n < 100).isTrue();
}
@AfterClass
@AfterAll
public static void tearDown() {
smtpServer.stop();
}
@@ -62,7 +64,7 @@ public class SmtpTests {
MailSendingMessageHandler handler = new MailSendingMessageHandler(mailSender);
handler.handleMessage(MessageBuilder.withPayload("foo")
.setHeader(MailHeaders.TO, new String[] {"bar@baz"})
.setHeader(MailHeaders.TO, new String[]{ "bar@baz" })
.setHeader(MailHeaders.FROM, "foo@bar")
.setHeader(MailHeaders.SUBJECT, "foo")
.build());
@@ -74,12 +76,12 @@ public class SmtpTests {
assertThat(smtpServer.getMessages().size() > 0).isTrue();
String message = smtpServer.getMessages().get(0);
assertThat(message).endsWith("foo\n");
assertThat(message).contains("foo@bar");
assertThat(message).contains("bar@baz");
assertThat(message).contains("user:user");
assertThat(message).contains("password:pw");
assertThat(message)
.endsWith("foo\n")
.contains("foo@bar")
.contains("bar@baz")
.contains("user:user")
.contains("password:pw");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2021 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.
@@ -169,7 +169,7 @@ public class MailTests {
assertThat(headers.get(MailHeaders.TO, String[].class)).containsExactly("Foo <foo@bar>");
assertThat(headers.get(MailHeaders.FROM)).isEqualTo("Bar <bar@baz>");
assertThat(headers.get(MailHeaders.SUBJECT)).isEqualTo("Test Email");
assertThat(message.getPayload()).isEqualTo(TestMailServer.MailServer.MailHandler.MESSAGE + "\r\n");
assertThat(message.getPayload()).isEqualTo(TestMailServer.MailServer.MailHandler.BODY + "\r\n");
assertThat(message.getHeaders().containsKey(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE)).isTrue();
this.imapIdleAdapter.stop();
assertThat(TestUtils.getPropertyValue(this.imapIdleAdapter, "shouldReconnectAutomatically", Boolean.class))
@@ -265,6 +265,7 @@ public class MailTests {
.javaMailProperties(p -> p.put("mail.debug", "false")
.put("mail.imap.connectionpoolsize", "5"))
.shouldReconnectAutomatically(false)
.simpleContent(true)
.headerMapper(mailHeaderMapper()))
.channel(MessageChannels.queue("imapIdleChannel"))
.get();