Skip to content

Commit

Permalink
Delete test submission files
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Apr 24, 2024
1 parent 878e6cf commit bb70c7d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,6 +88,10 @@ private void deleteTestSubmissions(Grant testGrant) throws IOException {
deleteObject(testDeposit);
deleteObject(testDeposit.getRepositoryCopy());
});
PassClientSelector<File> testFileSelector = new PassClientSelector<>(File.class);
testFileSelector.setFilter(RSQL.equals("submission.id", testSubmission.getId()));
List<File> testFiles = passClient.streamObjects(testFileSelector).toList();
testFiles.forEach(this::deleteFile);
deleteObject(testSubmission);
deleteObject(testSubmission.getPublication());
} catch (IOException e) {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -86,6 +90,9 @@ public void cleanUp() throws IOException {
PassClientSelector<RepositoryCopy> repoCopySelector = new PassClientSelector<>(RepositoryCopy.class);
List<RepositoryCopy> testRepoCopies = passClient.streamObjects(repoCopySelector).toList();
testRepoCopies.forEach(this::deleteObject);
PassClientSelector<File> fileSelector = new PassClientSelector<>(File.class);
List<File> testFiles = passClient.streamObjects(fileSelector).toList();
testFiles.forEach(this::deleteFile);
PassClientSelector<Submission> submissionSelector = new PassClientSelector<>(Submission.class);
List<Submission> testSubmissions = passClient.streamObjects(submissionSelector).toList();
testSubmissions.forEach(this::deleteObject);
Expand All @@ -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
Expand Down Expand Up @@ -177,6 +192,9 @@ public void testProcessData_DeleteTestSubmissionsForTestGrant() throws Exception
PassClientSelector<Publication> publicationSelector = new PassClientSelector<>(Publication.class);
List<Publication> testPublications = passClient.streamObjects(publicationSelector).toList();
assertTrue(testPublications.isEmpty());
PassClientSelector<File> fileSelector = new PassClientSelector<>(File.class);
List<File> testFiles = passClient.streamObjects(fileSelector).toList();
assertTrue(testFiles.isEmpty());
}

@Test
Expand Down Expand Up @@ -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<File> fileSelector = new PassClientSelector<>(File.class);
List<File> 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 {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit bb70c7d

Please sign in to comment.