-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And add IT
- Loading branch information
Showing
6 changed files
with
154 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,5 +54,4 @@ jscholarship.hack.sword.statement.uri-replacement=https://jscholarship.library.j | |
|
||
pass.deposit.nihms.email.enabled=false | ||
pass.deposit.nihms.email.delay=30000 | ||
pass.deposit.nihms.email.from=${PASS_DEPOSIT_NIHMS_EMAIL_FROM:[email protected]} | ||
pass.deposit.pmc.repo.key=${PASS_DEPOSIT_PMC_REPO_KEY:pmc} | ||
pass.deposit.nihms.email.from=${PASS_DEPOSIT_NIHMS_EMAIL_FROM:[email protected]} |
122 changes: 122 additions & 0 deletions
122
...eposit-core/src/test/java/org/eclipse/pass/deposit/service/NihmsReceiveMailServiceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright 2023 Johns Hopkins University | ||
* | ||
* 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 | ||
* | ||
* 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.eclipse.pass.deposit.service; | ||
|
||
import static java.util.concurrent.TimeUnit.SECONDS; | ||
import static org.awaitility.Awaitility.await; | ||
import static org.eclipse.pass.deposit.service.NihmsReceiveMailService.NIHMS_DEP_STATUS_REF_PREFIX; | ||
import static org.eclipse.pass.deposit.util.ResourceTestUtil.findByNameAsString; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.List; | ||
|
||
import com.icegreen.greenmail.configuration.GreenMailConfiguration; | ||
import com.icegreen.greenmail.junit5.GreenMailExtension; | ||
import com.icegreen.greenmail.user.GreenMailUser; | ||
import com.icegreen.greenmail.util.GreenMailUtil; | ||
import com.icegreen.greenmail.util.ServerSetupTest; | ||
import jakarta.mail.internet.MimeMessage; | ||
import org.eclipse.pass.deposit.AbstractDepositSubmissionIT; | ||
import org.eclipse.pass.deposit.DepositApp; | ||
import org.eclipse.pass.deposit.provider.nihms.NihmsAssembler; | ||
import org.eclipse.pass.deposit.util.ResourceTestUtil; | ||
import org.eclipse.pass.support.client.PassClientSelector; | ||
import org.eclipse.pass.support.client.RSQL; | ||
import org.eclipse.pass.support.client.model.Deposit; | ||
import org.eclipse.pass.support.client.model.DepositStatus; | ||
import org.eclipse.pass.support.client.model.Submission; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.SpyBean; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
/** | ||
* @author Russ Poetker ([email protected]) | ||
*/ | ||
@SpringBootTest(classes = DepositApp.class) | ||
@TestPropertySource("classpath:test-application.properties") | ||
@TestPropertySource(properties = { | ||
"pass.deposit.nihms.email.enabled=true", | ||
"pass.deposit.nihms.email.delay=2000", | ||
"pass.deposit.nihms.email.from=test-from@localhost", | ||
"nihms.mail.host=localhost", | ||
"nihms.mail.port=3993", | ||
"nihms.mail.username=testnihms@localhost", | ||
"nihms.mail.password=testnihmspassword" | ||
|
||
}) | ||
public class NihmsReceiveMailServiceIT extends AbstractDepositSubmissionIT { | ||
|
||
@RegisterExtension | ||
static GreenMailExtension greenMail = new GreenMailExtension(ServerSetupTest.IMAPS) | ||
.withConfiguration(new GreenMailConfiguration().withUser("testnihms@localhost", "testnihmspassword")) | ||
.withPerMethodLifecycle(false); | ||
|
||
@SpyBean private NihmsReceiveMailService nihmsReceiveMailService; | ||
|
||
@Test | ||
void testHandleReceivedMail() throws Exception { | ||
// GIVEN | ||
Submission testSubmission = initSubmissionDeposit(); | ||
final String subject1 = "Bulk submission"; | ||
final String body1 = findByNameAsString("nihmsemail-success.html", this.getClass()) | ||
.replace("{test-submission-id}", testSubmission.getId()); | ||
MimeMessage message1 = GreenMailUtil.createTextEmail("testnihms@localhost", "test-from@localhost", | ||
subject1, body1, greenMail.getImaps().getServerSetup()); | ||
GreenMailUser user = greenMail.setUser("testnihms@localhost", "testnihmspassword"); | ||
|
||
// WHEN | ||
user.deliver(message1); | ||
|
||
// THEN | ||
// wait for email poller to run, every 2 seconds plus few seconds for processing | ||
await().pollDelay(5, SECONDS).until(() -> true); | ||
verify(nihmsReceiveMailService, times(1)) | ||
.handleReceivedMail(any()); | ||
PassClientSelector<Deposit> sel = new PassClientSelector<>(Deposit.class); | ||
sel.setFilter(RSQL.equals("submission.id", testSubmission.getId())); | ||
List<Deposit> actualDeposits = passClient.selectObjects(sel).getObjects(); | ||
assertEquals(1, actualDeposits.size()); | ||
Deposit pmcDeposit = actualDeposits.get(0); | ||
assertEquals(DepositStatus.ACCEPTED, pmcDeposit.getDepositStatus()); | ||
assertEquals(NIHMS_DEP_STATUS_REF_PREFIX + "test-nihms-id", pmcDeposit.getDepositStatusRef()); | ||
assertNull(pmcDeposit.getStatusMessage()); | ||
} | ||
|
||
private Submission initSubmissionDeposit() throws Exception { | ||
Submission submission = findSubmission(createSubmission( | ||
ResourceTestUtil.readSubmissionJson("sample2"))); | ||
submission.setSubmittedDate(ZonedDateTime.now()); | ||
passClient.updateObject(submission); | ||
triggerSubmission(submission); | ||
final Submission actualSubmission = passClient.getObject(Submission.class, submission.getId()); | ||
Deposit pmcDeposit = new Deposit(); | ||
pmcDeposit.setSubmission(actualSubmission); | ||
// There is only the pmc repo on this submission | ||
pmcDeposit.setRepository(actualSubmission.getRepositories().get(0)); | ||
pmcDeposit.setDepositStatus(DepositStatus.SUBMITTED); | ||
pmcDeposit.setDepositStatusRef(NihmsAssembler.NIHMS_PKG_DEP_REF_PREFIX + | ||
"nihms-native-2017-07_2023-10-23_13-10-30_" + actualSubmission.getId()); | ||
passClient.createObject(pmcDeposit); | ||
return actualSubmission; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
.../deposit-core/src/test/resources/org/eclipse/pass/deposit/service/nihmsemail-success.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE"> | ||
<title>Bulk submission (errors encountered)</title> | ||
</head> | ||
<body style='font-family:"Helvetica Neue", Helvetica, Arial, sans-serif'> | ||
<table class="table" style="background-color:transparent; margin-bottom:20px; max-width:100%; width:100%; border-collapse:collapse" width="100%"> | ||
<colgroup> | ||
<col span="1" style="width:50px"> | ||
<col span="1"> | ||
</colgroup> | ||
<tbody> | ||
<tr style="page-break-inside:avoid"> | ||
<td class="label label-info" style="border:0 solid #000; border-radius:0.25em; color:#fff; font-size:75%; font-weight:bold; line-height:1.428571; padding:8px; text-align:center; vertical-align:top; white-space:nowrap; background-color:#5bc0de; border-top:1px solid #ddd" align="center" valign="top" bgcolor="#5bc0de">INFO</td> | ||
<td class="message" style="border-top:1px solid #ddd; line-height:1.428571; padding:8px; vertical-align:top" valign="top">Package ID=nihms-native-2017-07_2023-10-23_13-10-30_{test-submission-id} for Manuscript ID test-nihms-id was submitted successfully.</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> |