You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2024/01/24 11:52:34 UTC
(causeway) branch master updated (a9f3468986 -> 2f0364af66)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
from a9f3468986 CAUSEWAY-3668: removes commons-email
new 1b2bf6842a CAUSEWAY-3668: deprecates previous emails service config
new 2f0364af66 CAUSEWAY-3668: adds EmailServiceDefault IntegTest
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../core/config/CausewayConfiguration.java | 97 ++++++++++++++--
regressiontests/stable-config/pom.xml | 14 +++
.../config/EmailServiceDefault_IntegTest.java | 122 +++++++++++++++++++++
.../resources/application-config-test.properties | 9 ++
4 files changed, 230 insertions(+), 12 deletions(-)
create mode 100644 regressiontests/stable-config/src/test/java/org/apache/causeway/testdomain/config/EmailServiceDefault_IntegTest.java
(causeway) 01/02: CAUSEWAY-3668: deprecates previous emails service config
Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 1b2bf6842a8def044c623097d75b1890a56cc892
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Jan 24 11:34:31 2024 +0100
CAUSEWAY-3668: deprecates previous emails service config
---
.../core/config/CausewayConfiguration.java | 97 +++++++++++++++++++---
1 file changed, 85 insertions(+), 12 deletions(-)
diff --git a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
index 7f05a9e4e1..79e67cba29 100644
--- a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
+++ b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
@@ -57,8 +57,6 @@ import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
-import org.apache.causeway.applib.query.Query;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
@@ -77,6 +75,7 @@ import org.apache.causeway.applib.annotation.LabelPosition;
import org.apache.causeway.applib.annotation.PromptStyle;
import org.apache.causeway.applib.annotation.SemanticsOf;
import org.apache.causeway.applib.annotation.TableDecorator;
+import org.apache.causeway.applib.query.Query;
import org.apache.causeway.applib.services.i18n.Mode;
import org.apache.causeway.applib.services.iactn.Execution;
import org.apache.causeway.applib.services.publishing.spi.CommandSubscriber;
@@ -171,7 +170,6 @@ public class CausewayConfiguration {
* Or at least, from the {@link org.springframework.core.env.PropertySource} obtained from
* {@link ConfigurableEnvironment#getPropertySources()} that are also {@link EnumerablePropertySource}s.
* </p>
- * @return
*/
public Stream<String> streamConfigurationPropertyNames() {
MutablePropertySources propertySources = environment.getPropertySources();
@@ -189,7 +187,7 @@ public class CausewayConfiguration {
*
* @param configurationPropertyName - eg as obtained from {@link #streamConfigurationPropertyNames()}.
*/
- public Optional<String> valueOf(String configurationPropertyName) {
+ public Optional<String> valueOf(final String configurationPropertyName) {
return Optional.ofNullable(environment.getProperty(configurationPropertyName));
}
@@ -1813,18 +1811,49 @@ public class CausewayConfiguration {
private final Email email = new Email();
@Data
public static class Email {
+
+ @Deprecated
+ private int port = 587;
+
/**
* The port to use for sending email.
+ *
+ * @deprecated - ignored, instead use <code>spring.mail.port</code>
*/
- private int port = 587;
+ @Deprecated
+ @DeprecatedConfigurationProperty(replacement = "spring.mail.port")
+ public int getPort() {
+ return port;
+ }
+
+ @Deprecated
+ private int socketConnectionTimeout = 2000;
+
/**
* The maximum number of millseconds to wait to obtain a socket connection before timing out.
+ *
+ * @deprecated - ignored, instead use <code>spring.mail.properties.mail.smtp.connectiontimeout</code>
*/
- private int socketConnectionTimeout = 2000;
+ @Deprecated
+ @DeprecatedConfigurationProperty(replacement = "spring.mail.properties.mail.smtp.connectiontimeout")
+ public int getSocketConnectionTimeout() {
+ return socketConnectionTimeout;
+ }
+
+ @Deprecated
+ private int socketTimeout = 2000;
+
/**
* The maximum number of millseconds to wait to obtain a socket before timing out.
+ *
+ * @deprecated - ignored, instead use <code>spring.mail.properties.mail.smtp.timeout</code>
*/
- private int socketTimeout = 2000;
+ @Deprecated
+ @DeprecatedConfigurationProperty(replacement = "spring.mail.properties.mail.smtp.timeout")
+ public int getSocketTimeout() {
+ return socketTimeout;
+ }
+
/**
* If an email fails to send, whether to propagate the exception (meaning that potentially the end-user
* might see the exception), or whether instead to just indicate failure through the return value of
@@ -1859,6 +1888,10 @@ public class CausewayConfiguration {
private final Sender sender = new Sender();
@Data
public static class Sender {
+
+ @Deprecated
+ private String hostname;
+
/**
* Specifies the host running the SMTP service.
*
@@ -1866,16 +1899,37 @@ public class CausewayConfiguration {
* If not specified, then the value used depends upon the email implementation. The default
* implementation will use the <code>mail.smtp.host</code> system property.
* </p>
+ *
+ * @deprecated - now ignored, instead use <code>spring.mail.host</code>
*/
- private String hostname;
+ @Deprecated
+ @DeprecatedConfigurationProperty(replacement = "spring.mail.host")
+ public String getHostname() {
+ return hostname;
+ }
+
+ @Deprecated
+ private String username;
+
/**
* Specifies the username to use to connect to the SMTP service.
*
* <p>
* If not specified, then the sender's {@link #getAddress() email address} will be used instead.
* </p>
+ *
+ * @deprecated - now ignored, instead use <code>spring.mail.username</code>
*/
- private String username;
+ @Deprecated
+ @DeprecatedConfigurationProperty(replacement = "spring.mail.username")
+ public String getUsername() {
+ return username;
+ }
+
+ @Deprecated
+ private String password;
+
+
/**
* Specifies the password (corresponding to the {@link #getUsername() username} to connect to the
* SMTP service.
@@ -1884,8 +1938,15 @@ public class CausewayConfiguration {
* This configuration property is mandatory (for the default implementation of the
* {@link org.apache.causeway.applib.services.email.EmailService}, at least).
* </p>
+ *
+ * @deprecated - now ignored, instead use <code>spring.mail.password</code>
*/
- private String password;
+ @Deprecated
+ @DeprecatedConfigurationProperty(replacement = "spring.mail.password")
+ public String getPassword() {
+ return password;
+ }
+
/**
* Specifies the email address of the user sending the email.
*
@@ -1903,13 +1964,24 @@ public class CausewayConfiguration {
private String address;
}
+ @Deprecated
private final Tls tls = new Tls();
+ @Deprecated
@Data
public static class Tls {
+ @Deprecated
+ private boolean enabled = true;
+
/**
* Whether TLS encryption should be started (that is, <code>STARTTLS</code>).
+ *
+ * @deprecated - now ignored, instead use <code>spring.mail.javamail.properties.mail.smtp.starttls.enable</code>
*/
- private boolean enabled = true;
+ @Deprecated
+ @DeprecatedConfigurationProperty(replacement = "spring.mail.javamail.properties.mail.smtp.starttls.enable")
+ public boolean isEnabled() {
+ return enabled;
+ }
}
}
@@ -1939,6 +2011,7 @@ public class CausewayConfiguration {
*
* @deprecated - use instead <code>causeway.persistence.commons.repository-service.disable-auto-flush</code>
*/
+ @Deprecated
@DeprecatedConfigurationProperty(replacement = "causeway.persistence.commons.repository-service.disable-auto-flush")
public boolean isDisableAutoFlush() {
return disableAutoFlush;
@@ -3967,4 +4040,4 @@ public class CausewayConfiguration {
}
}
-}
+}
\ No newline at end of file
(causeway) 02/02: CAUSEWAY-3668: adds EmailServiceDefault IntegTest
Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 2f0364af66c7f5abe221eb4d5d1349d617869b08
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Jan 24 12:52:17 2024 +0100
CAUSEWAY-3668: adds EmailServiceDefault IntegTest
---
regressiontests/stable-config/pom.xml | 14 +++
.../config/EmailServiceDefault_IntegTest.java | 122 +++++++++++++++++++++
.../resources/application-config-test.properties | 9 ++
3 files changed, 145 insertions(+)
diff --git a/regressiontests/stable-config/pom.xml b/regressiontests/stable-config/pom.xml
index a0da351865..3ab5ff5fe4 100644
--- a/regressiontests/stable-config/pom.xml
+++ b/regressiontests/stable-config/pom.xml
@@ -41,11 +41,25 @@
</properties>
<dependencies>
+
<dependency>
<groupId>org.apache.causeway.regressiontests</groupId>
<artifactId>causeway-regressiontests-stable</artifactId>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.causeway.core</groupId>
+ <artifactId>causeway-core-runtimeservices</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>com.icegreen</groupId>
+ <artifactId>greenmail-junit5</artifactId>
+ <version>1.6.15</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
diff --git a/regressiontests/stable-config/src/test/java/org/apache/causeway/testdomain/config/EmailServiceDefault_IntegTest.java b/regressiontests/stable-config/src/test/java/org/apache/causeway/testdomain/config/EmailServiceDefault_IntegTest.java
new file mode 100644
index 0000000000..1ea2fc7fe6
--- /dev/null
+++ b/regressiontests/stable-config/src/test/java/org/apache/causeway/testdomain/config/EmailServiceDefault_IntegTest.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * http://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.apache.causeway.testdomain.config;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Properties;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import com.icegreen.greenmail.configuration.GreenMailConfiguration;
+import com.icegreen.greenmail.junit5.GreenMailExtension;
+import com.icegreen.greenmail.util.GreenMailUtil;
+import com.icegreen.greenmail.util.ServerSetupTest;
+
+import org.json.JSONException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.JavaMailSenderImpl;
+import org.springframework.test.context.TestPropertySource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.causeway.commons.collections.Can;
+import org.apache.causeway.commons.io.TextUtils;
+import org.apache.causeway.core.config.presets.CausewayPresets;
+import org.apache.causeway.core.runtimeservices.CausewayModuleCoreRuntimeServices;
+import org.apache.causeway.core.runtimeservices.email.EmailServiceDefault;
+import org.apache.causeway.testdomain.conf.Configuration_headless;
+
+@SpringBootTest(
+ classes = {
+ Configuration_headless.class,
+ CausewayModuleCoreRuntimeServices.class,
+ //JavaMailSenderImpl.class,
+ EmailServiceDefault_IntegTest.MailSenderProvider.class
+ }
+)
+@TestPropertySource({
+ "classpath:/application-config-test.properties",
+ CausewayPresets.UseLog4j2Test
+})
+class EmailServiceDefault_IntegTest {
+
+ @RegisterExtension
+ static GreenMailExtension greenMail = new GreenMailExtension(ServerSetupTest.SMTP)
+ .withConfiguration(GreenMailConfiguration.aConfig().withUser("user", "admin"))
+ .withPerMethodLifecycle(false);
+
+ @Autowired(required = true)
+ private EmailServiceDefault emailService;
+
+ @Configuration
+ static class MailSenderProvider {
+ @Bean
+ public JavaMailSender getJavaMailSender() {
+ JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
+ mailSender.setHost("127.0.0.1");
+ mailSender.setPort(3025);
+
+ mailSender.setUsername("user");
+ mailSender.setPassword("admin");
+
+ Properties props = mailSender.getJavaMailProperties();
+ props.put("mail.transport.protocol", "smtp");
+ props.put("mail.smtp.auth", "true");
+ props.put("mail.smtp.starttls.enable", "true");
+ props.put("mail.debug", "true");
+
+ return mailSender;
+ }
+ }
+
+ @Test
+ void should_send_email_to_user_with_green_mail_extension() throws JSONException, MessagingException {
+
+ boolean sent = emailService.send(
+ Arrays.asList("tester@spring.com"),
+ Collections.emptyList(),
+ Collections.emptyList(),
+ "Message from Java Mail Sender",
+ "Hello this is a simple email message");
+
+ assertTrue(sent);
+
+ MimeMessage receivedMessage = greenMail.getReceivedMessages()[0];
+
+ assertEquals(1, receivedMessage.getAllRecipients().length);
+ assertEquals("tester@spring.com", receivedMessage.getAllRecipients()[0].toString());
+ assertEquals("test.sender@hotmail.com", receivedMessage.getFrom()[0].toString());
+ assertEquals("Message from Java Mail Sender", receivedMessage.getSubject());
+
+ // extract payload from multiple parts
+ var bodyLines = TextUtils.readLines(GreenMailUtil.getBody(receivedMessage));
+ var filteredLines = bodyLines.filter(line->line.startsWith("Hello"));
+ assertEquals(Can.of("Hello this is a simple email message"), filteredLines);
+ }
+
+}
diff --git a/regressiontests/stable-config/src/test/resources/application-config-test.properties b/regressiontests/stable-config/src/test/resources/application-config-test.properties
index 132c8d5170..2c9a384f61 100644
--- a/regressiontests/stable-config/src/test/resources/application-config-test.properties
+++ b/regressiontests/stable-config/src/test/resources/application-config-test.properties
@@ -23,3 +23,12 @@
causeway.core.meta-model.introspector.policy=ANNOTATION_REQUIRED
+# spring powered mail, but does not seem to be picked up for testing
+spring.mail.host=127.0.0.1
+spring.mail.port=3025
+spring.mail.username=user
+spring.mail.password=admin
+spring.mail.properties.mail.smtp.auth=true
+spring.mail.properties.mail.smtp.starttls.enable=true
+
+causeway.core.runtime-services.email.sender.address=test.sender@hotmail.com
\ No newline at end of file