-
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.
story(ccls-2055) add update application endpoint
- Loading branch information
1 parent
28dad6e
commit a0c6d1c
Showing
16 changed files
with
362 additions
and
29 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 |
---|---|---|
|
@@ -119,6 +119,43 @@ paths: | |
description: 'Not found' | ||
'500': | ||
description: 'Internal server error' | ||
patch: | ||
tags: | ||
- applications | ||
summary: 'Update Application' | ||
operationId: 'updateApplication' | ||
|
||
requestBody: | ||
description: Update a application | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/applicationDetail' | ||
parameters: | ||
- name: 'id' | ||
in: 'path' | ||
required: true | ||
schema: | ||
type: 'integer' | ||
format: 'int64' | ||
example: '1234567890' | ||
- name: 'Caab-User-Login-Id' | ||
in: header | ||
required: true | ||
schema: | ||
type: 'string' | ||
example: '[email protected]' | ||
responses: | ||
'200': | ||
description: 'Successful operation' | ||
'400': | ||
description: 'Bad request' | ||
'401': | ||
description: 'Unauthorized' | ||
'404': | ||
description: 'Not found' | ||
'500': | ||
description: 'Internal server error' | ||
/applications/clients/{client-reference-id}: | ||
patch: | ||
tags: | ||
|
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 |
---|---|---|
|
@@ -12,7 +12,9 @@ | |
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Random; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.BeforeEach; | ||
|
@@ -81,6 +83,90 @@ private String generateTestCaseRef(){ | |
return stringBuilder.toString(); | ||
} | ||
|
||
private static Stream<Arguments> createApplicationUpdateArguments() { | ||
return Stream.of( | ||
Arguments.of("/json/applicationUpdate_caseReferenceNumber.json", "getCaseReferenceNumber", "caseReferenceNumber"), | ||
Arguments.of("/json/applicationUpdate_clientFirstName.json", "getClient.getFirstName", "client"), | ||
Arguments.of("/json/applicationUpdate_costLimit.json", "getCostLimit.getLimitAtTimeOfMerits", "costLimit"), | ||
Arguments.of("/json/applicationUpdate_applicationType.json", "getApplicationType.getId", "applicationType"), | ||
Arguments.of("/json/applicationUpdate_categoryOfLaw.json", "getCategoryOfLaw.getId", "categoryOfLaw"), | ||
Arguments.of("/json/applicationUpdate_correspondenceAddress.json", "getCorrespondenceAddress.getPostcode", "correspondenceAddress"), | ||
Arguments.of("/json/applicationUpdate_providerContact.json", "getProviderDetails.getProviderContact.getId", "providerDetails"), | ||
Arguments.of("/json/applicationUpdate_status.json", "getStatus.getId", "status") | ||
); | ||
} | ||
|
||
|
||
@ParameterizedTest | ||
@MethodSource("createApplicationUpdateArguments") | ||
@Sql(scripts = "/sql/application_insert.sql") | ||
public void testUpdateApplication(String fileInput, String methodCall, String fieldToIgnore) | ||
throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
ApplicationDetail patchedApplicationDetails = loadObjectFromJson( | ||
fileInput, ApplicationDetail.class); | ||
|
||
final Long id = 21L; | ||
|
||
//get the application before doing the update | ||
ApplicationDetail beforeUpdateApplication = applicationService.getApplication(id); | ||
|
||
String auditUser = "[email protected]"; | ||
ResponseEntity<Void> responseEntity = | ||
applicationController.updateApplication(id, auditUser, patchedApplicationDetails); | ||
|
||
assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); | ||
|
||
//get the application after doing the update | ||
ApplicationDetail afterUpdateApplication = applicationService.getApplication(id); | ||
|
||
// Split the methodCall string and iterate over it to get the final value | ||
String[] methodCalls = methodCall.split("\\."); | ||
Object expectedVariable = getObjectToCheckFromMethod(patchedApplicationDetails, methodCalls); | ||
Object actualVariable = getObjectToCheckFromMethod(afterUpdateApplication, methodCalls); | ||
assertEquals(expectedVariable, actualVariable); | ||
|
||
//check other variables are not changed | ||
assertTrue(areAllFieldsEqual( | ||
beforeUpdateApplication, | ||
afterUpdateApplication, | ||
ApplicationDetail.class, List.of(fieldToIgnore, "auditTrail"))); | ||
} | ||
|
||
// Utility method to resolve the method chain and get the value | ||
private Object getObjectToCheckFromMethod(Object initialObject, String[] methodCalls) | ||
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { | ||
|
||
Object currentObject = initialObject; | ||
for (String methodName : methodCalls) { | ||
Method method = currentObject.getClass().getMethod(methodName); | ||
currentObject = method.invoke(currentObject); | ||
} | ||
return currentObject; | ||
} | ||
|
||
|
||
public static boolean areAllFieldsEqual(Object obj1, Object obj2, Class<?> clazz, List<String> fieldsToIgnore) | ||
throws IllegalArgumentException, IllegalAccessException { | ||
|
||
for (Field field : clazz.getDeclaredFields()) { | ||
field.setAccessible(true); | ||
|
||
// Continue to the next field if it should be ignored | ||
if (fieldsToIgnore.contains(field.getName())) { | ||
continue; | ||
} | ||
|
||
Object value1 = field.get(obj1); | ||
Object value2 = field.get(obj2); | ||
|
||
if (!Objects.equals(value1, value2)) { | ||
System.out.println("Field " + field.getName() + " is not equal: " + value1 + " != " + value2); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Arguments for the testCreateApplication test method. | ||
*/ | ||
|
11 changes: 11 additions & 0 deletions
11
caab-service/src/integrationTest/resources/json/applicationUpdate_applicationType.json
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"application_type": { | ||
"id": "LEGAL_HELP", | ||
"display_value": "Legal Help", | ||
"devolved_powers": { | ||
"used": true, | ||
"date_used": "2024-01-01", | ||
"contract_flag": "No" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
caab-service/src/integrationTest/resources/json/applicationUpdate_caseReferenceNumber.json
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"case_reference_number": "300001234567" | ||
} |
6 changes: 6 additions & 0 deletions
6
caab-service/src/integrationTest/resources/json/applicationUpdate_categoryOfLaw.json
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"category_of_law": { | ||
"id": "FAM", | ||
"display_value": "Family" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
caab-service/src/integrationTest/resources/json/applicationUpdate_clientFirstName.json
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"client": { | ||
"first_name": "John" | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
caab-service/src/integrationTest/resources/json/applicationUpdate_correspondenceAddress.json
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"correspondence_address": { | ||
"no_fixed_abode": true, | ||
"postcode": "NA", | ||
"house_name_or_number": "NA", | ||
"address_line_1": "NA", | ||
"address_line_2": "NA", | ||
"city": "NA", | ||
"county": "NA", | ||
"country": "GBR", | ||
"care_of": "NA", | ||
"preferred_address": "NA" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
caab-service/src/integrationTest/resources/json/applicationUpdate_costLimit.json
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cost_limit": { | ||
"limit_at_time_of_merits": 2000 | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
caab-service/src/integrationTest/resources/json/applicationUpdate_providerContact.json
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"provider_details": { | ||
"provider_contact": { | ||
"id": "2027080", | ||
"display_value": "[email protected]" | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
caab-service/src/integrationTest/resources/json/applicationUpdate_status.json
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"status": { | ||
"id": "SUBMITTED", | ||
"display_value": "Submitted" | ||
} | ||
} |
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
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
Oops, something went wrong.