Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@

import static cwms.cda.api.Controllers.METHOD;
import static cwms.cda.api.Controllers.OFFICE;
import static cwms.cda.api.Controllers.PAGE_SIZE;
import static cwms.cda.api.Controllers.RATING_ID_MASK;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Tag("integration")
Expand Down Expand Up @@ -101,8 +103,26 @@ void test_empty_rating_spec() throws Exception {
.log().ifValidationFails(LogDetail.ALL,true)
.statusCode(is(HttpServletResponse.SC_CREATED));

RatingSpec ratingSpec = new RatingSpec(new RatingSpec.Builder().fromRatingSpec(new hec.data.cwmsRating.RatingSpec(specContainer)));

// Read and verify no failure on missing office ID
Response response = given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSONV2)
.queryParam(PAGE_SIZE, 500)
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/ratings/metadata");
JsonPath noOfficePath = new JsonPath(response.asString());
assertFalse(noOfficePath.getList("rating-metadata").isEmpty());
boolean foundMatching = IntStream.range(0, noOfficePath.getInt("rating-metadata.size()"))
.mapToObj(i -> noOfficePath.getObject("rating-metadata[" + i + "].rating-spec", RatingSpec.class))
.anyMatch(s -> s.hashCode() == ratingSpec.hashCode());
assertTrue(foundMatching);

//Read
Response response =
response =
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.JSONV2)
Expand All @@ -114,10 +134,9 @@ void test_empty_rating_spec() throws Exception {
.redirects().max(3)
.get("/ratings/metadata");
// then follows
RatingSpec ratingSpec = new RatingSpec(new RatingSpec.Builder().fromRatingSpec(new hec.data.cwmsRating.RatingSpec(specContainer)));
JsonPath path = new JsonPath(response.asString());
//get values of JSON array after getting array size
boolean foundMatching = IntStream.range(0, path.getInt("rating-metadata.size()"))
foundMatching = IntStream.range(0, path.getInt("rating-metadata.size()"))
.mapToObj(i -> path.getObject("rating-metadata[" + i + "].rating-spec", RatingSpec.class))
.anyMatch(s -> s.hashCode() == ratingSpec.hashCode());
assertTrue(foundMatching);
Expand Down
Loading