From c5b7f2494035060b9288c630e78de32d55160b52 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Wed, 17 Apr 2024 15:23:25 -0400 Subject: [PATCH 1/7] Add deployment test data service --- .../service/DeploymentTestDataService.java | 143 ++++++++++ .../src/main/resources/application.properties | 3 + .../service/DeploymentTestDataServiceIT.java | 250 ++++++++++++++++++ 3 files changed, 396 insertions(+) create mode 100644 pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java create mode 100644 pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java new file mode 100644 index 00000000..fb4875e9 --- /dev/null +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java @@ -0,0 +1,143 @@ +/* + * Copyright 2018 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 java.io.IOException; +import java.time.ZonedDateTime; +import java.util.List; + +import org.eclipse.pass.support.client.ModelUtil; +import org.eclipse.pass.support.client.PassClient; +import org.eclipse.pass.support.client.PassClientSelector; +import org.eclipse.pass.support.client.RSQL; +import org.eclipse.pass.support.client.model.AwardStatus; +import org.eclipse.pass.support.client.model.Deposit; +import org.eclipse.pass.support.client.model.Funder; +import org.eclipse.pass.support.client.model.Grant; +import org.eclipse.pass.support.client.model.Journal; +import org.eclipse.pass.support.client.model.PassEntity; +import org.eclipse.pass.support.client.model.Policy; +import org.eclipse.pass.support.client.model.Submission; +import org.eclipse.pass.support.client.model.User; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class DeploymentTestDataService { + private static final Logger LOG = LoggerFactory.getLogger(DeploymentTestDataService.class); + + private final PassClient passClient; + + @Value("${pass.test.data.policy.title}") + private String testPolicyTitle; + + @Value("${pass.test.data.user.email}") + private String testUserEmail; + + @Autowired + public DeploymentTestDataService(PassClient passClient) { + this.passClient = passClient; + } + + public void processTestData() throws IOException { + LOG.warn("Deployment Test Data Service running..."); + PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); + grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + List testGrants = passClient.streamObjects(grantSelector).toList(); + Grant testGrant = testGrants.isEmpty() ? createTestGrantData() : testGrants.get(0); + deleteTestSubmissions(testGrant); + } + + private void deleteTestSubmissions(Grant testGrant) throws IOException { + LOG.warn("Deleting Test Submissions"); + ZonedDateTime submissionToDate = ZonedDateTime.now().minusDays(1); + PassClientSelector testSubmissionSelector = new PassClientSelector<>(Submission.class); + testSubmissionSelector.setFilter(RSQL.and( + RSQL.equals("grants.id", testGrant.getId()), + RSQL.lte("submittedDate", ModelUtil.dateTimeFormatter().format(submissionToDate)) + )); + testSubmissionSelector.setInclude("publication"); + List testSubmissions = passClient.streamObjects(testSubmissionSelector).toList(); + testSubmissions.forEach(testSubmission -> { + try { + PassClientSelector testDepositSelector = new PassClientSelector<>(Deposit.class); + testDepositSelector.setFilter(RSQL.equals("submission.id", testSubmission.getId())); + testDepositSelector.setInclude("repositoryCopy"); + List testDeposits = passClient.streamObjects(testDepositSelector).toList(); + testDeposits.forEach(testDeposit -> { + deleteObject(testDeposit); + deleteObject(testDeposit.getRepositoryCopy()); + }); + deleteObject(testSubmission); + deleteObject(testSubmission.getPublication()); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + LOG.warn("Deleted {} Test Submissions", testSubmissions.size()); + } + + private void deleteObject(PassEntity entity) { + try { + passClient.deleteObject(entity); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private Grant createTestGrantData() throws IOException { + LOG.warn("Creating Test Grant Data"); + Journal testJournal = new Journal(); + testJournal.setJournalName("PASS_E2E_TEST_JOURNAL"); + testJournal.setIssns(List.of("Print:test-fake")); + passClient.createObject(testJournal); + + PassClientSelector policySelector = new PassClientSelector<>(Policy.class); + policySelector.setFilter(RSQL.equals("title", testPolicyTitle)); + List testPolicies = passClient.streamObjects(policySelector).toList(); + Policy testPolicy = testPolicies.get(0); + + Funder testFunder = new Funder(); + testFunder.setLocalKey("E2E_TEST_FUNDER_LK"); + testFunder.setName("PASS_E2E_TEST_FUNDER"); + testFunder.setPolicy(testPolicy); + passClient.createObject(testFunder); + + Grant testGrant = new Grant(); + testGrant.setProjectName("PASS_E2E_TEST_GRANT"); + testGrant.setAwardNumber("TEST_E2E_AWD_NUM"); + testGrant.setLocalKey("PASS_E2E_TEST_GRANT_LK"); + testGrant.setAwardDate(ZonedDateTime.parse("2020-02-01T00:00:00Z")); + testGrant.setStartDate(ZonedDateTime.parse("2020-01-01T00:00:00Z")); + testGrant.setEndDate(ZonedDateTime.parse("2088-01-01T00:00:00Z")); + testGrant.setAwardStatus(AwardStatus.ACTIVE); + testGrant.setDirectFunder(testFunder); + testGrant.setPrimaryFunder(testFunder); + + PassClientSelector userSelector = new PassClientSelector<>(User.class); + userSelector.setFilter(RSQL.equals("email", testUserEmail)); + List testUsers = passClient.streamObjects(userSelector).toList(); + User testUser = testUsers.get(0); + testGrant.setPi(testUser); + + passClient.createObject(testGrant); + return testGrant; + } + +} diff --git a/pass-deposit-services/deposit-core/src/main/resources/application.properties b/pass-deposit-services/deposit-core/src/main/resources/application.properties index 28651603..cdddd1c1 100644 --- a/pass-deposit-services/deposit-core/src/main/resources/application.properties +++ b/pass-deposit-services/deposit-core/src/main/resources/application.properties @@ -66,3 +66,6 @@ pass.deposit.nihms.email.enabled=false pass.deposit.nihms.email.delay=720000 pass.deposit.nihms.email.auth=${NIHMS_MAIL_AUTH:LOGIN} pass.deposit.nihms.email.from=${PASS_DEPOSIT_NIHMS_EMAIL_FROM:nihms-help@ncbi.nlm.nih.gov} + +pass.test.data.policy.title=${TEST_DATA_POLICY_TITLE:} +pass.test.data.user.email=${TEST_DATA_USER_EMAIL:} diff --git a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java new file mode 100644 index 00000000..a400d3f3 --- /dev/null +++ b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java @@ -0,0 +1,250 @@ +/* + * 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 org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.io.IOException; +import java.time.ZonedDateTime; +import java.util.List; + +import org.eclipse.pass.support.client.PassClientSelector; +import org.eclipse.pass.support.client.RSQL; +import org.eclipse.pass.support.client.model.AwardStatus; +import org.eclipse.pass.support.client.model.Deposit; +import org.eclipse.pass.support.client.model.DepositStatus; +import org.eclipse.pass.support.client.model.Grant; +import org.eclipse.pass.support.client.model.PassEntity; +import org.eclipse.pass.support.client.model.Policy; +import org.eclipse.pass.support.client.model.Publication; +import org.eclipse.pass.support.client.model.Repository; +import org.eclipse.pass.support.client.model.RepositoryCopy; +import org.eclipse.pass.support.client.model.Submission; +import org.eclipse.pass.support.client.model.User; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.TestPropertySource; + +/** + * @author Russ Poetker (rpoetke1@jh.edu) + */ +@TestPropertySource(properties = { + "pass.test.data.policy.title=test-policy-title", + "pass.test.data.user.email=test-user-email@foo" +}) +public class DeploymentTestDataServiceIT extends AbstractDepositIT { + + @Autowired private DeploymentTestDataService deploymentTestDataService; + + @BeforeEach + public void initPolicyAndUser() throws IOException { + PassClientSelector selector = new PassClientSelector<>(Policy.class); + selector.setFilter(RSQL.equals("title", "test-policy-title")); + List testPolicies = passClient.streamObjects(selector).toList(); + if (testPolicies.isEmpty()) { + Policy policy = new Policy(); + policy.setTitle("test-policy-title"); + passClient.createObject(policy); + User testUser = new User(); + testUser.setFirstName("test"); + testUser.setLastName("user"); + testUser.setEmail("test-user-email@foo"); + passClient.createObject(testUser); + } + } + + @AfterEach + public void cleanUp() throws IOException { + PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); + grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + List testGrants = passClient.streamObjects(grantSelector).toList(); + testGrants.forEach(this::deleteObject); + PassClientSelector depositSelector = new PassClientSelector<>(Deposit.class); + List testDeposits = passClient.streamObjects(depositSelector).toList(); + testDeposits.forEach(this::deleteObject); + PassClientSelector repoCopySelector = new PassClientSelector<>(RepositoryCopy.class); + List testRepoCopies = passClient.streamObjects(repoCopySelector).toList(); + testRepoCopies.forEach(this::deleteObject); + PassClientSelector submissionSelector = new PassClientSelector<>(Submission.class); + List testSubmissions = passClient.streamObjects(submissionSelector).toList(); + testSubmissions.forEach(this::deleteObject); + PassClientSelector publicationSelector = new PassClientSelector<>(Publication.class); + List testPublications = passClient.streamObjects(publicationSelector).toList(); + testPublications.forEach(this::deleteObject); + } + + private void deleteObject(PassEntity entity) { + try { + passClient.deleteObject(entity); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testProcessData_TestGrantDataCreatedIfNotExist() throws Exception { + // WHEN + deploymentTestDataService.processTestData(); + + // THEN + PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); + grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + grantSelector.setInclude("pi", "directFunder", "primaryFunder"); + List testGrants = passClient.streamObjects(grantSelector).toList(); + assertEquals(1, testGrants.size()); + Grant actualTestGrant = testGrants.get(0); + assertEquals("PASS_E2E_TEST_GRANT", actualTestGrant.getProjectName()); + assertEquals(AwardStatus.ACTIVE, actualTestGrant.getAwardStatus()); + assertEquals("test-user-email@foo", actualTestGrant.getPi().getEmail()); + assertEquals("PASS_E2E_TEST_FUNDER", actualTestGrant.getDirectFunder().getName()); + assertEquals("PASS_E2E_TEST_FUNDER", actualTestGrant.getPrimaryFunder().getName()); + } + + @Test + public void testProcessData_DoesNotTestGrantDataCreatedIfExist() throws Exception { + // GIVEN + Grant testGrant = new Grant(); + testGrant.setProjectName("PASS_E2E_TEST_GRANT"); + testGrant.setAwardStatus(AwardStatus.ACTIVE); + passClient.createObject(testGrant); + Mockito.reset(passClient); + + // WHEN + deploymentTestDataService.processTestData(); + + // THEN + PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); + grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + List testGrants = passClient.streamObjects(grantSelector).toList(); + assertEquals(1, testGrants.size()); + Grant actualTestGrant = testGrants.get(0); + assertEquals(testGrant.getId(), actualTestGrant.getId()); + assertEquals("PASS_E2E_TEST_GRANT", actualTestGrant.getProjectName()); + assertEquals(AwardStatus.ACTIVE, actualTestGrant.getAwardStatus()); + verify(passClient, times(0)).createObject(any()); + } + + @Test + public void testProcessData_DeleteTestSubmissionsForTestGrant() throws Exception { + // GIVEN + Grant testGrant = new Grant(); + testGrant.setProjectName("PASS_E2E_TEST_GRANT"); + testGrant.setAwardStatus(AwardStatus.ACTIVE); + passClient.createObject(testGrant); + initSubmissionAndDeposits(testGrant); + + // WHEN + deploymentTestDataService.processTestData(); + + // THEN + PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); + grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + List testGrants = passClient.streamObjects(grantSelector).toList(); + assertEquals(1, testGrants.size()); + Grant actualTestGrant = testGrants.get(0); + assertEquals("PASS_E2E_TEST_GRANT", actualTestGrant.getProjectName()); + assertEquals(AwardStatus.ACTIVE, actualTestGrant.getAwardStatus()); + PassClientSelector depositSelector = new PassClientSelector<>(Deposit.class); + List testDeposits = passClient.streamObjects(depositSelector).toList(); + assertTrue(testDeposits.isEmpty()); + PassClientSelector repoCopySelector = new PassClientSelector<>(RepositoryCopy.class); + List testRepoCopies = passClient.streamObjects(repoCopySelector).toList(); + assertTrue(testRepoCopies.isEmpty()); + PassClientSelector submissionSelector = new PassClientSelector<>(Submission.class); + List testSubmissions = passClient.streamObjects(submissionSelector).toList(); + assertTrue(testSubmissions.isEmpty()); + PassClientSelector publicationSelector = new PassClientSelector<>(Publication.class); + List testPublications = passClient.streamObjects(publicationSelector).toList(); + assertTrue(testPublications.isEmpty()); + } + + @Test + public void testProcessData_DoesNotDeleteTestSubmissionsForOtherGrant() throws Exception { + // GIVEN + Grant testGrant = new Grant(); + testGrant.setProjectName("Some Other Grant"); + testGrant.setAwardStatus(AwardStatus.ACTIVE); + passClient.createObject(testGrant); + Submission testSubmission = initSubmissionAndDeposits(testGrant); + + // WHEN + deploymentTestDataService.processTestData(); + + // THEN + PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); + grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + List testGrants = passClient.streamObjects(grantSelector).toList(); + assertEquals(1, testGrants.size()); + Grant actualTestGrant = testGrants.get(0); + assertEquals("PASS_E2E_TEST_GRANT", actualTestGrant.getProjectName()); + assertEquals(AwardStatus.ACTIVE, actualTestGrant.getAwardStatus()); + PassClientSelector depositSelector = new PassClientSelector<>(Deposit.class); + List testDeposits = passClient.streamObjects(depositSelector).toList(); + assertFalse(testDeposits.isEmpty()); + PassClientSelector repoCopySelector = new PassClientSelector<>(RepositoryCopy.class); + List testRepoCopies = passClient.streamObjects(repoCopySelector).toList(); + assertFalse(testRepoCopies.isEmpty()); + PassClientSelector publicationSelector = new PassClientSelector<>(Publication.class); + List testPublications = passClient.streamObjects(publicationSelector).toList(); + assertFalse(testPublications.isEmpty()); + PassClientSelector submissionSelector = new PassClientSelector<>(Submission.class); + submissionSelector.setInclude("grants"); + List testSubmissions = passClient.streamObjects(submissionSelector).toList(); + assertFalse(testSubmissions.isEmpty()); + Submission actualSubmission = testSubmissions.get(0); + assertEquals(testSubmission.getId(), actualSubmission.getId()); + } + + private Submission initSubmissionAndDeposits(Grant testGrant) throws Exception { + Submission submission = new Submission(); + submission.setGrants(List.of(testGrant)); + submission.setSubmittedDate(ZonedDateTime.now().minusDays(2)); + passClient.createObject(submission); + + Repository repository = new Repository(); + repository.setName("test-repository"); + passClient.createObject(repository); + + Publication publication = new Publication(); + publication.setTitle("test-publication"); + passClient.createObject(publication); + + RepositoryCopy repositoryCopy = new RepositoryCopy(); + repositoryCopy.setRepository(repository); + repositoryCopy.setPublication(publication); + passClient.createObject(repositoryCopy); + + Deposit j10pDeposit = new Deposit(); + j10pDeposit.setSubmission(submission); + j10pDeposit.setDepositStatus(DepositStatus.SUBMITTED); + j10pDeposit.setRepositoryCopy(repositoryCopy); + passClient.createObject(j10pDeposit); + + submission.setPublication(publication); + passClient.updateObject(submission); + + return submission; + } + +} From d351c571addc4f2098c0fabe487e79f186c312f3 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Wed, 17 Apr 2024 15:51:02 -0400 Subject: [PATCH 2/7] Add deployment test data job --- .../service/DeploymentTestDataService.java | 2 +- .../support/jobs/DeploymentTestDataJob.java | 53 +++++++++++++++++++ .../src/main/resources/application.properties | 4 ++ .../service/DeploymentTestDataServiceIT.java | 2 +- .../support/jobs/ScheduledJobsTest.java | 16 +++++- 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/jobs/DeploymentTestDataJob.java diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java index fb4875e9..563b6494 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Johns Hopkins University + * Copyright 2024 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. diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/jobs/DeploymentTestDataJob.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/jobs/DeploymentTestDataJob.java new file mode 100644 index 00000000..d5eeb0c0 --- /dev/null +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/support/jobs/DeploymentTestDataJob.java @@ -0,0 +1,53 @@ +/* + * Copyright 2024 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.support.jobs; + +import org.eclipse.pass.deposit.service.DeploymentTestDataService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@ConditionalOnExpression( + "'${pass.test.data.job.enabled}'=='true' and '${pass.deposit.jobs.disabled}'=='false'" +) +@Component +public class DeploymentTestDataJob { + + private static final Logger LOG = LoggerFactory.getLogger(DeploymentTestDataJob.class); + + private final DeploymentTestDataService deploymentTestDataService; + + public DeploymentTestDataJob(DeploymentTestDataService deploymentTestDataService) { + this.deploymentTestDataService = deploymentTestDataService; + } + + @Scheduled( + fixedDelayString = "${pass.test.data.job.interval-ms}", + initialDelayString = "${pass.deposit.jobs.3.init.delay}" + ) + public void processDeploymentTestData() { + LOG.warn("Starting {}", this.getClass().getSimpleName()); + try { + deploymentTestDataService.processTestData(); + } catch (Exception e) { + LOG.error("DeploymentTestDataJob execution failed: {}", e.getMessage(), e); + } + LOG.warn("Finished {}", this.getClass().getSimpleName()); + } + +} diff --git a/pass-deposit-services/deposit-core/src/main/resources/application.properties b/pass-deposit-services/deposit-core/src/main/resources/application.properties index cdddd1c1..b5c19de7 100644 --- a/pass-deposit-services/deposit-core/src/main/resources/application.properties +++ b/pass-deposit-services/deposit-core/src/main/resources/application.properties @@ -48,6 +48,7 @@ pass.deposit.jobs.disabled=false pass.deposit.jobs.default-interval-ms=600000 pass.deposit.jobs.1.init.delay=5000 pass.deposit.jobs.2.init.delay=10000 +pass.deposit.jobs.3.init.delay=20000 jscholarship.hack.sword.statement.uri-prefix=http://dspace-prod.mse.jhu.edu:8080/swordv2/ jscholarship.hack.sword.statement.uri-replacement=https://jscholarship.library.jhu.edu/swordv2/ @@ -67,5 +68,8 @@ pass.deposit.nihms.email.delay=720000 pass.deposit.nihms.email.auth=${NIHMS_MAIL_AUTH:LOGIN} pass.deposit.nihms.email.from=${PASS_DEPOSIT_NIHMS_EMAIL_FROM:nihms-help@ncbi.nlm.nih.gov} +pass.test.data.job.enabled=false +# Run every 12 hours +pass.test.data.job.interval-ms=43200000 pass.test.data.policy.title=${TEST_DATA_POLICY_TITLE:} pass.test.data.user.email=${TEST_DATA_USER_EMAIL:} diff --git a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java index a400d3f3..9fb0bf6d 100644 --- a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java +++ b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Johns Hopkins University + * Copyright 2024 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. diff --git a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/support/jobs/ScheduledJobsTest.java b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/support/jobs/ScheduledJobsTest.java index 3aef6df9..8e583a37 100644 --- a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/support/jobs/ScheduledJobsTest.java +++ b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/support/jobs/ScheduledJobsTest.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.verify; import org.eclipse.pass.deposit.DepositApp; +import org.eclipse.pass.deposit.service.DeploymentTestDataService; import org.eclipse.pass.deposit.service.DepositUpdater; import org.eclipse.pass.deposit.service.SubmissionStatusUpdater; import org.junit.jupiter.api.Test; @@ -34,14 +35,18 @@ @TestPropertySource("classpath:test-application.properties") @TestPropertySource(properties = { "pass.deposit.jobs.disabled=false", + "pass.test.data.job.enabled=true", "pass.deposit.jobs.default-interval-ms=1500", + "pass.test.data.job.interval-ms=1500", "pass.deposit.jobs.1.init.delay=50", - "pass.deposit.jobs.2.init.delay=100" + "pass.deposit.jobs.2.init.delay=100", + "pass.deposit.jobs.3.init.delay=120" }) public class ScheduledJobsTest { @MockBean private SubmissionStatusUpdater submissionStatusUpdater; @MockBean private DepositUpdater depositUpdater; + @MockBean private DeploymentTestDataService deploymentTestDataService; @Test void testDepositUpdaterJob() { @@ -61,4 +66,13 @@ void testSubmissionStatusUpdaterJob() { }); } + @Test + void testDeploymentTestDataJob() { + // GIVEN/WHEN + // deploymentTestDataService.processTestData() will be called from Scheduled method in job + await().atMost(3, SECONDS).untilAsserted(() -> { + verify(deploymentTestDataService).processTestData(); + }); + } + } From 9528f5eb16b6d4b302d45b087a85e53049a2f1c9 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Thu, 18 Apr 2024 10:06:23 -0400 Subject: [PATCH 3/7] Add more test verifications --- .../service/DeploymentTestDataServiceIT.java | 54 ++++++++++++------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java index 9fb0bf6d..43b485c4 100644 --- a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java +++ b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java @@ -16,7 +16,6 @@ package org.eclipse.pass.deposit.service; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; @@ -182,38 +181,55 @@ public void testProcessData_DeleteTestSubmissionsForTestGrant() throws Exception @Test public void testProcessData_DoesNotDeleteTestSubmissionsForOtherGrant() throws Exception { // GIVEN - Grant testGrant = new Grant(); - testGrant.setProjectName("Some Other Grant"); - testGrant.setAwardStatus(AwardStatus.ACTIVE); - passClient.createObject(testGrant); - Submission testSubmission = initSubmissionAndDeposits(testGrant); + Grant deploymentGrant = new Grant(); + deploymentGrant.setProjectName("PASS_E2E_TEST_GRANT"); + deploymentGrant.setAwardStatus(AwardStatus.ACTIVE); + passClient.createObject(deploymentGrant); + initSubmissionAndDeposits(deploymentGrant); + + Grant testOtherGrant = new Grant(); + testOtherGrant.setProjectName("Some Other Grant"); + testOtherGrant.setAwardStatus(AwardStatus.ACTIVE); + passClient.createObject(testOtherGrant); + Submission testOtherSubmission = initSubmissionAndDeposits(testOtherGrant); // WHEN deploymentTestDataService.processTestData(); // THEN - PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); + final PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); - List testGrants = passClient.streamObjects(grantSelector).toList(); - assertEquals(1, testGrants.size()); - Grant actualTestGrant = testGrants.get(0); + List actualTestGrants = passClient.streamObjects(grantSelector).toList(); + assertEquals(1, actualTestGrants.size()); + Grant actualTestGrant = actualTestGrants.get(0); assertEquals("PASS_E2E_TEST_GRANT", actualTestGrant.getProjectName()); assertEquals(AwardStatus.ACTIVE, actualTestGrant.getAwardStatus()); + + PassClientSelector submissionSelector = new PassClientSelector<>(Submission.class); + List testSubmissions = passClient.streamObjects(submissionSelector).toList(); + assertEquals(1, testSubmissions.size()); + Submission actualSubmission = testSubmissions.get(0); + assertEquals(testOtherSubmission.getId(), actualSubmission.getId()); + assertEquals(testOtherGrant.getId(), actualSubmission.getGrants().get(0).getId()); + PassClientSelector depositSelector = new PassClientSelector<>(Deposit.class); List testDeposits = passClient.streamObjects(depositSelector).toList(); - assertFalse(testDeposits.isEmpty()); + assertEquals(1, testDeposits.size()); + Deposit actualDeposit = testDeposits.get(0); + assertEquals(testOtherSubmission.getId(), actualDeposit.getSubmission().getId()); + PassClientSelector repoCopySelector = new PassClientSelector<>(RepositoryCopy.class); List testRepoCopies = passClient.streamObjects(repoCopySelector).toList(); - assertFalse(testRepoCopies.isEmpty()); + assertEquals(1, testRepoCopies.size()); + RepositoryCopy actualRepoCopy = testRepoCopies.get(0); + assertEquals(actualDeposit.getRepositoryCopy().getId(), actualRepoCopy.getId()); + PassClientSelector publicationSelector = new PassClientSelector<>(Publication.class); List testPublications = passClient.streamObjects(publicationSelector).toList(); - assertFalse(testPublications.isEmpty()); - PassClientSelector submissionSelector = new PassClientSelector<>(Submission.class); - submissionSelector.setInclude("grants"); - List testSubmissions = passClient.streamObjects(submissionSelector).toList(); - assertFalse(testSubmissions.isEmpty()); - Submission actualSubmission = testSubmissions.get(0); - assertEquals(testSubmission.getId(), actualSubmission.getId()); + assertEquals(1, testPublications.size()); + Publication actualPublication = testPublications.get(0); + assertEquals(actualRepoCopy.getPublication().getId(), actualPublication.getId()); + assertEquals(actualSubmission.getPublication().getId(), actualPublication.getId()); } private Submission initSubmissionAndDeposits(Grant testGrant) throws Exception { From 69820936056a0ddaf2442ff485d501564c4bb1a8 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Thu, 18 Apr 2024 13:01:35 -0400 Subject: [PATCH 4/7] Add logging statement --- .../eclipse/pass/deposit/service/DeploymentTestDataService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java index 563b6494..7b7043de 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java @@ -62,6 +62,7 @@ public void processTestData() throws IOException { List testGrants = passClient.streamObjects(grantSelector).toList(); Grant testGrant = testGrants.isEmpty() ? createTestGrantData() : testGrants.get(0); deleteTestSubmissions(testGrant); + LOG.warn("Done running Deployment Test Data Service"); } private void deleteTestSubmissions(Grant testGrant) throws IOException { From 965f75baab12b890a6915bb0856ba333626fe312 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Fri, 19 Apr 2024 07:42:06 -0400 Subject: [PATCH 5/7] Clean code --- .../service/DeploymentTestDataService.java | 6 +++-- .../service/DeploymentTestDataServiceIT.java | 25 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java index 7b7043de..7f365a4e 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java @@ -42,6 +42,8 @@ public class DeploymentTestDataService { private static final Logger LOG = LoggerFactory.getLogger(DeploymentTestDataService.class); + static final String PASS_E2E_TEST_GRANT = "PASS_E2E_TEST_GRANT"; + private final PassClient passClient; @Value("${pass.test.data.policy.title}") @@ -58,7 +60,7 @@ public DeploymentTestDataService(PassClient passClient) { public void processTestData() throws IOException { LOG.warn("Deployment Test Data Service running..."); PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); - grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + grantSelector.setFilter(RSQL.equals("projectName", PASS_E2E_TEST_GRANT)); List testGrants = passClient.streamObjects(grantSelector).toList(); Grant testGrant = testGrants.isEmpty() ? createTestGrantData() : testGrants.get(0); deleteTestSubmissions(testGrant); @@ -121,7 +123,7 @@ private Grant createTestGrantData() throws IOException { passClient.createObject(testFunder); Grant testGrant = new Grant(); - testGrant.setProjectName("PASS_E2E_TEST_GRANT"); + testGrant.setProjectName(PASS_E2E_TEST_GRANT); testGrant.setAwardNumber("TEST_E2E_AWD_NUM"); testGrant.setLocalKey("PASS_E2E_TEST_GRANT_LK"); testGrant.setAwardDate(ZonedDateTime.parse("2020-02-01T00:00:00Z")); diff --git a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java index 43b485c4..d807b25d 100644 --- a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java +++ b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java @@ -15,6 +15,7 @@ */ package org.eclipse.pass.deposit.service; +import static org.eclipse.pass.deposit.service.DeploymentTestDataService.PASS_E2E_TEST_GRANT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -76,7 +77,7 @@ public void initPolicyAndUser() throws IOException { @AfterEach public void cleanUp() throws IOException { PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); - grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + grantSelector.setFilter(RSQL.equals("projectName", PASS_E2E_TEST_GRANT)); List testGrants = passClient.streamObjects(grantSelector).toList(); testGrants.forEach(this::deleteObject); PassClientSelector depositSelector = new PassClientSelector<>(Deposit.class); @@ -108,12 +109,12 @@ public void testProcessData_TestGrantDataCreatedIfNotExist() throws Exception { // THEN PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); - grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + grantSelector.setFilter(RSQL.equals("projectName", PASS_E2E_TEST_GRANT)); grantSelector.setInclude("pi", "directFunder", "primaryFunder"); List testGrants = passClient.streamObjects(grantSelector).toList(); assertEquals(1, testGrants.size()); Grant actualTestGrant = testGrants.get(0); - assertEquals("PASS_E2E_TEST_GRANT", actualTestGrant.getProjectName()); + assertEquals(PASS_E2E_TEST_GRANT, actualTestGrant.getProjectName()); assertEquals(AwardStatus.ACTIVE, actualTestGrant.getAwardStatus()); assertEquals("test-user-email@foo", actualTestGrant.getPi().getEmail()); assertEquals("PASS_E2E_TEST_FUNDER", actualTestGrant.getDirectFunder().getName()); @@ -124,7 +125,7 @@ public void testProcessData_TestGrantDataCreatedIfNotExist() throws Exception { public void testProcessData_DoesNotTestGrantDataCreatedIfExist() throws Exception { // GIVEN Grant testGrant = new Grant(); - testGrant.setProjectName("PASS_E2E_TEST_GRANT"); + testGrant.setProjectName(PASS_E2E_TEST_GRANT); testGrant.setAwardStatus(AwardStatus.ACTIVE); passClient.createObject(testGrant); Mockito.reset(passClient); @@ -134,12 +135,12 @@ public void testProcessData_DoesNotTestGrantDataCreatedIfExist() throws Exceptio // THEN PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); - grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + grantSelector.setFilter(RSQL.equals("projectName", PASS_E2E_TEST_GRANT)); List testGrants = passClient.streamObjects(grantSelector).toList(); assertEquals(1, testGrants.size()); Grant actualTestGrant = testGrants.get(0); assertEquals(testGrant.getId(), actualTestGrant.getId()); - assertEquals("PASS_E2E_TEST_GRANT", actualTestGrant.getProjectName()); + assertEquals(PASS_E2E_TEST_GRANT, actualTestGrant.getProjectName()); assertEquals(AwardStatus.ACTIVE, actualTestGrant.getAwardStatus()); verify(passClient, times(0)).createObject(any()); } @@ -148,7 +149,7 @@ public void testProcessData_DoesNotTestGrantDataCreatedIfExist() throws Exceptio public void testProcessData_DeleteTestSubmissionsForTestGrant() throws Exception { // GIVEN Grant testGrant = new Grant(); - testGrant.setProjectName("PASS_E2E_TEST_GRANT"); + testGrant.setProjectName(PASS_E2E_TEST_GRANT); testGrant.setAwardStatus(AwardStatus.ACTIVE); passClient.createObject(testGrant); initSubmissionAndDeposits(testGrant); @@ -158,11 +159,11 @@ public void testProcessData_DeleteTestSubmissionsForTestGrant() throws Exception // THEN PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); - grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + grantSelector.setFilter(RSQL.equals("projectName", PASS_E2E_TEST_GRANT)); List testGrants = passClient.streamObjects(grantSelector).toList(); assertEquals(1, testGrants.size()); Grant actualTestGrant = testGrants.get(0); - assertEquals("PASS_E2E_TEST_GRANT", actualTestGrant.getProjectName()); + assertEquals(PASS_E2E_TEST_GRANT, actualTestGrant.getProjectName()); assertEquals(AwardStatus.ACTIVE, actualTestGrant.getAwardStatus()); PassClientSelector depositSelector = new PassClientSelector<>(Deposit.class); List testDeposits = passClient.streamObjects(depositSelector).toList(); @@ -182,7 +183,7 @@ public void testProcessData_DeleteTestSubmissionsForTestGrant() throws Exception public void testProcessData_DoesNotDeleteTestSubmissionsForOtherGrant() throws Exception { // GIVEN Grant deploymentGrant = new Grant(); - deploymentGrant.setProjectName("PASS_E2E_TEST_GRANT"); + deploymentGrant.setProjectName(PASS_E2E_TEST_GRANT); deploymentGrant.setAwardStatus(AwardStatus.ACTIVE); passClient.createObject(deploymentGrant); initSubmissionAndDeposits(deploymentGrant); @@ -198,11 +199,11 @@ public void testProcessData_DoesNotDeleteTestSubmissionsForOtherGrant() throws E // THEN final PassClientSelector grantSelector = new PassClientSelector<>(Grant.class); - grantSelector.setFilter(RSQL.equals("projectName", "PASS_E2E_TEST_GRANT")); + grantSelector.setFilter(RSQL.equals("projectName", PASS_E2E_TEST_GRANT)); List actualTestGrants = passClient.streamObjects(grantSelector).toList(); assertEquals(1, actualTestGrants.size()); Grant actualTestGrant = actualTestGrants.get(0); - assertEquals("PASS_E2E_TEST_GRANT", actualTestGrant.getProjectName()); + assertEquals(PASS_E2E_TEST_GRANT, actualTestGrant.getProjectName()); assertEquals(AwardStatus.ACTIVE, actualTestGrant.getAwardStatus()); PassClientSelector submissionSelector = new PassClientSelector<>(Submission.class); From 8f70cdfeac6301a3c219e89b01e94f6ca1f58f49 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Fri, 19 Apr 2024 09:04:28 -0400 Subject: [PATCH 6/7] Add deleteFile to pass data client --- .../support/client/JsonApiPassClient.java | 17 ++++++++++++ .../pass/support/client/PassClient.java | 7 +++++ .../support/client/JsonApiPassClientIT.java | 26 +++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/pass-data-client/src/main/java/org/eclipse/pass/support/client/JsonApiPassClient.java b/pass-data-client/src/main/java/org/eclipse/pass/support/client/JsonApiPassClient.java index d3573576..80b2911b 100644 --- a/pass-data-client/src/main/java/org/eclipse/pass/support/client/JsonApiPassClient.java +++ b/pass-data-client/src/main/java/org/eclipse/pass/support/client/JsonApiPassClient.java @@ -674,6 +674,23 @@ public InputStream downloadFile(File file) throws IOException { return response.body().byteStream(); } + @Override + public void deleteFile(File file) throws IOException { + // Transform File URI to use baseUrl in order to avoid authentication issues + HttpUrl urlFileBin = HttpUrl.parse(baseUrl).newBuilder() + .addEncodedPathSegments(file.getUri().getRawPath().substring(1)).build(); + + Request requestFileBin = new Request.Builder().url(urlFileBin).delete().build(); + Response responseFileBin = client.newCall(requestFileBin).execute(); + + if (!responseFileBin.isSuccessful() && responseFileBin.code() != 404) { + throw new IOException(String.format("Failed to delete for File: %s, URL: %s, Status code: %d", + file.getId(), urlFileBin, responseFileBin.code())); + } + + deleteObject(file); + } + @Override public URI uploadBinary(String name, byte[] data) throws IOException { HttpUrl url = HttpUrl.parse(baseUrl).newBuilder() diff --git a/pass-data-client/src/main/java/org/eclipse/pass/support/client/PassClient.java b/pass-data-client/src/main/java/org/eclipse/pass/support/client/PassClient.java index 707cf8e4..c96ecdf0 100644 --- a/pass-data-client/src/main/java/org/eclipse/pass/support/client/PassClient.java +++ b/pass-data-client/src/main/java/org/eclipse/pass/support/client/PassClient.java @@ -211,6 +211,13 @@ public Spliterator trySplit() { */ InputStream downloadFile(File file) throws IOException; + /** + * Deletes the binary data associated to the File parameter and the File entity. + * @param file the File to delete + * @throws IOException if operation fails + */ + void deleteFile(File file) throws IOException; + /** * @param id of File * @return InputStream of bytes diff --git a/pass-data-client/src/test/java/org/eclipse/pass/support/client/JsonApiPassClientIT.java b/pass-data-client/src/test/java/org/eclipse/pass/support/client/JsonApiPassClientIT.java index 2b1e812d..a2f14460 100644 --- a/pass-data-client/src/test/java/org/eclipse/pass/support/client/JsonApiPassClientIT.java +++ b/pass-data-client/src/test/java/org/eclipse/pass/support/client/JsonApiPassClientIT.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertIterableEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -737,4 +738,29 @@ public void testUploadDownloadFile() throws IOException { assertEquals(data, test_data); } + + @Test + public void testDeleteFile() throws IOException { + // GIVEN + File file = new File(); + String data = "What's in a name?"; + file.setName("rose.txt"); + URI data_uri = client.uploadBinary(file.getName(), data.getBytes(StandardCharsets.UTF_8)); + assertNotNull(data_uri); + file.setUri(data_uri); + client.createObject(file); + + // WHEN + client.deleteFile(file); + + // THEN + IOException ioExBin = assertThrows(IOException.class, () -> { + client.downloadFile(file); + }); + assertEquals("Failed to retrieve binary for File: " + file.getId() + ", URL: " + + file.getUri().toString() + ", Status code: 404", ioExBin.getMessage()); + + File actualFile = client.getObject(File.class, file.getId()); + assertNull(actualFile); + } } From 47a5425c354a07140b6bd29f72a7b40daf561984 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Fri, 19 Apr 2024 09:43:51 -0400 Subject: [PATCH 7/7] Delete test submission files --- .../service/DeploymentTestDataService.java | 13 ++++++++ .../service/DeploymentTestDataServiceIT.java | 33 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java index 7f365a4e..04c8166e 100644 --- a/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java +++ b/pass-deposit-services/deposit-core/src/main/java/org/eclipse/pass/deposit/service/DeploymentTestDataService.java @@ -25,6 +25,7 @@ import org.eclipse.pass.support.client.RSQL; import org.eclipse.pass.support.client.model.AwardStatus; import org.eclipse.pass.support.client.model.Deposit; +import org.eclipse.pass.support.client.model.File; import org.eclipse.pass.support.client.model.Funder; import org.eclipse.pass.support.client.model.Grant; import org.eclipse.pass.support.client.model.Journal; @@ -87,6 +88,10 @@ private void deleteTestSubmissions(Grant testGrant) throws IOException { deleteObject(testDeposit); deleteObject(testDeposit.getRepositoryCopy()); }); + PassClientSelector testFileSelector = new PassClientSelector<>(File.class); + testFileSelector.setFilter(RSQL.equals("submission.id", testSubmission.getId())); + List testFiles = passClient.streamObjects(testFileSelector).toList(); + testFiles.forEach(this::deleteFile); deleteObject(testSubmission); deleteObject(testSubmission.getPublication()); } catch (IOException e) { @@ -104,6 +109,14 @@ private void deleteObject(PassEntity entity) { } } + private void deleteFile(File file) { + try { + passClient.deleteFile(file); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + private Grant createTestGrantData() throws IOException { LOG.warn("Creating Test Grant Data"); Journal testJournal = new Journal(); diff --git a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java index d807b25d..10371194 100644 --- a/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java +++ b/pass-deposit-services/deposit-core/src/test/java/org/eclipse/pass/deposit/service/DeploymentTestDataServiceIT.java @@ -17,12 +17,15 @@ import static org.eclipse.pass.deposit.service.DeploymentTestDataService.PASS_E2E_TEST_GRANT; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.io.IOException; +import java.net.URI; +import java.nio.charset.StandardCharsets; import java.time.ZonedDateTime; import java.util.List; @@ -31,6 +34,7 @@ import org.eclipse.pass.support.client.model.AwardStatus; import org.eclipse.pass.support.client.model.Deposit; import org.eclipse.pass.support.client.model.DepositStatus; +import org.eclipse.pass.support.client.model.File; import org.eclipse.pass.support.client.model.Grant; import org.eclipse.pass.support.client.model.PassEntity; import org.eclipse.pass.support.client.model.Policy; @@ -86,6 +90,9 @@ public void cleanUp() throws IOException { PassClientSelector repoCopySelector = new PassClientSelector<>(RepositoryCopy.class); List testRepoCopies = passClient.streamObjects(repoCopySelector).toList(); testRepoCopies.forEach(this::deleteObject); + PassClientSelector fileSelector = new PassClientSelector<>(File.class); + List testFiles = passClient.streamObjects(fileSelector).toList(); + testFiles.forEach(this::deleteFile); PassClientSelector submissionSelector = new PassClientSelector<>(Submission.class); List testSubmissions = passClient.streamObjects(submissionSelector).toList(); testSubmissions.forEach(this::deleteObject); @@ -102,6 +109,14 @@ private void deleteObject(PassEntity entity) { } } + private void deleteFile(File file) { + try { + passClient.deleteFile(file); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + @Test public void testProcessData_TestGrantDataCreatedIfNotExist() throws Exception { // WHEN @@ -177,6 +192,9 @@ public void testProcessData_DeleteTestSubmissionsForTestGrant() throws Exception PassClientSelector publicationSelector = new PassClientSelector<>(Publication.class); List testPublications = passClient.streamObjects(publicationSelector).toList(); assertTrue(testPublications.isEmpty()); + PassClientSelector fileSelector = new PassClientSelector<>(File.class); + List testFiles = passClient.streamObjects(fileSelector).toList(); + assertTrue(testFiles.isEmpty()); } @Test @@ -231,6 +249,12 @@ public void testProcessData_DoesNotDeleteTestSubmissionsForOtherGrant() throws E Publication actualPublication = testPublications.get(0); assertEquals(actualRepoCopy.getPublication().getId(), actualPublication.getId()); assertEquals(actualSubmission.getPublication().getId(), actualPublication.getId()); + + PassClientSelector fileSelector = new PassClientSelector<>(File.class); + List testFiles = passClient.streamObjects(fileSelector).toList(); + assertEquals(1, testFiles.size()); + File actualFile = testFiles.get(0); + assertEquals(actualSubmission.getId(), actualFile.getSubmission().getId()); } private Submission initSubmissionAndDeposits(Grant testGrant) throws Exception { @@ -261,6 +285,15 @@ private Submission initSubmissionAndDeposits(Grant testGrant) throws Exception { submission.setPublication(publication); passClient.updateObject(submission); + File file = new File(); + String data = "Test data file"; + file.setName("test_data_file.txt"); + URI data_uri = passClient.uploadBinary(file.getName(), data.getBytes(StandardCharsets.UTF_8)); + assertNotNull(data_uri); + file.setUri(data_uri); + file.setSubmission(submission); + passClient.createObject(file); + return submission; }