Skip to content

Commit

Permalink
More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Nov 2, 2023
1 parent 0ecf034 commit cbae230
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
<@emailMacros.msg "email.welcome.verify.1" />
</p>
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
<b><@emailMacros.msg "email.welcome.verify.2" /></b><br />
<@emailMacros.msg "email.welcome.verify.3" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,29 +32,39 @@ public class TemplateManagerTest {
private OrcidUrlManager orcidUrlManager;

@Resource(name = "messageSource")
private MessageSource messages;
private MessageSource messages;

@Test
public void testProcessTemplate() {
Map<String, Object> params = new HashMap<String, Object>();
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<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("primaryEmail", "[email protected]");
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);

Check failure on line 53 in orcid-core/src/test/java/org/orcid/core/manager/TemplateManagerTest.java

View workflow job for this annotation

GitHub Actions / orcid-core Unit Tests

org.orcid.core.manager.TemplateManagerTest ► testGenerateVerifyEmailNonPrimaryPlain

Failed test found in: TEST-org.orcid.core.manager.TemplateManagerTest.xml Error: org.junit.ComparisonFailure:
Raw output
org.junit.ComparisonFailure: 
expected:<...xeVJSMy9Scz0?lang=en[
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]> but was:<...xeVJSMy9Scz0?lang=en[                    
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
]>
	at org.orcid.core.manager.TemplateManagerTest.testGenerateVerifyEmailNonPrimaryPlain(TemplateManagerTest.java:53)
}

@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<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("primaryEmail", "[email protected]");
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());
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("isPrimary", true);
addStandardParams(templateParams);

// Generate body from template
Expand All @@ -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<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("primaryEmail", "[email protected]");
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<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("primaryEmail", "[email protected]");
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
Hi Josiah Carberry,<br/>
You need to verify your email address. </p>
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
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.</p>
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
<b>How do I verify my email address?</b><br />
Simply click the button below to sign into your ORCID record and complete verification. <table cellpadding="0" cellspacing="0" style="font-family: Helvetica, Arial, sans-serif; border-spacing: 0px; border-collapse: separate !important; border-radius: 4px; margin: 0 auto; margin-top:20px">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html>
<head>
<title>[ORCID] Reminder to verify your email address</title>
</head>
<body>
<div style="padding: 20px; padding-top: 10px; margin: auto;">
<img src="https://orcid.org/sites/all/themes/orcid/img/orcid-logo.png" alt="ORCID.org"/>
<hr />
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
Your ORCID iD: 4444-4444-4444-4446<br/>
Your ORCID record is <a href="https://testserver.orcid.org/4444-4444-4444-4446" target="orcid.blank">https://testserver.orcid.org/4444-4444-4444-4446</a>
</p>
<hr />
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
Hi Josiah Carberry,<br/>
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. </p>
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
<b>How do I verify my email address?</b><br />
Simply click the button below to sign into your ORCID record and complete verification. <table cellpadding="0" cellspacing="0" style="font-family: Helvetica, Arial, sans-serif; border-spacing: 0px; border-collapse: separate !important; border-radius: 4px; margin: 0 auto; margin-top:20px">
<tbody>
<tr>
<td style="border-spacing: 0px; border-collapse: collapse; line-height: 24px; font-size: 16px; border-radius: 4px; margin: 0;">
<a id="verificationButton"
href="http://testserver.orcid.org/verify-email/WnhVWGhYVk9lTng4bWdqaDl0azBXY3BmN1F4dHExOW95SnNxeVJSMy9Scz0?lang=en"
style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; text-decoration: none; border-radius: 4.8px; line-height: 25px; display: inline-block; font-weight: normal; white-space: nowrap; background-color: #31789B; color: #ffffff; padding: 8px 16px; border: 1px solid #31789B;"
>Verify your email address</a>
</td>
</tr>
</tbody>
</table>
</p>
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
Or, copy and paste the link below into your browser's address bar: <table cellpadding="0" cellspacing="0" style="font-family: arial, helvetica, sans-serif; border-spacing: 0px; border-collapse: separate !important; border-radius: 4px; margin: 0 auto; ">
<tbody>
<tr>
<td>
<p align="center" class="text-center" style="line-height: 24px; font-size: 16px; margin: 0; padding-bottom: 30px; padding-top: 20px; word-break: break-word;">
<a id="verificationUrl"
href="http://testserver.orcid.org/verify-email/WnhVWGhYVk9lTng4bWdqaDl0azBXY3BmN1F4dHExOW95SnNxeVJSMy9Scz0?lang=en"
target="orcid.blank"
>http://testserver.orcid.org/verify-email/WnhVWGhYVk9lTng4bWdqaDl0azBXY3BmN1F4dHExOW95SnNxeVJSMy9Scz0?lang=en</a>
</p>
</td>
</tr>
</tbody>
</table>
</p> <hr />
<p style="font-family: arial, helvetica, sans-serif; font-size: 16px; color: #494A4C;">
Please visit our <a href="https://info.orcid.org/researchers/" target="orcid.blank">researcher homepage</a> for more information on how to get the most out of your ORCID record.
</p>
<p>
<pre style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C;">
Warm Regards,
ORCID Support Team
<a href="https://support.orcid.org/hc/en-us" target="_blank" style="color: #2E7F9F;">https://support.orcid.org</a>
</pre>
</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C;">
You have received this email as a service announcement related to your ORCID Account.</p>
<p style="font-family: arial, helvetica, sans-serif;font-size: 15px;color: #494A4C;">
<small>
<a href="https://testserver.orcid.org/account" target="_blank" style="color: #2E7F9F;">email preferences</a>
| <a href="https://testserver.orcid.org/privacy-policy" target="_blank" style="color: #2E7F9F;">privacy policy</a>
| ORCID, Inc. | 10411 Motor City Drive, Suite 750, Bethesda, MD 20817, USA
| <a href="https://testserver.orcid.org" target="_blank" style="color: #2E7F9F;">ORCID.org</a>
</small>
</p>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -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 <a href="https://info.orcid.org/researchers/" target="orcid.blank">researcher homepage</a> 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

This file was deleted.

0 comments on commit cbae230

Please sign in to comment.