From 7020bfdb94a12519a488ce1697890ba81eb837e0 Mon Sep 17 00:00:00 2001 From: zack-rma Date: Mon, 21 Oct 2024 06:51:24 -0700 Subject: [PATCH] Fixed issue #886 build errors (#920) Fixes #886 build errors caused by bad assertion mapping in integration test --- .../api/LocationGroupControllerTestIT.java | 53 +++++++++++++------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/cwms-data-api/src/test/java/cwms/cda/api/LocationGroupControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/LocationGroupControllerTestIT.java index 7ba8c5da8..61b385c59 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/LocationGroupControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/LocationGroupControllerTestIT.java @@ -58,6 +58,7 @@ import static cwms.cda.api.Controllers.*; import static io.restassured.RestAssured.given; import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; @Tag("integration") class LocationGroupControllerTestIT extends DataApiTestIT { @@ -656,7 +657,7 @@ void test_CWMS_permissions() throws Exception { .statusCode(is(HttpServletResponse.SC_OK)); // get the location group and assert that changes were made - given() + ExtractableResponse otherResponse = given() .log().ifValidationFails(LogDetail.ALL,true) .accept(Formats.JSON) .contentType(Formats.JSON) @@ -670,12 +671,22 @@ void test_CWMS_permissions() throws Exception { .log().ifValidationFails(LogDetail.ALL,true) .assertThat() .statusCode(is(HttpServletResponse.SC_OK)) - .body("office-id", equalTo(group.getOfficeId())) - .body("id", equalTo(group.getId())) - .body("description", equalTo(newLocGroup.getDescription())) - .body("assigned-locations[0].location-id", equalTo(locationId)) - .body("assigned-locations[0].alias-id", nullValue()) - .body("assigned-locations[0].ref-location-id", nullValue()); + .extract(); + + assertEquals(otherResponse.body().jsonPath().getString("office-id"), group.getOfficeId()); + assertEquals(otherResponse.body().jsonPath().getString("id"), group.getId()); + assertEquals(otherResponse.body().jsonPath().getString("description"), newLocGroup.getDescription()); + List assignedLocations = otherResponse.body().jsonPath().getList("assigned-locations", AssignedLocation.class); + boolean found = false; + for (AssignedLocation assignedLocation : assignedLocations) { + if (assignedLocation.getLocationId().equals(locationId)) { + assertEquals(assignedLocation.getLocationId(), locationId); + assertNull(assignedLocation.getAliasId()); + assertNull(assignedLocation.getRefLocationId()); + found = true; + } + } + assertTrue(found); // patch the location group owned by CWMS office given() @@ -764,12 +775,12 @@ void test_CWMS_permissions_with_replacement() throws Exception { .redirects().max(3) .patch("/location/group/" + group.getId()) .then() - .assertThat() .log().ifValidationFails(LogDetail.ALL,true) + .assertThat() .statusCode(is(HttpServletResponse.SC_OK)); // get the location group and assert that changes were made - given() + ExtractableResponse otherResponse = given() .log().ifValidationFails(LogDetail.ALL,true) .accept(Formats.JSON) .contentType(Formats.JSON) @@ -780,15 +791,25 @@ void test_CWMS_permissions_with_replacement() throws Exception { .redirects().max(3) .get("/location/group/" + group.getId()) .then() - .assertThat() .log().ifValidationFails(LogDetail.ALL,true) + .assertThat() .statusCode(is(HttpServletResponse.SC_OK)) - .body("office-id", equalTo(group.getOfficeId())) - .body("id", equalTo(group.getId())) - .body("description", equalTo(newLocGroup.getDescription())) - .body("assigned-locations[0].location-id", equalTo(locationId)) - .body("assigned-locations[0].alias-id", nullValue()) - .body("assigned-locations[0].ref-location-id", nullValue()); + .extract(); + + assertEquals(otherResponse.body().jsonPath().getString("office-id"), group.getOfficeId()); + assertEquals(otherResponse.body().jsonPath().getString("id"), group.getId()); + assertEquals(otherResponse.body().jsonPath().getString("description"), newLocGroup.getDescription()); + List assignedLocations = otherResponse.body().jsonPath().getList("assigned-locations", AssignedLocation.class); + boolean found = false; + for (AssignedLocation assignedLocation : assignedLocations) { + if (assignedLocation.getLocationId().equals(locationId)) { + assertEquals(assignedLocation.getLocationId(), locationId); + assertNull(assignedLocation.getAliasId()); + assertNull(assignedLocation.getRefLocationId()); + found = true; + } + } + assertTrue(found); // patch the location group owned by CWMS office given()