Skip to content

Commit

Permalink
Merge pull request #606 from USACE/devops/office_format_tweaks
Browse files Browse the repository at this point in the history
Additional tests. Correct formats. Remove CSV and Tab from list. (sti…
  • Loading branch information
MikeNeilson authored Apr 8, 2024
2 parents 4592fda + fa5604c commit a8ede4b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
14 changes: 5 additions & 9 deletions cwms-data-api/src/main/java/cwms/cda/api/OfficeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import cwms.cda.formatters.OfficeFormatV1;
import cwms.cda.formatters.csv.CsvV1Office;
import cwms.cda.formatters.tab.TabV1Office;
import cwms.cda.formatters.xml.XMLv1Office;
import io.javalin.apibuilder.CrudHandler;
import io.javalin.core.util.Header;
import io.javalin.http.Context;
Expand Down Expand Up @@ -83,9 +84,7 @@ private Timer.Context markAndTime(String subject) {
@OpenApiContent(from = OfficeFormatV1.class, type = ""),
@OpenApiContent(from = Office.class, isArray = true, type = Formats.JSONV2),
@OpenApiContent(from = OfficeFormatV1.class, type = Formats.JSON),
@OpenApiContent(from = TabV1Office.class, type = Formats.TAB),
@OpenApiContent(from = CsvV1Office.class, type = Formats.CSV),
@OpenApiContent(from = CsvV1Office.class, type = Formats.XML)
@OpenApiContent(from = XMLv1Office.class, type = Formats.XML)
}),
}, tags = { "Offices" }
)
Expand Down Expand Up @@ -128,13 +127,10 @@ public void getAll(Context ctx) {
description = "A list of offices.",
content = {
@OpenApiContent(from = OfficeFormatV1.class, type = ""),
@OpenApiContent(from = Office.class,
isArray = true,
type = Formats.JSONV2),
@OpenApiContent(from = Office.class, isArray = true, type = Formats.JSONV2),
@OpenApiContent(from = OfficeFormatV1.class, type = Formats.JSON),
@OpenApiContent(from = TabV1Office.class, type = Formats.TAB),
@OpenApiContent(from = CsvV1Office.class, type = Formats.CSV),
@OpenApiContent(from = CsvV1Office.class, type = Formats.XML)
@OpenApiContent(from = Office.class, type = Formats.XML),
@OpenApiContent(from = Office.class, type = Formats.XMLV2)
})
}, tags = { "Offices" })
@Override
Expand Down
2 changes: 2 additions & 0 deletions cwms-data-api/src/main/java/cwms/cda/data/dto/Office.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import cwms.cda.formatters.json.JsonV2;
import cwms.cda.formatters.tab.TabV1;
import cwms.cda.formatters.xml.XMLv1;
import cwms.cda.formatters.xml.XMLv2;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "A representation of a CWMS office")
@XmlRootElement(name="office")
@XmlAccessorType(XmlAccessType.FIELD)
@FormattableWith(contentType = Formats.XML, formatter = XMLv1.class)
@FormattableWith(contentType = Formats.XMLV2, formatter = XMLv2.class)
@FormattableWith(contentType = Formats.JSON, formatter = JsonV1.class)
@FormattableWith(contentType = Formats.JSONV2, formatter = JsonV2.class)
@FormattableWith(contentType = Formats.CSV, formatter = CsvV1.class)
Expand Down
43 changes: 43 additions & 0 deletions cwms-data-api/src/test/java/cwms/cda/api/OfficeControllerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,47 @@ void test_get_one() {
;

}

@Test
void test_get_one_xmlv2() {

given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.XMLV2)
.contentType(Formats.XMLV2)
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/offices/" + OFFICE)
.then()
.assertThat()
.log().ifValidationFails(LogDetail.ALL,true)
.statusCode(is(HttpServletResponse.SC_OK))
.header(Header.ETAG, not(isEmptyOrNullString()))
.headers(Header.CACHE_CONTROL.toLowerCase(), containsString("max-age="))
.body("office.long-name", containsString("Sacramento"))
;
}

@Test
void test_get_one_xmlv1() {

given()
.log().ifValidationFails(LogDetail.ALL,true)
.accept(Formats.XML)
.contentType(Formats.XML)
.when()
.redirects().follow(true)
.redirects().max(3)
.get("/offices/" + OFFICE)
.then()
.assertThat()
.log().ifValidationFails(LogDetail.ALL,true)
.statusCode(is(HttpServletResponse.SC_OK))
.header(Header.ETAG, not(isEmptyOrNullString()))
.headers(Header.CACHE_CONTROL.toLowerCase(), containsString("max-age="))
.body("office.long-name", containsString("Sacramento"))
;

}
}

0 comments on commit a8ede4b

Please sign in to comment.