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 @@ -410,92 +410,31 @@ void testPostAndDeleteSeason() throws Exception

String newSeasonId = response.jsonPath().getString("abbr");

// Retrieve Season and assert that it matches stored data
// Retrieve All Seasons and assert that the new one is in the list
response = given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", authHeader)
.filter(sessionFilter)
.queryParam("abbr", newSeasonId)
.when()
.redirects().follow(true)
.redirects().max(3)
.get("season")
.get("seasons")
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_OK))
.extract()
;

JsonPath actual = response.body().jsonPath();
JsonPath expected = new JsonPath(seasonJson);
assertEquals(expected.getString("abbr"), actual.getString("abbr"));
assertEquals(expected.getString("name"), actual.getString("name"));
assertEquals(expected.getString("start"), actual.getString("start"));
assertEquals(expected.getString("end"), actual.getString("end"));
assertEquals(expected.getString("tz"), actual.getString("tz"));

// Delete Season
given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", authHeader)
.filter(sessionFilter)
.queryParam("abbr", newSeasonId)
.when()
.redirects().follow(true)
.redirects().max(3)
.delete("season")
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_NO_CONTENT))
;

// Retrieve Season and assert that it is not found
given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", authHeader)
.filter(sessionFilter)
.queryParam("abbr", newSeasonId)
.when()
.redirects().follow(true)
.redirects().max(3)
.get("season")
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_NOT_FOUND))
;
}

@TestTemplate
void testPostAndDeleteSeasonWithFromAbbr() throws Exception
{
String seasonJson = getJsonFromResource("reflist_season_from_abbr_insert_data.json");

// Store Season
ExtractableResponse<Response> response = given()
.log().ifValidationFails(LogDetail.ALL, true)
.accept(MediaType.APPLICATION_JSON)
.header("Authorization", authHeader)
.contentType(MediaType.APPLICATION_JSON)
.filter(sessionFilter)
.body(seasonJson)
.when()
.redirects().follow(true)
.redirects().max(3)
.post("season")
.then()
.log().ifValidationFails(LogDetail.ALL, true)
.assertThat()
.statusCode(is(HttpServletResponse.SC_CREATED))
.extract()
;

String newSeasonId = response.jsonPath().getString("abbr");
Map<String, Object> actualMap = (Map<String, Object>) response.body().jsonPath().getList("").stream()
.filter(o -> ((Map<String, Object>)o).get("abbr").equals(expected.getString("abbr"))).findAny().get();
assertEquals(expected.getString("abbr"), actualMap.get("abbr").toString());
assertEquals(expected.getString("name"), actualMap.get("name").toString());
assertEquals(expected.getString("start"), actualMap.get("start").toString());
assertEquals(expected.getString("end"), actualMap.get("end").toString());
assertEquals(expected.getString("tz"), actualMap.get("tz").toString());

// Retrieve Season and assert that it matches stored data
response = given()
Expand All @@ -516,13 +455,11 @@ void testPostAndDeleteSeasonWithFromAbbr() throws Exception
;

JsonPath actual = response.body().jsonPath();
JsonPath expected = new JsonPath(seasonJson);
assertEquals(expected.getString("abbr"), actual.getString("abbr"));
assertEquals(expected.getString("name"), actual.getString("name"));
assertEquals(expected.getString("start"), actual.getString("start"));
assertEquals(expected.getString("end"), actual.getString("end"));
assertEquals(expected.getString("tz"), actual.getString("tz"));
assertEquals(expected.getString("fromAbbr"), actual.getString("fromAbbr"));

// Delete Season
given()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,12 @@ static ArrayList<ApiSeason> mapSeasons(DbEnum seasons)
for (EnumValue val : seasons.values())
{
ApiSeason as = new ApiSeason();
as.setName(val.getFullName());
as.setName(val.getDescription());
as.setAbbr(val.getValue());
String[] startEndTZ = val.getEditClassName().split(" ");
as.setStart(startEndTZ[0]);
as.setEnd(startEndTZ[1]);
as.setSortNumber(val.getSortNumber());
if (startEndTZ.length > 2)
{
as.setTz(startEndTZ[2]);
Expand Down Expand Up @@ -490,9 +491,7 @@ static ApiSeason map(EnumValue season)
},
tags = {"REST - Reference Lists"}
)
public Response postSeason(@Parameter(description = "Abbreviation of the existing season to modify")
@QueryParam("fromabbr") String fromAbbr,
@Parameter(description = "Details of the new or updated season", required = true) ApiSeason season)
public Response postSeason(@Parameter(description = "Details of the new or updated season", required = true) ApiSeason season)
throws DbException
{
try (EnumDAI dai = getLegacyTimeseriesDB().makeEnumDAO())
Expand All @@ -510,12 +509,13 @@ public Response postSeason(@Parameter(description = "Abbreviation of the existin
{
dbSeasonId = dbEnum.getId();
}
if (fromAbbr != null)
String fromabbr = season.getFromabbr();
if (fromabbr != null)
{
dai.deleteEnumValue(dbSeasonId, fromAbbr);
dai.deleteEnumValue(dbSeasonId, fromabbr);
}
EnumValue dbSeason = map(season, dbEnum);
dai.writeEnumValue(dbSeasonId, dbSeason, fromAbbr, season.getSortNumber());
dai.writeEnumValue(dbSeasonId, dbSeason, null, season.getSortNumber());
return Response.status(HttpServletResponse.SC_CREATED)
.entity(map(dbSeason))
.build();
Expand All @@ -540,13 +540,6 @@ static EnumValue map(ApiSeason season, DbEnum dbEnum)
return ret;
}

static DbEnum map(ApiSeason season, String fromAbbr)
{
DbEnum ret = new DbEnum(season.getName());
ret.setDefault(fromAbbr);
return ret;
}

@DELETE
@Path("season")
@Consumes(MediaType.APPLICATION_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void testSeasonMap() throws Exception
assertNotNull(seasons);
ApiSeason season = seasons.get(0);
assertEquals(enumValue.getValue(), season.getAbbr());
assertEquals(enumValue.getFullName(), season.getName());
assertEquals(enumValue.getDescription(), season.getName());
assertEquals(enumValue.getEditClassName(),
String.format("%s %s %s", season.getStart(), season.getEnd(), season.getTz()));
}
Expand Down Expand Up @@ -110,24 +110,7 @@ void testSeasonApiMap()
assertEquals(season.getStart(), startEndTzArray[0]);
assertEquals(season.getEnd(), startEndTzArray[1]);
assertEquals(season.getTz(), startEndTzArray[2]);
}

@Test
void testEnumSeasonMap()
{
ApiSeason season = new ApiSeason();
String abbr = "m";
season.setAbbr(abbr);
season.setName("Meter");
season.setStart("start");
season.setEnd("end");
season.setSortNumber(1);
season.setTz("UTC");

DbEnum dbEnum = map(season, abbr);

assertNotNull(dbEnum);
assertEquals(season.getName(), dbEnum.getUniqueName());
assertEquals(season.getSortNumber(), result.getSortNumber());
}

@Test
Expand Down
Loading