From 9f925ce808d07ffbabc2ac74811b3e6bbf2df1cd Mon Sep 17 00:00:00 2001 From: zack-rma Date: Fri, 8 May 2026 14:08:06 -0700 Subject: [PATCH] Added test to confirm error message is properly handled for timeseries posted to nonexistent sub-location --- .../cda/api/TimeseriesControllerTestIT.java | 44 +++++++++++++++++++ .../lrl/timeseries_nonexistent_subloc.json | 35 +++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 cwms-data-api/src/test/resources/cwms/cda/api/lrl/timeseries_nonexistent_subloc.json diff --git a/cwms-data-api/src/test/java/cwms/cda/api/TimeseriesControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/TimeseriesControllerTestIT.java index 9e69627c8..b5a85dffe 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/TimeseriesControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/TimeseriesControllerTestIT.java @@ -11,6 +11,7 @@ import static cwms.cda.api.Controllers.OFFICE; import static cwms.cda.api.Controllers.OVERRIDE_PROTECTION; import static cwms.cda.api.Controllers.START_TIME_INCLUSIVE; +import static cwms.cda.api.Controllers.STORE_RULE; import static cwms.cda.api.Controllers.TRIM; import static cwms.cda.api.Controllers.UNIT; import static cwms.cda.api.Controllers.VERSION_DATE; @@ -31,6 +32,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import cwms.cda.ApiServlet; +import cwms.cda.data.dao.StoreRule; import cwms.cda.data.dao.VerticalDatum; import cwms.cda.data.dto.TimeSeries; import cwms.cda.data.dto.VerticalDatumInfo; @@ -1029,6 +1031,48 @@ void test_attempt_store_with_entry_date() throws Exception ; } + @Test + void test_attempt_store_for_nonexistent_subloc() throws Exception + { + ObjectMapper mapper = new ObjectMapper(); + + InputStream resource = this.getClass().getResourceAsStream( + "/cwms/cda/api/lrl/timeseries_nonexistent_subloc.json"); + assertNotNull(resource); + + String tsData = IOUtils.toString(resource, StandardCharsets.UTF_8); + + JsonNode ts = mapper.readTree(tsData); + String location = ts.get(NAME).asText().split("\\.")[0].split("-")[0]; + String officeId = ts.get("office-id").asText(); + createLocation(location, true, officeId); + + TestAccounts.KeyUser user = TestAccounts.KeyUser.SPK_NORMAL; + + // inserting the time series + given() + .log().ifValidationFails(LogDetail.ALL, true) + .accept(Formats.DEFAULT) + .contentType(Formats.JSONV2) + .body(tsData) + .header("Authorization", user.toHeaderValue()) + .queryParam(OFFICE, officeId) + .queryParam(CREATE_AS_LRTS, "false") + .queryParam(STORE_RULE, StoreRule.REPLACE_ALL.toString()) + .queryParam(OVERRIDE_PROTECTION, "false") + .when() + .redirects().follow(true) + .redirects().max(3) + .post("/timeseries/") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_NOT_FOUND)) + .body("message", equalTo("ORA-20025: LOCATION_ID_NOT_FOUND: The Location: \"Buckhorn-Subloc\" does not exist.")) + .body("source", equalTo("Database")) + ; + } + @Test void test_delete_ts() throws Exception { ObjectMapper mapper = new ObjectMapper(); diff --git a/cwms-data-api/src/test/resources/cwms/cda/api/lrl/timeseries_nonexistent_subloc.json b/cwms-data-api/src/test/resources/cwms/cda/api/lrl/timeseries_nonexistent_subloc.json new file mode 100644 index 000000000..c40a9d3c1 --- /dev/null +++ b/cwms-data-api/src/test/resources/cwms/cda/api/lrl/timeseries_nonexistent_subloc.json @@ -0,0 +1,35 @@ +{ + "name": "Buckhorn-Subloc.Temp-Water.Inst.1Day.0.cda-test", + "office-id": "SPK", + "units": "F", + "begin": 1675335600000, + "end": 1675422000000, + "version-date": 1594786000000, + "value-columns" : [ + { + "name" : "date-time", + "ordinal" : 1, + "datatype" : "java.sql.Timestamp" + }, { + "name" : "value", + "ordinal" : 2, + "datatype" : "java.lang.Double" + }, { + "name" : "quality-code", + "ordinal" : 3, + "datatype" : "int" + } + ], + "values": [ + [ + 1675335600000, + 35, + 0 + ], + [ + 1675422000000, + 36, + 0 + ] + ] +} \ No newline at end of file