From 87ab52d797b1311561d4d4c32c0994b2f8b1a292 Mon Sep 17 00:00:00 2001 From: Russ Poetker Date: Thu, 14 Sep 2023 13:52:37 -0400 Subject: [PATCH] Add tests --- .../pass/object/ElidePassClientTest.java | 32 +++++++++++++++++++ .../eclipse/pass/user/UserServiceTest.java | 7 ++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/pass-core-main/src/test/java/org/eclipse/pass/object/ElidePassClientTest.java b/pass-core-main/src/test/java/org/eclipse/pass/object/ElidePassClientTest.java index e39ace08..a9a22f1b 100644 --- a/pass-core-main/src/test/java/org/eclipse/pass/object/ElidePassClientTest.java +++ b/pass-core-main/src/test/java/org/eclipse/pass/object/ElidePassClientTest.java @@ -15,6 +15,7 @@ */ package org.eclipse.pass.object; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -40,6 +41,37 @@ protected PassClient getNewClient() { return new ElidePassClient(refreshableElide); } + @Test + public void testUpdateObject_CheckVersionUpdate() throws IOException { + Submission submission = new Submission(); + + submission.setAggregatedDepositStatus(AggregatedDepositStatus.NOT_STARTED); + submission.setSubmissionStatus(SubmissionStatus.DRAFT); + submission.setSubmitterName("Bessie"); + + client.createObject(submission); + assertEquals(0, submission.getVersion()); + + submission.setSource(Source.OTHER); + submission.setSubmissionStatus(SubmissionStatus.SUBMITTED); + + client.updateObject(submission); + assertEquals(1, submission.getVersion()); + + Submission test = client.getObject(submission.getClass(), submission.getId()); + + assertEquals(submission.getId(), test.getId()); + assertEquals(submission.getAggregatedDepositStatus(), test.getAggregatedDepositStatus()); + assertEquals(submission.getSubmitterName(), test.getSubmitterName()); + assertEquals(submission.getSource(), test.getSource()); + assertEquals(submission.getSubmissionStatus(), test.getSubmissionStatus()); + assertEquals(submission.getMetadata(), test.getMetadata()); + assertEquals(1, test.getVersion()); + + // The lazy loading of objects from relationships does not play nicely with equality tests + // assertEquals(submission, test); + } + @Test public void testUpdateSubmission_OptimisticLocking() throws IOException { Submission submission = new Submission(); diff --git a/pass-core-main/src/test/java/org/eclipse/pass/user/UserServiceTest.java b/pass-core-main/src/test/java/org/eclipse/pass/user/UserServiceTest.java index cf59c5fd..8423fff9 100644 --- a/pass-core-main/src/test/java/org/eclipse/pass/user/UserServiceTest.java +++ b/pass-core-main/src/test/java/org/eclipse/pass/user/UserServiceTest.java @@ -1,6 +1,7 @@ package org.eclipse.pass.user; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; @@ -88,6 +89,7 @@ public void testHandleRequestWithUserToken() throws IOException, JSONException { try (PassClient client = PassClient.newInstance(refreshableElide)) { client.createObject(submission); } + assertEquals(0, submission.getVersion()); Token token = userTokenFactory.forPassResource("submission", submission.getId(), mailto); @@ -114,9 +116,10 @@ public void testHandleRequestWithUserToken() throws IOException, JSONException { try (PassClient client = PassClient.newInstance(refreshableElide)) { submission = client.getObject(submission.getClass(), submission.getId()); - assertEquals(null, submission.getSubmitterName()); - assertEquals(null, submission.getSubmitterEmail()); + assertNull(submission.getSubmitterName()); + assertNull(submission.getSubmitterEmail()); assertEquals(submitter.getId(), submission.getSubmitter().getId()); + assertEquals(1, submission.getVersion()); } } }