Skip to content

Commit

Permalink
PO-770: convert JSON names to snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
RustyHMCTS committed Sep 18, 2024
1 parent 435c6ef commit a50499f
Show file tree
Hide file tree
Showing 64 changed files with 904 additions and 769 deletions.
12 changes: 6 additions & 6 deletions src/functionalTest/java/uk/gov/hmcts/opal/config/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

public class Constants {

public static final String BUSINESS_UNIT_REF_DATA_URI = "/business-units/ref-data/";
public static final String COURTS_REF_DATA_URI = "/courts/ref-data/";
public static final String LJA_REF_DATA_URI = "/local-justice-areas/ref-data/";
public static final String OFFENCES_REF_DATA_URI = "/offences/ref-data/";
public static final String BUSINESS_UNIT_REF_DATA_URI = "/business-units";
public static final String COURTS_REF_DATA_URI = "/courts";
public static final String LJA_REF_DATA_URI = "/local-justice-areas";
public static final String OFFENCES_REF_DATA_URI = "/offences";

public static final String ENFORCERS_REF_DATA_URI = "/enforcers/ref-data/Aldridge";
public static final String MAJOR_CREDITORS_URI = "/major-creditors/";
public static final String ENFORCERS_REF_DATA_URI = "/enforcers?q=Aldridge";
public static final String MAJOR_CREDITORS_URI = "/major-creditors";
public static final String DRAFT_ACCOUNT_URI = "/draft-accounts";
public static final String RESULTS_URI = "/results";
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static String fetchToken(String user) {
.get(getTestUrl() + "/testing-support/token/user");

then().assertThat().statusCode(200);
return then().extract().body().jsonPath().getString("accessToken");
return then().extract().body().jsonPath().getString("access_token");
}

public static String getToken() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ public void postToDefendantSearchAPI(DataTable searchCriteria) throws JSONExcept
requestBody.put("initials", dataToPost.get("initials") != null ? dataToPost.get("initials") : "");

JSONObject dateOfBirth = new JSONObject();
dateOfBirth.put("dayOfMonth", dataToPost.get("dayOfMonth") != null ? dataToPost.get("dayOfMonth") : "");
dateOfBirth.put("monthOfYear", dataToPost.get("monthOfYear") != null ? dataToPost.get("monthOfYear") : "");
dateOfBirth.put("day_of_month",
dataToPost.get("day_of_month") != null ? dataToPost.get("day_of_month") : "");
dateOfBirth.put("month_of_year",
dataToPost.get("month_of_year") != null ? dataToPost.get("month_of_year") : "");
dateOfBirth.put("year", dataToPost.get("year") != null ? dataToPost.get("year") : "");
requestBody.put("dateOfBirth", dateOfBirth);
requestBody.put("date_of_birth", dateOfBirth);

requestBody.put(
"addressLine",
dataToPost.get("addressLine") != null ? dataToPost.get("addressLine") : ""
"address_line",
dataToPost.get("address_line") != null ? dataToPost.get("address_line") : ""
);

SerenityRest
Expand All @@ -53,17 +55,17 @@ public void thereIsOneResultReturnedMatching(DataTable expectedData) {

then().assertThat()
.statusCode(200)
.body("totalCount", Matchers.equalTo(1))
.body("searchResults.name[0]", Matchers.equalTo(expectedResult.get("name")))
.body("searchResults.dateOfBirth[0]", Matchers.equalTo(expectedResult.get("dateOfBirth")))
.body("searchResults.addressLine1[0]", Matchers.equalTo(expectedResult.get("addressLine1")));
.body("total_count", Matchers.equalTo(1))
.body("search_results.name[0]", Matchers.equalTo(expectedResult.get("name")))
.body("search_results.date_of_birth[0]", Matchers.equalTo(expectedResult.get("dateOfBirth")))
.body("search_results.address_line_1[0]", Matchers.equalTo(expectedResult.get("addressLine1")));
}

@Then("there are no results returned")
public void thereAreNoResultsReturned() {
then().assertThat()
.statusCode(200)
.body("totalCount", Matchers.equalTo(0));
.body("total_count", Matchers.equalTo(0));
}

@Then("the returned results match")
Expand All @@ -72,27 +74,27 @@ public void theReturnedResultsMatch(DataTable expectedData) {
then().assertThat()
.statusCode(200);

int totalCount = then().extract().jsonPath().getInt("totalCount");
int totalCount = then().extract().jsonPath().getInt("total_count");
System.out.println("total count is : " + totalCount);

int index = 0;

while (index < totalCount) {
if (expectedResult.get("name") != null) {
then().assertThat()
.body("searchResults.name[" + index + "]", Matchers.containsString(expectedResult.get("name")));
.body("search_results.name[" + index + "]", Matchers.containsString(expectedResult.get("name")));
}
if (expectedResult.get("dateOfBirth") != null) {
if (expectedResult.get("date_of_birth") != null) {
then().assertThat()
.body(
"searchResults.dateOfBirth[" + index + "]",
Matchers.containsString(expectedResult.get("dateOfBirth"))
"search_results.date_of_birth[" + index + "]",
Matchers.containsString(expectedResult.get("date_of_birth"))
);
}
if (expectedResult.get("addressLine1") != null) {
if (expectedResult.get("address_line_1") != null) {
then().assertThat()
.body(
"searchResults.addressLine1[" + index + "]",
"search_results.address_line_1[" + index + "]",
Matchers.containsString(expectedResult.get("addressLine1"))
);
}
Expand Down
70 changes: 37 additions & 33 deletions src/functionalTest/java/uk/gov/hmcts/opal/steps/RefDataStepDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class RefDataStepDef extends BaseStepDef {
@When("I make a request to the business unit ref data api filtering by business unit type {string}")
public void getRequestToBusinessUnitRefData(String filter) {

methods.getRequest(BUSINESS_UNIT_REF_DATA_URI + filter);
methods.getRequest(BUSINESS_UNIT_REF_DATA_URI + "?q=" + filter);

}

Expand All @@ -52,17 +52,17 @@ public void getRequestToOffencesRefDataBusinessUnit(int businessUnitId) {

@When("I make a request to the offence ref data api filtering by cjs code {string}")
public void getRequestToOffencesRefDataCjsCode(String cjsCode) {
methods.getRequest(OFFENCES_REF_DATA_URI + cjsCode);
methods.getRequest(OFFENCES_REF_DATA_URI + "?q=" + cjsCode);
}

@When("I make a request to the offence ref data api filtering with the offence title {string}")
public void getRequestToOffencesRefDataWording(String filter) {
methods.getRequest(OFFENCES_REF_DATA_URI + filter);
methods.getRequest(OFFENCES_REF_DATA_URI + "?q=" + filter);
}

@When("I make a request to the major creditors ref data api filter by major creditor id {int}")
public void getRequestToMajorCreditorsBy(int majorCreditorId) {
methods.getRequest(MAJOR_CREDITORS_URI + majorCreditorId);
methods.getRequest(MAJOR_CREDITORS_URI + "/" + majorCreditorId);
}

@When("I make a request to the LJA ref data api with")
Expand All @@ -77,17 +77,17 @@ public void getRequestToCourtsRefData() {

@When("I make a request to the court ref data api with a filter of {string}")
public void getRequestToCourtsRefDataWithFilter(String filter) {
methods.getRequest(COURTS_REF_DATA_URI + filter);
methods.getRequest(COURTS_REF_DATA_URI + "?q=" + filter);
}

@When("I make a request to the court ref data api with a filter of {string} and a business unit of {int}")
public void getRequestToCourtsRefDataWithFilterAndBU(String filter, int businessUnitId) {
methods.getRequest(COURTS_REF_DATA_URI + filter + "?businessUnit=" + businessUnitId);
methods.getRequest(COURTS_REF_DATA_URI + "?q=" + filter + "?business_unit=" + businessUnitId);
}

@When("I make a request to the court ref data api with a business unit of {int}")
public void getRequestToCourtsRefDataWithBU(int businessUnitId) {
methods.getRequest(COURTS_REF_DATA_URI + "?businessUnit=" + businessUnitId);
methods.getRequest(COURTS_REF_DATA_URI + "?business_unit=" + businessUnitId);
}

@Then("the LJA ref data matching to result")
Expand All @@ -110,13 +110,13 @@ public void theResponseContainsTheCorrectCourt(String courtName) throws SQLExcep
court = db.getCourtsByCourtName(courtName);
then().assertThat().statusCode(200);
for (int i = 0; i < totalCount; i++) {
String courtId = then().extract().jsonPath().getString("refData.courtId[" + i + "]");
String courtId = then().extract().jsonPath().getString("refData.court_id[" + i + "]");
assertEquals(courtId, court.getJSONObject(i).getString("court_id"));

String businessUnitId = then().extract().jsonPath().getString("refData.businessUnitId[" + i + "]");
String businessUnitId = then().extract().jsonPath().getString("refData.business_unit_id[" + i + "]");
assertEquals(businessUnitId, court.getJSONObject(i).getString("business_unit_id"));

String courtCode = then().extract().jsonPath().getString("refData.courtCode[" + i + "]");
String courtCode = then().extract().jsonPath().getString("refData.court_code[" + i + "]");
assertEquals(courtCode, court.getJSONObject(i).getString("court_code"));

String name = then().extract().jsonPath().getString("refData.name[" + i + "]");
Expand All @@ -139,12 +139,14 @@ public void responseContainsMajorCreditorData(DataTable data) {
Map<String, String> expected = data.asMap(String.class, String.class);
then().assertThat().statusCode(200);

assertEquals(expected.get("majorCreditorId"), then().extract().jsonPath().getString("majorCreditorId"));
assertEquals(expected.get("majorCreditorCode"), then().extract().jsonPath().getString("majorCreditorCode"));
assertEquals(expected.get("majorCreditorId"),
then().extract().jsonPath().getString("major_creditor_id"));
assertEquals(expected.get("majorCreditorCode"),
then().extract().jsonPath().getString("major_creditor_code"));
assertEquals(expected.get("name"), then().extract().jsonPath().getString("name"));
assertEquals(
expected.get("businessUnitId"),
then().extract().jsonPath().getString("businessUnit.businessUnitId")
expected.get("business_unit_d"),
then().extract().jsonPath().getString("business_unit.business_unit_id")
);
}

Expand All @@ -153,12 +155,14 @@ public void responseDoesNotContainMajorCreditorData(DataTable data) {
Map<String, String> expected = data.asMap(String.class, String.class);
then().assertThat().statusCode(200);

assertNotEquals(expected.get("majorCreditorId"), then().extract().jsonPath().getString("majorCreditorId"));
assertNotEquals(expected.get("majorCreditorCode"), then().extract().jsonPath().getString("majorCreditorCode"));
assertNotEquals(expected.get("major_creditor_id"),
then().extract().jsonPath().getString("major_creditor_id"));
assertNotEquals(expected.get("major_creditor_code"),
then().extract().jsonPath().getString("major_creditor_code"));
assertNotEquals(expected.get("name"), then().extract().jsonPath().getString("name"));
assertNotEquals(
expected.get("businessUnitId"),
then().extract().jsonPath().getString("businessUnit.businessUnitId")
expected.get("business_unit_id"),
then().extract().jsonPath().getString("businessUnit.business_unit_id")
);
}

Expand All @@ -169,9 +173,9 @@ public void responseContainsCourtData(DataTable data) {
then().assertThat().statusCode(200);
for (int i = 0; i < totalCount; i++) {
String actualName = then().extract().jsonPath().getString("refData.name[" + i + "]");
String actualBuId = then().extract().jsonPath().getString("refData.businessUnitId[" + i + "]");
String actualBuId = then().extract().jsonPath().getString("refData.business_unit_id[" + i + "]");
String expectedName = expectedData.get("name");
String expectedBuId = expectedData.get("businessUnitId");
String expectedBuId = expectedData.get("business_unit_id");
log.info("\nApi response: \n" + " Count: " + (i + 1) + "/" + totalCount + "\n "
+ actualName + "\n " + actualBuId);
if (expectedName == null) {
Expand All @@ -194,9 +198,9 @@ public void responseDoesNotContainCourtData(DataTable data) {
then().assertThat().statusCode(200);
for (int i = 0; i < totalCount; i++) {
String actualName = then().extract().jsonPath().getString("refData.name[" + i + "]");
String actualBuId = then().extract().jsonPath().getString("refData.businessUnitId[" + i + "]");
String actualBuId = then().extract().jsonPath().getString("refData.business_unit_id[" + i + "]");
String expectedName = expectedData.get("name");
String expectedBuId = expectedData.get("businessUnitId");
String expectedBuId = expectedData.get("business_unit_id");
log.info("\nApi response: \n" + " Count: " + (i + 1) + "/" + totalCount + "\n "
+ actualName + "\n " + actualBuId);
if (expectedName == null) {
Expand All @@ -218,10 +222,10 @@ public void responseContainsOffenceData(DataTable data) {
int totalCount = then().extract().jsonPath().getInt("count");
then().assertThat().statusCode(200);
for (int i = 0; i < totalCount; i++) {
String actualOffenceTitle = then().extract().jsonPath().getString("refData.getOffenceTitle[" + i + "]");
String actualBuId = then().extract().jsonPath().getString("refData.businessUnitId[" + i + "]");
String actualOffenceTitle = then().extract().jsonPath().getString("refData._offence_title[" + i + "]");
String actualBuId = then().extract().jsonPath().getString("refData.business_unit_id[" + i + "]");
String expectedOffenceTitle = expectedData.get("offenceTitle");
String expectedBuId = expectedData.get("businessUnitId");
String expectedBuId = expectedData.get("business_unit_id");
log.info("Expected name: " + expectedOffenceTitle + " Expected buId: " + expectedBuId);
log.info("\nApi response: \n" + " Count: " + (i + 1) + "/" + totalCount + "\n "
+ actualOffenceTitle + "\n " + actualBuId);
Expand Down Expand Up @@ -252,9 +256,9 @@ public void responseDoesNotContainOffenceData(DataTable data) {
int totalCount = then().extract().jsonPath().getInt("count");
then().assertThat().statusCode(200);
for (int i = 0; i < totalCount; i++) {
String actualOffenceTitle = then().extract().jsonPath().getString("refData.getOffenceTitle[" + i + "]");
String actualBuId = then().extract().jsonPath().getString("refData.businessUnitId[" + i + "]");
String expectedBuId = expectedData.get("businessUnitId");
String actualOffenceTitle = then().extract().jsonPath().getString("refData.offence_title[" + i + "]");
String actualBuId = then().extract().jsonPath().getString("refData.business_unit_id[" + i + "]");
String expectedBuId = expectedData.get("business_unit_id");
log.info("\nApi response: \n" + " Count: " + (i + 1) + "/" + totalCount + "\n "
+ actualOffenceTitle + "\n " + actualBuId);
assertNotEquals(expectedBuId, actualBuId);
Expand All @@ -267,13 +271,13 @@ public void theResponseContainsTheCorrectMajorCreditor(int majorCreditorId) thro
JSONArray majorCreditor;
majorCreditor = db.getMajorCredByID(String.valueOf(majorCreditorId));
then().assertThat().statusCode(200);
String majorCreditorFromAPI = then().extract().jsonPath().getString("majorCreditorId");
String majorCreditorFromAPI = then().extract().jsonPath().getString("major_creditor_id");
assertEquals(majorCreditorFromAPI, majorCreditor.getJSONObject(0).getString("major_creditor_id"));

String businessUnitId = then().extract().jsonPath().getString("businessUnit.businessUnitId");
String businessUnitId = then().extract().jsonPath().getString("businessUnit.business_unit_id");
assertEquals(businessUnitId, majorCreditor.getJSONObject(0).getString("business_unit_id"));

String majorCreditorCode = then().extract().jsonPath().getString("majorCreditorCode");
String majorCreditorCode = then().extract().jsonPath().getString("major_creditor_code");
assertEquals(majorCreditorCode, majorCreditor.getJSONObject(0).getString("major_creditor_code"));

String name = then().extract().jsonPath().getString("name");
Expand All @@ -288,10 +292,10 @@ public void theResponseDoesNotContainTheCorrectMajorCreditor(int majorCreditorId
JSONArray majorCreditor;
majorCreditor = db.getMajorCredByID(String.valueOf(majorCreditorId));
then().assertThat().statusCode(200);
String majorCreditorFromAPI = then().extract().jsonPath().getString("majorCreditorId");
String majorCreditorFromAPI = then().extract().jsonPath().getString("major_creditor_id");
assertNotEquals(majorCreditorFromAPI, majorCreditor.getJSONObject(0).getString("major_creditor_id"));

String majorCreditorCode = then().extract().jsonPath().getString("majorCreditorCode");
String majorCreditorCode = then().extract().jsonPath().getString("major_creditor_code");
assertNotEquals(majorCreditorCode, majorCreditor.getJSONObject(0).getString("major_creditor_code"));

String name = then().extract().jsonPath().getString("name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void deleteDraftAccount(String draftAccountId) {
.accept("*/*")
.contentType("application/json")
.when()
.delete(getTestUrl() + DRAFT_ACCOUNT_URI + "/" + draftAccountId + "?ignoreMissing=true");
.delete(getTestUrl() + DRAFT_ACCOUNT_URI + "/" + draftAccountId + "?ignore_missing=true");
}

@Then("I delete the created draft accounts")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Feature: Test the add note endpoint for Legacy

Scenario: assert add note canned response is valid for Legacy route
When I make a request to the defendant account add notes api with
| associatedRecordId | 500000000 |
| businessUnitId | 17 |
| noteText | test account note1 |
| associated_record_id | 500000000 |
| business_unit_id | 17 |
| note_text | test account note1 |
Then the add notes response contains
| noteId | 12345678 |
| associatedRecordId | 500000000 |
| noteText | test account note1 |
| note_id | 12345678 |
| associated_record_id | 500000000 |
| note_text | test account note1 |
Loading

0 comments on commit a50499f

Please sign in to comment.