From a0e6d7c7d4ee98c77359eb76f63ff2e1c3db78f9 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 9 Jan 2024 14:09:01 -0500 Subject: [PATCH] Make Mail supplier as auto-config * Fix all their Checkstyle violations * Fix Checkstyle violations in the `spring-kafka-supplier`, too --- .../kafka/KafkaSupplierConfiguration.java | 2 +- .../cloud/fn/supplier/kafka/package-info.java | 4 + supplier/spring-mail-supplier/README.adoc | 2 +- .../mail/MailSupplierConfiguration.java | 80 +++++++------------ .../supplier/mail/MailSupplierProperties.java | 42 +--------- .../cloud/fn/supplier/mail/package-info.java | 4 + ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../mail/AbstractMailSupplierTests.java | 12 ++- .../cloud/fn/supplier/mail/ImapFailTests.java | 51 ------------ .../fn/supplier/mail/ImapIdlePassTests.java | 24 ++++-- .../cloud/fn/supplier/mail/Pop3FailTests.java | 43 ---------- .../cloud/fn/supplier/mail/Pop3PassTests.java | 10 +-- 12 files changed, 76 insertions(+), 199 deletions(-) create mode 100644 supplier/spring-kafka-supplier/src/main/java/org/springframework/cloud/fn/supplier/kafka/package-info.java create mode 100644 supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/package-info.java create mode 100644 supplier/spring-mail-supplier/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/ImapFailTests.java delete mode 100644 supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/Pop3FailTests.java diff --git a/supplier/spring-kafka-supplier/src/main/java/org/springframework/cloud/fn/supplier/kafka/KafkaSupplierConfiguration.java b/supplier/spring-kafka-supplier/src/main/java/org/springframework/cloud/fn/supplier/kafka/KafkaSupplierConfiguration.java index 10804af7..2a594104 100644 --- a/supplier/spring-kafka-supplier/src/main/java/org/springframework/cloud/fn/supplier/kafka/KafkaSupplierConfiguration.java +++ b/supplier/spring-kafka-supplier/src/main/java/org/springframework/cloud/fn/supplier/kafka/KafkaSupplierConfiguration.java @@ -126,7 +126,7 @@ public class KafkaSupplierConfiguration { StandardEvaluationContext evaluationContext = IntegrationContextUtils.getEvaluationContext(beanFactory); - return consumerRecord -> Boolean.TRUE.equals( + return (consumerRecord) -> Boolean.TRUE.equals( kafkaSupplierProperties.getRecordFilter().getValue(evaluationContext, consumerRecord, Boolean.class)); } diff --git a/supplier/spring-kafka-supplier/src/main/java/org/springframework/cloud/fn/supplier/kafka/package-info.java b/supplier/spring-kafka-supplier/src/main/java/org/springframework/cloud/fn/supplier/kafka/package-info.java new file mode 100644 index 00000000..ba790b36 --- /dev/null +++ b/supplier/spring-kafka-supplier/src/main/java/org/springframework/cloud/fn/supplier/kafka/package-info.java @@ -0,0 +1,4 @@ +/** + * The Apache Kafka supplier auto-configuration support. + */ +package org.springframework.cloud.fn.supplier.kafka; diff --git a/supplier/spring-mail-supplier/README.adoc b/supplier/spring-mail-supplier/README.adoc index e5f1f4a1..20228909 100644 --- a/supplier/spring-mail-supplier/README.adoc +++ b/supplier/spring-mail-supplier/README.adoc @@ -9,7 +9,7 @@ Users have to subscribe to this `Flux` and receive the data. ## Beans for injection -You can import the `MailSupplierConfiguration` in the application and then inject the following bean. +The `MailSupplierConfiguration` auto-configuration provides the following bean: `mailSupplier` diff --git a/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/MailSupplierConfiguration.java b/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/MailSupplierConfiguration.java index 6bbaa5ea..6a514d6c 100644 --- a/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/MailSupplierConfiguration.java +++ b/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/MailSupplierConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 the original author or authors. + * Copyright 2020-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. @@ -25,11 +25,11 @@ import jakarta.mail.URLName; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; +import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.fn.common.config.ComponentCustomizer; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.integration.core.MessageSource; import org.springframework.integration.dsl.IntegrationFlow; import org.springframework.integration.dsl.MessageProducerSpec; @@ -38,27 +38,28 @@ import org.springframework.integration.endpoint.MessageProducerSupport; import org.springframework.integration.endpoint.ReactiveMessageSourceProducer; import org.springframework.integration.mail.MailHeaders; import org.springframework.integration.mail.dsl.ImapIdleChannelAdapterSpec; +import org.springframework.integration.mail.dsl.ImapMailInboundChannelAdapterSpec; import org.springframework.integration.mail.dsl.Mail; import org.springframework.integration.mail.dsl.MailInboundChannelAdapterSpec; +import org.springframework.integration.mail.dsl.Pop3MailInboundChannelAdapterSpec; import org.springframework.integration.transformer.support.AbstractHeaderValueMessageProcessor; import org.springframework.integration.transformer.support.HeaderValueMessageProcessor; import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** - * Mail supplier components. + * Mail supplier auto-configuration. * - * @author Amol * @author Artem Bilan * @author Chris Schaefer - * @author Soby Chacko * @author Corneil du Plessis + * @author Soby Chacko */ -@Configuration(proxyBeanMethods = false) @EnableConfigurationProperties(MailSupplierProperties.class) +@AutoConfiguration public class MailSupplierConfiguration { - final private MailSupplierProperties properties; + private final MailSupplierProperties properties; public MailSupplierConfiguration(MailSupplierProperties properties) { this.properties = properties; @@ -66,10 +67,9 @@ public class MailSupplierConfiguration { @Bean public Publisher> mailInboundFlow(MessageProducerSupport messageProducer) { - return IntegrationFlow.from(messageProducer) .transform(Mail.toStringTransformer(this.properties.getCharset())) - .enrichHeaders(h -> h.defaultOverwrite(true) + .enrichHeaders((h) -> h.defaultOverwrite(true) .header(MailHeaders.TO, arrayToListProcessor(MailHeaders.TO)) .header(MailHeaders.CC, arrayToListProcessor(MailHeaders.CC)) .header(MailHeaders.BCC, arrayToListProcessor(MailHeaders.BCC))) @@ -81,7 +81,7 @@ public class MailSupplierConfiguration { return () -> Flux.from(messagePublisher); } - private HeaderValueMessageProcessor arrayToListProcessor(final String header) { + private HeaderValueMessageProcessor arrayToListProcessor(String header) { return new AbstractHeaderValueMessageProcessor>() { @Override @@ -103,7 +103,8 @@ public class MailSupplierConfiguration { .userFlag(this.properties.getUserFlag()) .javaMailProperties(getJavaMailProperties(urlName)) .selectorExpression(this.properties.getExpression()) - .shouldMarkMessagesAsRead(this.properties.isMarkAsRead()); + .shouldMarkMessagesAsRead(this.properties.isMarkAsRead()) + .autoStartup(false); if (imapIdleChannelAdapterSpecCustomizer != null) { imapIdleChannelAdapterSpecCustomizer.customize(imapIdleChannelAdapterSpec); @@ -118,18 +119,11 @@ public class MailSupplierConfiguration { MailInboundChannelAdapterSpec adapterSpec; URLName urlName = this.properties.getUrl(); - switch (urlName.getProtocol().toUpperCase()) { - case "IMAP": - case "IMAPS": - adapterSpec = getImapChannelAdapterSpec(urlName); - break; - case "POP3": - case "POP3S": - adapterSpec = getPop3ChannelAdapterSpec(urlName); - break; - default: - throw new IllegalArgumentException("Unsupported mail protocol: " + urlName.getProtocol()); - } + adapterSpec = switch (urlName.getProtocol().toUpperCase()) { + case "IMAP", "IMAPS" -> getImapChannelAdapterSpec(urlName); + case "POP3", "POP3S" -> getPop3ChannelAdapterSpec(urlName); + default -> throw new IllegalArgumentException("Unsupported mail protocol: " + urlName.getProtocol()); + }; adapterSpec.javaMailProperties(getJavaMailProperties(urlName)) .userFlag(this.properties.getUserFlag()) .selectorExpression(this.properties.getExpression()) @@ -145,26 +139,17 @@ public class MailSupplierConfiguration { @Bean("mailChannelAdapter") @ConditionalOnProperty(value = "mail.supplier.idle-imap", matchIfMissing = true, havingValue = "false") MessageProducerSupport mailMessageProducer(MessageSource mailMessageSource) { - return new ReactiveMessageSourceProducer(mailMessageSource); + ReactiveMessageSourceProducer reactiveMessageSourceProducer = new ReactiveMessageSourceProducer( + mailMessageSource); + reactiveMessageSourceProducer.setAutoStartup(false); + return reactiveMessageSourceProducer; } - /** - * Method to build Mail Channel Adapter for POP3. - * @param urlName Mail source URL. - * @return Mail Channel for POP3 - */ - @SuppressWarnings("rawtypes") - private MailInboundChannelAdapterSpec getPop3ChannelAdapterSpec(URLName urlName) { + private Pop3MailInboundChannelAdapterSpec getPop3ChannelAdapterSpec(URLName urlName) { return Mail.pop3InboundAdapter(urlName.toString()); } - /** - * Method to build Mail Channel Adapter for IMAP. - * @param urlName Mail source URL. - * @return Mail Channel for IMAP - */ - @SuppressWarnings("rawtypes") - private MailInboundChannelAdapterSpec getImapChannelAdapterSpec(URLName urlName) { + private ImapMailInboundChannelAdapterSpec getImapChannelAdapterSpec(URLName urlName) { return Mail.imapInboundAdapter(urlName.toString()).shouldMarkMessagesAsRead(this.properties.isMarkAsRead()); } @@ -172,29 +157,26 @@ public class MailSupplierConfiguration { Properties javaMailProperties = new Properties(); switch (urlName.getProtocol().toUpperCase()) { - case "IMAP": + case "IMAP" -> { javaMailProperties.setProperty("mail.imap.socketFactory.class", "javax.net.SocketFactory"); javaMailProperties.setProperty("mail.imap.socketFactory.fallback", "false"); javaMailProperties.setProperty("mail.store.protocol", "imap"); - break; - - case "IMAPS": + } + case "IMAPS" -> { javaMailProperties.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); javaMailProperties.setProperty("mail.imap.socketFactory.fallback", "false"); javaMailProperties.setProperty("mail.store.protocol", "imaps"); - break; - - case "POP3": + } + case "POP3" -> { javaMailProperties.setProperty("mail.pop3.socketFactory.class", "javax.net.SocketFactory"); javaMailProperties.setProperty("mail.pop3.socketFactory.fallback", "false"); javaMailProperties.setProperty("mail.store.protocol", "pop3"); - break; - - case "POP3S": + } + case "POP3S" -> { javaMailProperties.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); javaMailProperties.setProperty("mail.pop3.socketFactory.fallback", "false"); javaMailProperties.setProperty("mail.store.protocol", "pop3s"); - break; + } } javaMailProperties.putAll(this.properties.getJavaMailProperties()); diff --git a/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/MailSupplierProperties.java b/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/MailSupplierProperties.java index a6972644..13808148 100644 --- a/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/MailSupplierProperties.java +++ b/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/MailSupplierProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2020 the original author or authors. + * Copyright 2020-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. @@ -26,7 +26,7 @@ import org.springframework.integration.mail.AbstractMailReceiver; import org.springframework.validation.annotation.Validated; /** - * Properties for the file supplier. + * Configuration properties for Mail supplier. * * @author Gary Russell * @author Artem Bilan @@ -58,7 +58,7 @@ public class MailSupplierProperties { private boolean idleImap = false; /** - * JavaMail properties as a new line delimited string of name-value pairs, e.g. + * Java Mail properties as a new line delimited string of name-value pairs, e.g. * 'foo=bar\n baz=car'. */ private Properties javaMailProperties = new Properties(); @@ -78,89 +78,53 @@ public class MailSupplierProperties { */ private String userFlag = AbstractMailReceiver.DEFAULT_SI_USER_FLAG; - /** - * @return the markAsRead - */ public boolean isMarkAsRead() { return this.markAsRead; } - /** - * @param markAsRead the markAsRead to set - */ public void setMarkAsRead(boolean markAsRead) { this.markAsRead = markAsRead; } - /** - * @return the delete - */ public boolean isDelete() { return this.delete; } - /** - * @param delete the delete to set - */ public void setDelete(boolean delete) { this.delete = delete; } - /** - * @return the idleImap - */ public boolean isIdleImap() { return this.idleImap; } - /** - * @param idleImap the idleImap to set - */ public void setIdleImap(boolean idleImap) { this.idleImap = idleImap; } - /** - * @return the javaMailProperties - */ @NotNull public Properties getJavaMailProperties() { return this.javaMailProperties; } - /** - * @param javaMailProperties the javaMailProperties to set - */ public void setJavaMailProperties(Properties javaMailProperties) { this.javaMailProperties = javaMailProperties; } - /** - * @return the url - */ @NotNull public URLName getUrl() { return this.url; } - /** - * @param url the url to set - */ public void setUrl(URLName url) { this.url = url; } - /** - * @return the expression - */ @NotNull public String getExpression() { return this.expression; } - /** - * @param expression the expression to set - */ public void setExpression(String expression) { this.expression = expression; } diff --git a/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/package-info.java b/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/package-info.java new file mode 100644 index 00000000..4d7fd620 --- /dev/null +++ b/supplier/spring-mail-supplier/src/main/java/org/springframework/cloud/fn/supplier/mail/package-info.java @@ -0,0 +1,4 @@ +/** + * The MQTT supplier auto-configuration support. + */ +package org.springframework.cloud.fn.supplier.mail; diff --git a/supplier/spring-mail-supplier/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/supplier/spring-mail-supplier/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..a4d8e1b3 --- /dev/null +++ b/supplier/spring-mail-supplier/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.springframework.cloud.fn.supplier.mail.MailSupplierConfiguration diff --git a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/AbstractMailSupplierTests.java b/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/AbstractMailSupplierTests.java index 264faa0b..7ed5c60c 100644 --- a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/AbstractMailSupplierTests.java +++ b/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/AbstractMailSupplierTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2020 the original author or authors. + * Copyright 2020-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. @@ -23,6 +23,7 @@ import com.icegreen.greenmail.util.GreenMail; import com.icegreen.greenmail.util.GreenMailUtil; import com.icegreen.greenmail.util.ServerSetup; import com.icegreen.greenmail.util.ServerSetupTest; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import reactor.core.publisher.Flux; @@ -35,8 +36,8 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, properties = { "mail.supplier.mark-as-read=true", - "mail.supplier.delete=false", "mail.supplier.user-flag=testSIUserFlag", +@SpringBootTest(properties = { "mail.supplier.mark-as-read=true", "mail.supplier.delete=false", + "mail.supplier.user-flag=testSIUserFlag", "mail.supplier.java-mail-properties=mail.imap.socketFactory.fallback=true\\n mail.store.protocol=imap\\n mail.debug=true" }) @DirtiesContext public abstract class AbstractMailSupplierTests { @@ -70,6 +71,11 @@ public abstract class AbstractMailSupplierTests { mailServer.start(); } + @AfterAll + static void tearDown() { + mailServer.stop(); + } + @DynamicPropertySource static void mongoDbProperties(DynamicPropertyRegistry registry) { registry.add("test.mail.server.imap.port", mailServer.getImap().getServerSetup()::getPort); diff --git a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/ImapFailTests.java b/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/ImapFailTests.java deleted file mode 100644 index 05615d96..00000000 --- a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/ImapFailTests.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2020-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. - * 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.cloud.fn.supplier.mail; - -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.integration.mail.transformer.MailToStringTransformer; -import org.springframework.integration.test.util.TestUtils; -import org.springframework.messaging.Message; -import org.springframework.test.context.TestPropertySource; - -import static org.assertj.core.api.Assertions.assertThat; - -@TestPropertySource(properties = { "mail.supplier.url=imap://user:pw@localhost:${test.mail.server.imap.port}/INBOX", - "mail.supplier.charset=cp1251" }) -public class ImapFailTests extends AbstractMailSupplierTests { - - @Autowired - protected MailToStringTransformer mailToStringTransformer; - - @Test - public void testSimpleTest() { - // given - sendMessage("test", "foo"); - // when - final Flux> messageFlux = mailSupplier.get(); - // then - assertThat(TestUtils.getPropertyValue(mailToStringTransformer, "charset").equals("cp1251")).isTrue(); - StepVerifier.create(messageFlux).assertNext((message) -> { - assertThat(((String) message.getPayload())).isNotEqualTo("Test Mail"); - }).thenCancel().verify(); - } - -} diff --git a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/ImapIdlePassTests.java b/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/ImapIdlePassTests.java index 96ee190b..7e4b9e7b 100644 --- a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/ImapIdlePassTests.java +++ b/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/ImapIdlePassTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2020 the original author or authors. + * Copyright 2020-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. @@ -20,26 +20,36 @@ import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.mail.transformer.MailToStringTransformer; +import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.test.context.TestPropertySource; import static org.assertj.core.api.Assertions.assertThat; @TestPropertySource(properties = { "mail.supplier.idle-imap=true", - "mail.supplier.url=imap://user:pw@localhost:${test.mail.server.imap.port}/INBOX" }) + "mail.supplier.url=imap://user:pw@localhost:${test.mail.server.imap.port}/INBOX", + "mail.supplier.charset=cp1251" }) public class ImapIdlePassTests extends AbstractMailSupplierTests { + @Autowired + MailToStringTransformer mailToStringTransformer; + @Test public void testSimpleTest() { // given sendMessage("test", "foo"); // when - final Flux> messageFlux = mailSupplier.get(); + final Flux> messageFlux = this.mailSupplier.get(); // then - StepVerifier.create(messageFlux).assertNext((message) -> { - System.out.println("Message:" + message); - assertThat(((String) message.getPayload())).isEqualTo("foo"); - }).thenCancel().verify(); + + assertThat(TestUtils.getPropertyValue(this.mailToStringTransformer, "charset").equals("cp1251")).isTrue(); + + StepVerifier.create(messageFlux) + .assertNext((message) -> assertThat(((String) message.getPayload())).isEqualTo("foo")) + .thenCancel() + .verify(); } } diff --git a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/Pop3FailTests.java b/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/Pop3FailTests.java deleted file mode 100644 index aca6d806..00000000 --- a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/Pop3FailTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2020-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. - * 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.cloud.fn.supplier.mail; - -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - -import org.springframework.messaging.Message; -import org.springframework.test.context.TestPropertySource; - -import static org.assertj.core.api.Assertions.assertThat; - -@TestPropertySource(properties = "mail.supplier.url=pop3://user:pw@localhost:${test.mail.server.pop3.port}/INBOX") -public class Pop3FailTests extends AbstractMailSupplierTests { - - @Test - public void testSimpleTest() { - // given - sendMessage("test", "foo"); - // when - final Flux> messageFlux = mailSupplier.get(); - // then - StepVerifier.create(messageFlux).assertNext((message) -> { - assertThat(((String) message.getPayload())).isNotEqualTo("Test Mail"); - }).thenCancel().verify(); - } - -} diff --git a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/Pop3PassTests.java b/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/Pop3PassTests.java index 0e263122..ac49ee88 100644 --- a/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/Pop3PassTests.java +++ b/supplier/spring-mail-supplier/src/test/java/org/springframework/cloud/fn/supplier/mail/Pop3PassTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2020 the original author or authors. + * Copyright 2020-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. @@ -34,10 +34,10 @@ public class Pop3PassTests extends AbstractMailSupplierTests { sendMessage("test", "foo"); final Flux> messageFlux = mailSupplier.get(); - StepVerifier.create(messageFlux).assertNext((message) -> { - assertThat(((String) message.getPayload())).contains("foo"); - }).thenCancel().verify(); - + StepVerifier.create(messageFlux) + .assertNext((message) -> assertThat(((String) message.getPayload())).contains("foo")) + .thenCancel() + .verify(); } }