forked from hmcts/rse-cft-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
only increment case data version when data changes
- Loading branch information
Alex McAusland
committed
Nov 8, 2024
1 parent
c43bb7e
commit ae7fdcf
Showing
3 changed files
with
87 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,7 +133,7 @@ public void getEventHistory() throws Exception { | |
|
||
@Order(4) | ||
@Test | ||
public void testOptimisticLock() throws Exception { | ||
public void testAddNoteRunsConcurrently() throws Exception { | ||
var firstEvent = ccdApi.startEvent( | ||
getAuthorisation("[email protected]"), | ||
getServiceAuth(), String.valueOf(caseRef), "caseworker-add-note").getToken(); | ||
|
@@ -151,9 +151,44 @@ public void testOptimisticLock() throws Exception { | |
"ignore_warning", false | ||
); | ||
|
||
// Conflicting change! | ||
// Concurrent change to case notes should be allowed without raising a conflict | ||
addNote(); | ||
|
||
var e = | ||
buildRequest("[email protected]", | ||
"http://localhost:4452/cases/" + caseRef + "/events", HttpPost::new); | ||
e.addHeader("experimental", "true"); | ||
e.addHeader("Accept", | ||
"application/vnd.uk.gov.hmcts.ccd-data-store-api.create-event.v2+json;charset=UTF-8"); | ||
|
||
e.setEntity(new StringEntity(new Gson().toJson(body), ContentType.APPLICATION_JSON)); | ||
var response = HttpClientBuilder.create().build().execute(e); | ||
assertThat(response.getStatusLine().getStatusCode(), equalTo(201)); | ||
} | ||
|
||
@Order(5) | ||
@Test | ||
public void testOptimisticLockOnJsonBlob() throws Exception { | ||
var firstEvent = ccdApi.startEvent( | ||
getAuthorisation("[email protected]"), | ||
getServiceAuth(), String.valueOf(caseRef), "caseworker-update-due-date").getToken(); | ||
|
||
var body = Map.of( | ||
"data", Map.of( | ||
"dueDate", "2020-01-01" | ||
), | ||
"event", Map.of( | ||
"id", "caseworker-update-due-date", | ||
"summary", "summary", | ||
"description", "description" | ||
), | ||
"event_token", firstEvent, | ||
"ignore_warning", false | ||
); | ||
|
||
// Concurrent change to json blob should be rejected | ||
updateDueDate(); | ||
|
||
var e = | ||
buildRequest("[email protected]", | ||
"http://localhost:4452/cases/" + caseRef + "/events", HttpPost::new); | ||
|
@@ -166,6 +201,37 @@ public void testOptimisticLock() throws Exception { | |
assertThat(response.getStatusLine().getStatusCode(), equalTo(409)); | ||
} | ||
|
||
private void updateDueDate() throws Exception { | ||
|
||
var token = ccdApi.startEvent( | ||
getAuthorisation("[email protected]"), | ||
getServiceAuth(), String.valueOf(caseRef), "caseworker-update-due-date").getToken(); | ||
|
||
var body = Map.of( | ||
"data", Map.of( | ||
"dueDate", "2020-01-01" | ||
), | ||
"event", Map.of( | ||
"id", "caseworker-update-due-date", | ||
"summary", "summary", | ||
"description", "description" | ||
), | ||
"event_token", token, | ||
"ignore_warning", false | ||
); | ||
|
||
var e = | ||
buildRequest("[email protected]", | ||
"http://localhost:4452/cases/" + caseRef + "/events", HttpPost::new); | ||
e.addHeader("experimental", "true"); | ||
e.addHeader("Accept", | ||
"application/vnd.uk.gov.hmcts.ccd-data-store-api.create-event.v2+json;charset=UTF-8"); | ||
|
||
e.setEntity(new StringEntity(new Gson().toJson(body), ContentType.APPLICATION_JSON)); | ||
var response = HttpClientBuilder.create().build().execute(e); | ||
assertThat(response.getStatusLine().getStatusCode(), equalTo(201)); | ||
} | ||
|
||
|
||
private void addNote() throws Exception { | ||
|
||
|
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