Skip to content
Merged
Show file tree
Hide file tree
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 @@ -77,6 +77,7 @@
import hec.data.cwmsRating.RatingSet;
import io.javalin.core.util.Header;
import io.javalin.core.validation.JavalinValidation;
import io.javalin.http.BadRequestResponse;
import io.javalin.http.Context;
import io.javalin.http.HttpCode;
import io.javalin.plugin.openapi.annotations.HttpMethod;
Expand All @@ -87,6 +88,8 @@
import io.javalin.plugin.openapi.annotations.OpenApiResponse;
import java.io.IOException;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.TransformerException;
import mil.army.usace.hec.cwms.rating.io.xml.RatingXmlFactory;
Expand Down Expand Up @@ -296,12 +299,12 @@ public void delete(@NotNull Context ctx, @NotNull String ratingSpecId) {
+ "field for this URI are:"
+ "\n* `tab`"
+ "\n* `csv`"
+ "\n* `xml`"
+ "\n* `json` (default)")},
+ "\n* `xml` (default)"
+ "\n* `json`")},
responses = {
@OpenApiResponse(status = STATUS_200, content = {
@OpenApiContent(type = Formats.JSON),
@OpenApiContent(type = Formats.XML),
@OpenApiContent(type = Formats.JSONV2),
@OpenApiContent(type = Formats.XMLV2),
@OpenApiContent(type = Formats.TAB),
@OpenApiContent(type = Formats.CSV)
}),
Expand All @@ -327,6 +330,11 @@ public void getAll(@NotNull Context ctx) {
String timezone = ctx.queryParamAsClass(TIMEZONE, String.class).getOrDefault("UTC");

String format = ctx.queryParamAsClass(FORMAT, String.class).getOrDefault("");
if (!format.isEmpty() && !format.contains("version=2")) {
Map<String, String> details = new HashMap<>();
details.put("message", String.format("Invalid format. V1 formats no longer supported: %s", format));
throw new BadRequestResponse("", details);
}
String header = ctx.header(Header.ACCEPT);

ContentType contentType = Formats.parseHeaderAndQueryParm(header, format, RatingAliasMarker.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

import static cwms.cda.api.Controllers.*;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -307,35 +308,36 @@ static void storeLong() throws Exception
@EnumSource(GetAllLegacyTest.class)
void test_getAll_legacy(GetAllLegacyTest test) {
given()
.log().ifValidationFails(LogDetail.ALL,true)
.queryParam(FORMAT, test.queryParam)
.log().ifValidationFails(LogDetail.ALL,true)
.queryParam(FORMAT, test.queryParam)
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/ratings")
.redirects().follow(true)
.redirects().max(3)
.get("/ratings")
.then()
.assertThat()
.log().ifValidationFails(LogDetail.ALL,true)
.statusCode(is(HttpServletResponse.SC_OK))
.contentType(is(test.expectedContentType));

.log().ifValidationFails(LogDetail.ALL,true)
.statusCode(is(HttpServletResponse.SC_BAD_REQUEST))
.body("message", equalTo("Bad Request"))
.body("source", equalTo("User Input"))
.body("details.message", equalTo("Invalid format. V1 formats no longer supported: " + test.queryParam));
}

@ParameterizedTest
@EnumSource(GetAllTest.class)
void test_getAll(GetAllTest test) {
given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(test.accept)
.log().ifValidationFails(LogDetail.ALL,true)
.accept(test.accept)
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/ratings")
.redirects().follow(true)
.redirects().max(3)
.get("/ratings")
.then()
.assertThat()
.log().ifValidationFails(LogDetail.ALL,true)
.statusCode(is(HttpServletResponse.SC_OK))
.contentType(is(test.expectedContentType));
.log().ifValidationFails(LogDetail.ALL,true)
.statusCode(is(HttpServletResponse.SC_OK))
.contentType(is(test.expectedContentType));
}

@ParameterizedTest
Expand Down Expand Up @@ -445,9 +447,7 @@ void get_one_with_content_length() {
enum GetOneTest
{
DEFAULT(Formats.DEFAULT, Formats.XMLV2),
XML(Formats.XML, Formats.XMLV2),
XMLV2(Formats.XMLV2, Formats.XMLV2),
JSON(Formats.JSON, Formats.JSONV2),
JSONV2(Formats.JSONV2, Formats.JSONV2),
;

Expand Down Expand Up @@ -480,11 +480,7 @@ enum GetAllLegacyTest
enum GetAllTest
{
DEFAULT(Formats.DEFAULT, Formats.XMLV2),
XML(Formats.XML, Formats.XMLV2),
XMLV1(Formats.XMLV1, Formats.XMLV1),
XMLV2(Formats.XMLV2, Formats.XMLV2),
JSON(Formats.JSON, Formats.JSONV2),
JSONV1(Formats.JSONV1, Formats.JSONV1),
JSONV2(Formats.JSONV2, Formats.JSONV2),
;

Expand Down
Loading