From cbae2307b9f27e6be707200721e01dc6e853e9f1 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Thu, 2 Nov 2023 09:45:26 -0600 Subject: [PATCH] More unit tests --- .../how_do_i_verify_my_email_address_html.ftl | 3 - .../core/manager/TemplateManagerTest.java | 59 +++++++++++---- ...ample_verification_email_non_primary.html} | 2 - ...xample_verification_email_non_primary.txt} | 0 .../example_verification_email_primary.html | 71 +++++++++++++++++++ .../example_verification_email_primary.txt | 20 ++++++ .../org/orcid/core/template/test.ftl | 1 - 7 files changed, 135 insertions(+), 21 deletions(-) rename orcid-core/src/test/resources/org/orcid/core/manager/{example_verification_email_body.html => example_verification_email_non_primary.html} (93%) rename orcid-core/src/test/resources/org/orcid/core/manager/{example_verification_email_body.txt => example_verification_email_non_primary.txt} (100%) create mode 100644 orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_primary.html create mode 100644 orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_primary.txt delete mode 100644 orcid-core/src/test/resources/org/orcid/core/template/test.ftl diff --git a/orcid-core/src/main/resources/org/orcid/core/template/how_do_i_verify_my_email_address_html.ftl b/orcid-core/src/main/resources/org/orcid/core/template/how_do_i_verify_my_email_address_html.ftl index cee91dc8194..4d24229fd87 100644 --- a/orcid-core/src/main/resources/org/orcid/core/template/how_do_i_verify_my_email_address_html.ftl +++ b/orcid-core/src/main/resources/org/orcid/core/template/how_do_i_verify_my_email_address_html.ftl @@ -1,6 +1,3 @@ -

- <@emailMacros.msg "email.welcome.verify.1" /> -

<@emailMacros.msg "email.welcome.verify.2" />
<@emailMacros.msg "email.welcome.verify.3" /> diff --git a/orcid-core/src/test/java/org/orcid/core/manager/TemplateManagerTest.java b/orcid-core/src/test/java/org/orcid/core/manager/TemplateManagerTest.java index c36cc84473d..2b21ae373b3 100644 --- a/orcid-core/src/test/java/org/orcid/core/manager/TemplateManagerTest.java +++ b/orcid-core/src/test/java/org/orcid/core/manager/TemplateManagerTest.java @@ -1,7 +1,6 @@ package org.orcid.core.manager; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -33,21 +32,30 @@ public class TemplateManagerTest { private OrcidUrlManager orcidUrlManager; @Resource(name = "messageSource") - private MessageSource messages; + private MessageSource messages; @Test - public void testProcessTemplate() { - Map params = new HashMap(); - params.put("name", "Declan"); - params.put("word", "cucumber"); - String result = templateManager.processTemplate("test.ftl", params); - assertNotNull(result); - assertEquals("Hello, Declan. Did you say cucumber?", result); - } + public void testGenerateVerifyEmailNonPrimaryPlain() throws IOException { + String expectedText = IOUtils.toString(getClass().getResourceAsStream("example_verification_email_non_primary.txt"), StandardCharsets.UTF_8); + + Map templateParams = new HashMap(); + templateParams.put("primaryEmail", "josiah_carberry@brown.edu"); + templateParams.put("userName", "Josiah Carberry"); + templateParams.put("subject", "[ORCID] Reminder to verify your email address"); + templateParams.put("verificationUrl", "http://testserver.orcid.org/verify-email/WnhVWGhYVk9lTng4bWdqaDl0azBXY3BmN1F4dHExOW95SnNxeVJSMy9Scz0"); + templateParams.put("orcidId", "4444-4444-4444-4446"); + templateParams.put("baseUri", orcidUrlManager.getBaseUrl()); + addStandardParams(templateParams); + // Generate body from template + String body = templateManager.processTemplate("verification_email_v2.ftl", templateParams); + + assertEquals(expectedText, body); + } + @Test - public void testGenerateVerifyEmailPlainText() throws IOException { - String expectedText = IOUtils.toString(getClass().getResourceAsStream("example_verification_email_body.txt"), StandardCharsets.UTF_8); + public void testGenerateVerifyEmailPrimaryPlain() throws IOException { + String expectedText = IOUtils.toString(getClass().getResourceAsStream("example_verification_email_primary.txt"), StandardCharsets.UTF_8); Map templateParams = new HashMap(); templateParams.put("primaryEmail", "josiah_carberry@brown.edu"); @@ -55,7 +63,8 @@ public void testGenerateVerifyEmailPlainText() throws IOException { templateParams.put("subject", "[ORCID] Reminder to verify your email address"); templateParams.put("verificationUrl", "http://testserver.orcid.org/verify-email/WnhVWGhYVk9lTng4bWdqaDl0azBXY3BmN1F4dHExOW95SnNxeVJSMy9Scz0"); templateParams.put("orcidId", "4444-4444-4444-4446"); - templateParams.put("baseUri", orcidUrlManager.getBaseUrl()); + templateParams.put("baseUri", orcidUrlManager.getBaseUrl()); + templateParams.put("isPrimary", true); addStandardParams(templateParams); // Generate body from template @@ -65,8 +74,27 @@ public void testGenerateVerifyEmailPlainText() throws IOException { } @Test - public void testGenerateVerifyEmailHtml() throws IOException { - String expectedHtml = IOUtils.toString(getClass().getResourceAsStream("example_verification_email_body.html"), StandardCharsets.UTF_8); + public void testGenerateVerifyEmailNonPrimaryHtml() throws IOException { + String expectedHtml = IOUtils.toString(getClass().getResourceAsStream("example_verification_email_non_primary.html"), StandardCharsets.UTF_8); + + Map templateParams = new HashMap(); + templateParams.put("primaryEmail", "josiah_carberry@brown.edu"); + templateParams.put("userName", "Josiah Carberry"); + templateParams.put("subject", "[ORCID] Reminder to verify your email address"); + templateParams.put("verificationUrl", "http://testserver.orcid.org/verify-email/WnhVWGhYVk9lTng4bWdqaDl0azBXY3BmN1F4dHExOW95SnNxeVJSMy9Scz0"); + templateParams.put("orcidId", "4444-4444-4444-4446"); + templateParams.put("baseUri", orcidUrlManager.getBaseUrl()); + addStandardParams(templateParams); + + // Generate body from template + String htmlBody = templateManager.processTemplate("verification_email_html_v2.ftl", templateParams); + + assertEquals(expectedHtml, htmlBody); + } + + @Test + public void testGenerateVerifyEmailPrimaryHtml() throws IOException { + String expectedHtml = IOUtils.toString(getClass().getResourceAsStream("example_verification_email_primary.html"), StandardCharsets.UTF_8); Map templateParams = new HashMap(); templateParams.put("primaryEmail", "josiah_carberry@brown.edu"); @@ -75,6 +103,7 @@ public void testGenerateVerifyEmailHtml() throws IOException { templateParams.put("verificationUrl", "http://testserver.orcid.org/verify-email/WnhVWGhYVk9lTng4bWdqaDl0azBXY3BmN1F4dHExOW95SnNxeVJSMy9Scz0"); templateParams.put("orcidId", "4444-4444-4444-4446"); templateParams.put("baseUri", orcidUrlManager.getBaseUrl()); + templateParams.put("isPrimary", true); addStandardParams(templateParams); // Generate body from template diff --git a/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_body.html b/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_non_primary.html similarity index 93% rename from orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_body.html rename to orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_non_primary.html index 4afe421856c..e183c954857 100644 --- a/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_body.html +++ b/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_non_primary.html @@ -15,8 +15,6 @@

Hi Josiah Carberry,
You need to verify your email address.

-

- Verifying your email address unlocks advanced editing features in your ORCID record. Until then you will only be able to manage your names and email addresses in your ORCID record.

How do I verify my email address?
Simply click the button below to sign into your ORCID record and complete verification. diff --git a/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_body.txt b/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_non_primary.txt similarity index 100% rename from orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_body.txt rename to orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_non_primary.txt diff --git a/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_primary.html b/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_primary.html new file mode 100644 index 00000000000..cfa14ee28ff --- /dev/null +++ b/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_primary.html @@ -0,0 +1,71 @@ + + + + [ORCID] Reminder to verify your email address + + +
+ ORCID.org +
+

+ Your ORCID iD: 4444-4444-4444-4446
+ Your ORCID record is https://testserver.orcid.org/4444-4444-4444-4446 +

+
+

+ Hi Josiah Carberry,
+This is a friendly reminder to verify your email address in your ORCID record so that you can unlock advanced editing features in your ORCID record. Until then, you will only be able to manage your names and email addresses in your ORCID record.

+

+ How do I verify my email address?
+Simply click the button below to sign into your ORCID record and complete verification.

+ + + + + +
+ Verify your email address +
+

+

+Or, copy and paste the link below into your browser's address bar: + + + + + +
+

+ http://testserver.orcid.org/verify-email/WnhVWGhYVk9lTng4bWdqaDl0azBXY3BmN1F4dHExOW95SnNxeVJSMy9Scz0?lang=en +

+
+


+

+ Please visit our researcher homepage for more information on how to get the most out of your ORCID record. +

+

+

+Warm Regards,
+ORCID Support Team
+https://support.orcid.org
+
+

+

+You have received this email as a service announcement related to your ORCID Account.

+

+ +email preferences +| privacy policy +| ORCID, Inc. | 10411 Motor City Drive, Suite 750, Bethesda, MD 20817, USA +| ORCID.org + +

+ + + diff --git a/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_primary.txt b/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_primary.txt new file mode 100644 index 00000000000..b59adc89620 --- /dev/null +++ b/orcid-core/src/test/resources/org/orcid/core/manager/example_verification_email_primary.txt @@ -0,0 +1,20 @@ +Your ORCID iD: 4444-4444-4444-4446 +Your ORCID record is https://testserver.orcid.org/4444-4444-4444-4446 + +Hi Josiah Carberry, +This is a friendly reminder to verify your email address in your ORCID record so that you can unlock advanced editing features in your ORCID record. Until then, you will only be able to manage your names and email addresses in your ORCID record. + +How do I verify my email address? +Or, copy and paste the link below into your browser's address bar: +http://testserver.orcid.org/verify-email/WnhVWGhYVk9lTng4bWdqaDl0azBXY3BmN1F4dHExOW95SnNxeVJSMy9Scz0?lang=en +Please visit our researcher homepage for more information on how to get the most out of your ORCID record. +Warm Regards, +ORCID Support Team +https://support.orcid.org + +You have received this email as a service announcement related to your ORCID Account. +email preferences (https://testserver.orcid.org/account) +privacy policy (https://testserver.orcid.org/privacy-policy) +ORCID, Inc. +10411 Motor City Drive, Suite 750, Bethesda, MD 20817, USA +https://testserver.orcid.org \ No newline at end of file diff --git a/orcid-core/src/test/resources/org/orcid/core/template/test.ftl b/orcid-core/src/test/resources/org/orcid/core/template/test.ftl deleted file mode 100644 index e85c0386479..00000000000 --- a/orcid-core/src/test/resources/org/orcid/core/template/test.ftl +++ /dev/null @@ -1 +0,0 @@ -Hello, ${name}. Did you say ${word}? \ No newline at end of file