Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Sep 25, 2023
1 parent 53ab4b8 commit 87ab52d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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());
}
}
}

0 comments on commit 87ab52d

Please sign in to comment.