diff --git a/cwms-data-api/src/main/java/cwms/cda/api/BasinController.java b/cwms-data-api/src/main/java/cwms/cda/api/BasinController.java index 215bb2ab65..39eb6e28e9 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/BasinController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/BasinController.java @@ -45,6 +45,7 @@ import cwms.cda.data.dao.JooqDao; import cwms.cda.data.dao.basinconnectivity.BasinDao; import cwms.cda.data.dto.CwmsId; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.basinconnectivity.Basin; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -251,7 +252,8 @@ public void update(@NotNull Context ctx, @NotNull String name) { .withOfficeId(officeId) .build(); basinDao.renameBasin(oldLoc, newLoc); - ctx.status(HttpServletResponse.SC_OK).json("Updated Location"); + StatusResponse re = new StatusResponse(officeId, "Updated Location", newBasinId); + ctx.status(HttpServletResponse.SC_OK).json(re); } @OpenApi( @@ -276,13 +278,15 @@ public void create(@NotNull Context ctx) { String newBasinId = basin.getBasinId().getName(); cwms.cda.data.dao.basin.BasinDao basinDao = new cwms.cda.data.dao.basin.BasinDao(dsl); basinDao.storeBasin(basin); - ctx.status(HttpServletResponse.SC_CREATED).json(newBasinId + " Created"); + StatusResponse re = new StatusResponse(basin.getBasinId().getOfficeId(), + "Basin successfully stored to CWMS.", newBasinId); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } @OpenApi( queryParams = { @OpenApiParam(name = OFFICE, required = true, description = "Specifies the" - + " owning office of the basin to be renamed."), + + " owning office of the basin to be deleted."), @OpenApiParam(name = METHOD, required = true, description = "Specifies the delete method used.", type = JooqDao.DeleteMethod.class) }, @@ -290,7 +294,7 @@ public void create(@NotNull Context ctx) { @OpenApiParam(name = NAME, description = "Specifies the name of " + "the basin to be deleted.") }, - description = "Renames CWMS Basin", + description = "Deletes CWMS Basin", tags = {TAG} ) @Override @@ -303,6 +307,7 @@ public void delete(@NotNull Context ctx, @NotNull String name) { .withOfficeId(ctx.queryParam(OFFICE)) .build(); basinDao.deleteBasin(basinId, deleteMethod.getRule()); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(basinId.getName() + " Deleted"); + StatusResponse re = new StatusResponse(basinId.getOfficeId(), "Deleted CWMS Basin", basinId.getName()); + ctx.status(HttpServletResponse.SC_OK).json(re); } } \ No newline at end of file diff --git a/cwms-data-api/src/main/java/cwms/cda/api/EmbankmentController.java b/cwms-data-api/src/main/java/cwms/cda/api/EmbankmentController.java index a735277624..1db14e6160 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/EmbankmentController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/EmbankmentController.java @@ -29,6 +29,7 @@ import com.codahale.metrics.Timer; import cwms.cda.data.dao.JooqDao; import cwms.cda.data.dao.location.kind.EmbankmentDao; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.location.kind.Embankment; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -167,7 +168,9 @@ public void create(Context ctx) { DSLContext dsl = getDslContext(ctx); EmbankmentDao dao = new EmbankmentDao(dsl); dao.storeEmbankment(embankment, failIfExists); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Embankment"); + StatusResponse re = new StatusResponse(embankment.getLocation().getOfficeId(), + "Embankment successfully stored to CWMS", embankment.getLocation().getName()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } @@ -197,7 +200,8 @@ public void update(@NotNull Context ctx, @NotNull String name) { DSLContext dsl = getDslContext(ctx); EmbankmentDao dao = new EmbankmentDao(dsl); dao.renameEmbankment(office, name, newName); - ctx.status(HttpServletResponse.SC_OK).json("Renamed Embankment"); + StatusResponse re = new StatusResponse(office, "Embankment successfully renamed in CWMS", newName); + ctx.status(HttpServletResponse.SC_OK).json(re); } } @@ -217,7 +221,7 @@ public void update(@NotNull Context ctx, @NotNull String name) { method = HttpMethod.DELETE, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Embankment successfully deleted from CWMS."), + @OpenApiResponse(status = STATUS_200, description = "Embankment successfully deleted from CWMS."), @OpenApiResponse(status = STATUS_404, description = "Based on the combination of " + "inputs provided the embankment was not found.") } @@ -231,7 +235,8 @@ public void delete(@NotNull Context ctx, @NotNull String name) { DSLContext dsl = getDslContext(ctx); EmbankmentDao dao = new EmbankmentDao(dsl); dao.deleteEmbankment(name, office, deleteMethod.getRule()); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(name + " Deleted"); + StatusResponse re = new StatusResponse(office, "Embankment successfully deleted from CWMS", name); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } \ No newline at end of file diff --git a/cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java b/cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java index d6cdc684ab..ff23602077 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/LevelsController.java @@ -43,6 +43,7 @@ import cwms.cda.api.enums.UnitSystem; import cwms.cda.data.dao.LocationLevelsDao; import cwms.cda.data.dao.LocationLevelsDaoImpl; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.locationlevel.ConstantLocationLevel; import cwms.cda.data.dto.locationlevel.LocationLevel; import cwms.cda.data.dto.locationlevel.LocationLevels; @@ -119,7 +120,8 @@ public void create(@NotNull Context ctx) { DSLContext dsl = getDslContext(ctx); LocationLevelsDao levelsDao = getLevelsDao(dsl); levelsDao.storeLocationLevel(level); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Location Level"); + StatusResponse re = new StatusResponse(level.getOfficeId(),"Created Location Level", level.getLocationLevelId()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } catch (IOException e) { throw new IllegalArgumentException("Unable to parse the request body", e); } @@ -185,7 +187,8 @@ public void delete(@NotNull Context ctx, @NotNull String levelId) { ? DateUtils.parseUserDate(dateString, timezone) : null; LocationLevelsDao levelsDao = getLevelsDao(dsl); levelsDao.deleteLocationLevel(levelId, unmarshalledDateTime, office, cascadeDelete); - ctx.status(HttpServletResponse.SC_OK).json(levelId + " Deleted"); + StatusResponse re = new StatusResponse(office,"CWMS Location Level Deleted", levelId); + ctx.status(HttpServletResponse.SC_OK).json(re); } } @@ -411,7 +414,8 @@ public void update(@NotNull Context ctx, @NotNull String oldLevelId) { if (!oldLevelId.equals(newLevelId)) { //if name changed then delete location with old name levelsDao.renameLocationLevel(oldLevelId, newLevelId, officeId); - ctx.status(HttpServletResponse.SC_OK).json("Renamed Location Level"); + StatusResponse re = new StatusResponse(officeId,"Renamed Location Level", newLevelId); + ctx.status(HttpServletResponse.SC_OK).json(re); } else { String dateString = queryParamAsClass(ctx, new String[]{EFFECTIVE_DATE, DATE}, String.class, null, metrics, @@ -432,7 +436,8 @@ public void update(@NotNull Context ctx, @NotNull String oldLevelId) { levelFromBody, unmarshalledDateTime); levelsDao.storeLocationLevel(updatedLocationLevel); - ctx.status(HttpServletResponse.SC_OK).json("Updated Location Level"); + StatusResponse re = new StatusResponse(officeId,"Updated Location Level", newLevelId); + ctx.status(HttpServletResponse.SC_OK).json(re); } } catch (JsonProcessingException ex) { throw new FormattingException("Failed to format location level update request", ex); diff --git a/cwms-data-api/src/main/java/cwms/cda/api/LocationController.java b/cwms-data-api/src/main/java/cwms/cda/api/LocationController.java index 98556c834b..0e46e6f58e 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/LocationController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/LocationController.java @@ -62,6 +62,7 @@ import cwms.cda.data.dao.LocationsDao; import cwms.cda.data.dao.LocationsDaoImpl; import cwms.cda.data.dto.Location; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; import cwms.cda.formatters.UnsupportedFormatException; @@ -306,7 +307,8 @@ public void create(@NotNull Context ctx) { Location locationFromBody = Formats.parseContent(contentType, ctx.body(), Location.class); boolean failIfExists = ctx.queryParamAsClass(FAIL_IF_EXISTS, Boolean.class).getOrDefault(true); locationsDao.storeLocation(locationFromBody, failIfExists); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Location"); + StatusResponse re = new StatusResponse(locationFromBody.getOfficeId(),"Created Location", locationFromBody.getName()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } catch (IOException ex) { CdaError re = new CdaError("failed to process request"); logger.log(Level.SEVERE, re.toString(), ex); @@ -351,10 +353,12 @@ public void update(@NotNull Context ctx, @NotNull String locationId) { if (!updatedLocation.getName().equalsIgnoreCase(existingLocation.getName())) { //if name changed then delete location with old name locationsDao.renameLocation(locationId, updatedLocation); - ctx.status(HttpServletResponse.SC_OK).json("Updated and renamed Location"); + ctx.status(HttpServletResponse.SC_OK).json(new StatusResponse(updatedLocation.getOfficeId(), + "Updated and renamed Location", updatedLocation.getName())); } else { locationsDao.storeLocation(updatedLocation, false); - ctx.status(HttpServletResponse.SC_OK).json("Updated Location"); + ctx.status(HttpServletResponse.SC_OK).json(new StatusResponse(updatedLocation.getOfficeId(), + "Updated Location", updatedLocation.getName())); } } catch (NotFoundException e) { CdaError re = new CdaError("Not found."); @@ -386,6 +390,7 @@ public void update(@NotNull Context ctx, @NotNull String locationId) { path = "/locations", tags = {"Locations"}, responses = { + @OpenApiResponse(status = STATUS_200, description = "Location successfully deleted from CWMS."), @OpenApiResponse(status = STATUS_404, description = "Based on the combination of " + "inputs provided the location was not found.") } @@ -400,7 +405,8 @@ public void delete(@NotNull Context ctx, @NotNull String locationId) { LocationsDao locationsDao = getLocationsDao(dsl); boolean cascadeDelete = ctx.queryParamAsClass(CASCADE_DELETE, Boolean.class).getOrDefault(false); locationsDao.deleteLocation(locationId, office, cascadeDelete); - ctx.status(HttpServletResponse.SC_OK).json(locationId + " Deleted"); + StatusResponse re = new StatusResponse(office,"Deleted CWMS Location", locationId); + ctx.status(HttpServletResponse.SC_OK).json(re); } catch (DataAccessException ex) { SQLException cause = ex.getCause(SQLException.class); if (cause != null && cause.getErrorCode() == 20031) { diff --git a/cwms-data-api/src/main/java/cwms/cda/api/LookupTypeController.java b/cwms-data-api/src/main/java/cwms/cda/api/LookupTypeController.java index e3b70700f9..1390398626 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/LookupTypeController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/LookupTypeController.java @@ -29,6 +29,7 @@ import com.codahale.metrics.Timer; import cwms.cda.data.dao.LookupTypeDao; import cwms.cda.data.dto.LookupType; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; import io.javalin.apibuilder.CrudHandler; @@ -138,7 +139,9 @@ public void create(Context ctx) { DSLContext dsl = getDslContext(ctx); LookupTypeDao dao = new LookupTypeDao(dsl); dao.storeLookupType(category, prefix, lookupType); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Lookup Type"); + StatusResponse re = new StatusResponse(lookupType.getOfficeId(), "Lookup Type successfully stored to CWMS.", + lookupType.getDisplayValue()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } @@ -156,7 +159,7 @@ public void create(Context ctx) { method = HttpMethod.PATCH, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Lookup Type successfully stored to CWMS.") + @OpenApiResponse(status = STATUS_200, description = "Updated Lookup Type") } ) @Override @@ -170,7 +173,9 @@ public void update(Context ctx, String name) { DSLContext dsl = getDslContext(ctx); LookupTypeDao dao = new LookupTypeDao(dsl); dao.updateLookupType(category, prefix, lookupType); - ctx.status(HttpServletResponse.SC_OK).json("Updated Lookup Type"); + StatusResponse re = new StatusResponse(lookupType.getOfficeId(), "Updated Lookup Type", + lookupType.getDisplayValue()); + ctx.status(HttpServletResponse.SC_OK).json(re); } } @@ -184,7 +189,7 @@ public void update(Context ctx, String name) { method = HttpMethod.DELETE, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Lookup Type successfully deleted from CWMS."), + @OpenApiResponse(status = STATUS_200, description = "Lookup Type successfully deleted from CWMS."), @OpenApiResponse(status = STATUS_404, description = "Based on the combination of inputs provided the lookup type was not found.") } ) @@ -197,7 +202,8 @@ public void delete(Context ctx, @NotNull String displayValue) { DSLContext dsl = getDslContext(ctx); LookupTypeDao dao = new LookupTypeDao(dsl); dao.deleteLookupType(category, prefix, officeId, displayValue); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(displayValue + " Deleted"); + StatusResponse re = new StatusResponse(officeId, "Lookup Type successfully deleted from CWMS.", displayValue); + ctx.status(HttpServletResponse.SC_OK).json(re); } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/MeasurementController.java b/cwms-data-api/src/main/java/cwms/cda/api/MeasurementController.java index 8f2607176d..1288dcc28a 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/MeasurementController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/MeasurementController.java @@ -49,6 +49,8 @@ import static cwms.cda.api.Controllers.OFFICE; import static cwms.cda.api.Controllers.OFFICE_MASK; import static cwms.cda.api.Controllers.QUALITY; +import static cwms.cda.api.Controllers.STATUS_200; +import static cwms.cda.api.Controllers.STATUS_404; import static cwms.cda.api.Controllers.TIMEZONE; import static cwms.cda.api.Controllers.UNIT_SYSTEM; import static cwms.cda.api.Controllers.queryParamAsDouble; @@ -56,6 +58,7 @@ import static cwms.cda.api.Controllers.requiredParam; import cwms.cda.api.enums.UnitSystem; import cwms.cda.data.dao.MeasurementDao; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.measurement.Measurement; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -188,7 +191,7 @@ public void getOne(@NotNull Context ctx, @NotNull String locationId) { method = HttpMethod.POST, tags = {TAG}, responses = { - @OpenApiResponse(status = "204", description = "Measurement(s) successfully stored.") + @OpenApiResponse(status = "201", description = "Measurement(s) successfully stored.") } ) @Override @@ -202,12 +205,8 @@ public void create(Context ctx) { DSLContext dsl = getDslContext(ctx); MeasurementDao dao = new MeasurementDao(dsl); dao.storeMeasurements(measurements, failIfExists); - String statusMsg = "Created Measurement"; - if(measurements.size() > 1) - { - statusMsg += "s"; - } - ctx.status(HttpServletResponse.SC_CREATED).json(statusMsg); + StatusResponse re = new StatusResponse(measurements.get(0).getOfficeId(), "Measurement(s) successfully stored."); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } @@ -245,8 +244,8 @@ public void update(@NotNull Context ctx, @NotNull String locationId) { method = HttpMethod.DELETE, tags = {TAG}, responses = { - @OpenApiResponse(status = "204", description = "Measurement successfully deleted."), - @OpenApiResponse(status = "404", description = "Measurement not found.") + @OpenApiResponse(status = STATUS_200, description = "Measurement successfully deleted."), + @OpenApiResponse(status = STATUS_404, description = "Measurement not found.") } ) @Override @@ -260,7 +259,8 @@ public void delete(@NotNull Context ctx, @NotNull String locationId) { DSLContext dsl = getDslContext(ctx); MeasurementDao dao = new MeasurementDao(dsl); dao.deleteMeasurements(officeId, locationId, minDate, maxDate,minNum, maxNum); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json( "Measurements for " + locationId + " Deleted"); + StatusResponse re = new StatusResponse(officeId, "Measurement successfully deleted for specified location-id.", locationId); + ctx.status(HttpServletResponse.SC_OK).json( re); } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/PropertyController.java b/cwms-data-api/src/main/java/cwms/cda/api/PropertyController.java index aa450d8438..7a2459a1e6 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/PropertyController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/PropertyController.java @@ -29,6 +29,7 @@ import com.codahale.metrics.Timer; import cwms.cda.data.dao.PropertyDao; import cwms.cda.data.dto.Property; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; import io.javalin.apibuilder.CrudHandler; @@ -175,7 +176,9 @@ public void create(Context ctx) { DSLContext dsl = getDslContext(ctx); PropertyDao dao = new PropertyDao(dsl); dao.storeProperty(property); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Property"); + StatusResponse re = new StatusResponse(property.getOfficeId(), + "Property successfully stored to CWMS.", property.getName()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } @@ -190,7 +193,7 @@ public void create(Context ctx) { method = HttpMethod.PATCH, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Property successfully stored to CWMS.") + @OpenApiResponse(status = STATUS_200, description = "Property successfully updated in CWMS.") } ) @Override @@ -202,7 +205,9 @@ public void update(Context ctx, String name) { DSLContext dsl = getDslContext(ctx); PropertyDao dao = new PropertyDao(dsl); dao.updateProperty(property); - ctx.status(HttpServletResponse.SC_OK).json("Updated Property"); + StatusResponse re = new StatusResponse(property.getOfficeId(), + "Property successfully updated in CWMS.", property.getName()); + ctx.status(HttpServletResponse.SC_OK).json(re); } } @@ -222,7 +227,7 @@ public void update(Context ctx, String name) { method = HttpMethod.DELETE, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Property successfully deleted from CWMS."), + @OpenApiResponse(status = STATUS_200, description = "Property successfully deleted from CWMS."), @OpenApiResponse(status = STATUS_404, description = "Based on the combination of " + "inputs provided the property was not found.") } @@ -235,7 +240,8 @@ public void delete(Context ctx, String name) { DSLContext dsl = getDslContext(ctx); PropertyDao dao = new PropertyDao(dsl); dao.deleteProperty(office, category, name); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(name + " Deleted"); + StatusResponse re = new StatusResponse(office, "Property successfully deleted from CWMS.", name); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/StreamController.java b/cwms-data-api/src/main/java/cwms/cda/api/StreamController.java index d24660e7a4..62bb650f73 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/StreamController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/StreamController.java @@ -51,6 +51,7 @@ import cwms.cda.data.dao.DeleteRule; import cwms.cda.data.dao.JooqDao; import cwms.cda.data.dao.StreamDao; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.stream.Stream; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -197,7 +198,9 @@ public void create(Context ctx) { DSLContext dsl = getDslContext(ctx); StreamDao dao = new StreamDao(dsl); dao.storeStream(stream, failIfExists); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Stream"); + StatusResponse re = new StatusResponse(stream.getOfficeId(), "Stream successfully stored to CWMS.", + stream.getId().getName()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } @@ -227,7 +230,8 @@ public void update(@NotNull Context ctx, @NotNull String streamId) { DSLContext dsl = getDslContext(ctx); StreamDao dao = new StreamDao(dsl); dao.renameStream(office, streamId, newStreamId); - ctx.status(HttpServletResponse.SC_OK).json("Renamed Stream"); + StatusResponse re = new StatusResponse(office, "Stream successfully renamed in CWMS.", newStreamId); + ctx.status(HttpServletResponse.SC_OK).json(re); } } @@ -247,7 +251,7 @@ public void update(@NotNull Context ctx, @NotNull String streamId) { method = HttpMethod.DELETE, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Stream successfully deleted from CWMS."), + @OpenApiResponse(status = STATUS_200, description = "Stream successfully deleted from CWMS."), @OpenApiResponse(status = STATUS_404, description = "Based on the combination of " + "inputs provided the stream was not found.") } @@ -276,7 +280,8 @@ public void delete(@NotNull Context ctx, @NotNull String streamId) { + deleteMethod); } dao.deleteStream(office, streamId, deleteRule); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(streamId + " Deleted"); + StatusResponse re = new StatusResponse(office, "Stream successfully deleted from CWMS.", streamId); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } \ No newline at end of file diff --git a/cwms-data-api/src/main/java/cwms/cda/api/StreamLocationController.java b/cwms-data-api/src/main/java/cwms/cda/api/StreamLocationController.java index b611f6560d..3e3f4813c0 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/StreamLocationController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/StreamLocationController.java @@ -44,12 +44,13 @@ import static cwms.cda.api.Controllers.STAGE_UNIT; import static cwms.cda.api.Controllers.STATION_UNIT; import static cwms.cda.api.Controllers.STATUS_200; -import static cwms.cda.api.Controllers.STATUS_204; +import static cwms.cda.api.Controllers.STATUS_201; import static cwms.cda.api.Controllers.STATUS_404; import static cwms.cda.api.Controllers.STREAM_ID; import static cwms.cda.api.Controllers.STREAM_ID_MASK; import static cwms.cda.api.Controllers.requiredParam; import cwms.cda.data.dao.StreamLocationDao; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.stream.StreamLocation; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -191,7 +192,7 @@ public void getOne(@NotNull Context ctx, @NotNull String locationId) { method = HttpMethod.POST, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Stream Location successfully stored to CWMS.") + @OpenApiResponse(status = STATUS_201, description = "Stream Location successfully stored to CWMS.") } ) @Override @@ -204,7 +205,9 @@ public void create(Context ctx) { DSLContext dsl = getDslContext(ctx); StreamLocationDao dao = new StreamLocationDao(dsl); dao.storeStreamLocation(streamLocation, failIfExists); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Stream Location"); + StatusResponse re = new StatusResponse(streamLocation.getId().getOfficeId(), + "Stream Location successfully stored to CWMS.", streamLocation.getId().getName()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } @@ -218,7 +221,7 @@ public void create(Context ctx) { method = HttpMethod.PATCH, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Stream Location successfully updated to CWMS.") + @OpenApiResponse(status = STATUS_200, description = "Updated Stream Location") } ) @Override @@ -230,7 +233,9 @@ public void update(Context ctx, @NotNull String locationId) { DSLContext dsl = getDslContext(ctx); StreamLocationDao dao = new StreamLocationDao(dsl); dao.updateStreamLocation(streamLocation); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json("Updated Stream Location"); + StatusResponse re = new StatusResponse(streamLocation.getId().getOfficeId(), + "Updated Stream Location", streamLocation.getId().getName()); + ctx.status(HttpServletResponse.SC_OK).json(re); } } @@ -249,7 +254,7 @@ public void update(Context ctx, @NotNull String locationId) { method = HttpMethod.DELETE, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Stream Location successfully deleted from CWMS."), + @OpenApiResponse(status = STATUS_200, description = "Stream Location successfully deleted from CWMS."), @OpenApiResponse(status = STATUS_404, description = "Stream Location not found.") } ) @@ -261,7 +266,9 @@ public void delete(@NotNull Context ctx, @NotNull String locationId) { DSLContext dsl = getDslContext(ctx); StreamLocationDao dao = new StreamLocationDao(dsl); dao.deleteStreamLocation(officeId, streamId, locationId); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json("Deleted Stream Location"); + StatusResponse re = new StatusResponse(officeId, + "Stream Location successfully deleted from CWMS.", streamId); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/TurbineController.java b/cwms-data-api/src/main/java/cwms/cda/api/TurbineController.java index f6d409d58d..5be3f682e8 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/TurbineController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/TurbineController.java @@ -29,6 +29,7 @@ import com.codahale.metrics.Timer; import cwms.cda.data.dao.JooqDao; import cwms.cda.data.dao.location.kind.TurbineDao; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.location.kind.Turbine; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -155,7 +156,7 @@ public void getOne(@NotNull Context ctx, @NotNull String name) { method = HttpMethod.POST, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Turbine successfully stored to CWMS.") + @OpenApiResponse(status = STATUS_201, description = "Turbine successfully stored to CWMS.") } ) @Override @@ -169,7 +170,9 @@ public void create(Context ctx) { DSLContext dsl = getDslContext(ctx); TurbineDao dao = new TurbineDao(dsl); dao.storeTurbine(turbine, failIfExists); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Turbine"); + StatusResponse re = new StatusResponse(turbine.getLocation().getOfficeId(),"Turbine successfully stored to CWMS.", + turbine.getProjectId().getName()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } @@ -188,7 +191,7 @@ public void create(Context ctx) { method = HttpMethod.PATCH, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Turbine successfully renamed in to CWMS.") + @OpenApiResponse(status = STATUS_200, description = "Turbine successfully renamed in to CWMS.") } ) @Override @@ -199,7 +202,8 @@ public void update(@NotNull Context ctx, @NotNull String name) { DSLContext dsl = getDslContext(ctx); TurbineDao dao = new TurbineDao(dsl); dao.renameTurbine(office, name, newName); - ctx.status(HttpServletResponse.SC_OK).json("Renamed Turbine"); + StatusResponse re = new StatusResponse(office,"Turbine successfully renamed in to CWMS", newName); + ctx.status(HttpServletResponse.SC_OK).json(re); } } @@ -219,7 +223,7 @@ public void update(@NotNull Context ctx, @NotNull String name) { method = HttpMethod.DELETE, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Turbine successfully deleted from CWMS."), + @OpenApiResponse(status = STATUS_200, description = "Turbine successfully deleted from CWMS."), @OpenApiResponse(status = STATUS_404, description = "Based on the combination of " + "inputs provided the turbine was not found.") } @@ -233,7 +237,8 @@ public void delete(@NotNull Context ctx, @NotNull String name) { DSLContext dsl = getDslContext(ctx); TurbineDao dao = new TurbineDao(dsl); dao.deleteTurbine(name, office, deleteMethod.getRule()); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(name + " Deleted"); + StatusResponse re = new StatusResponse(office, "Turbine successfully deleted from CWMS", name); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } \ No newline at end of file diff --git a/cwms-data-api/src/main/java/cwms/cda/api/location/kind/LockController.java b/cwms-data-api/src/main/java/cwms/cda/api/location/kind/LockController.java index 42b0319101..1acb7e586c 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/location/kind/LockController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/location/kind/LockController.java @@ -37,6 +37,7 @@ import static cwms.cda.api.Controllers.RESULTS; import static cwms.cda.api.Controllers.SIZE; import static cwms.cda.api.Controllers.STATUS_200; +import static cwms.cda.api.Controllers.STATUS_201; import static cwms.cda.api.Controllers.STATUS_204; import static cwms.cda.api.Controllers.STATUS_404; import static cwms.cda.api.Controllers.UNIT; @@ -52,6 +53,7 @@ import cwms.cda.data.dao.JooqDao; import cwms.cda.data.dao.location.kind.LockDao; import cwms.cda.data.dto.CwmsId; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.location.kind.Lock; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -180,7 +182,7 @@ public void getOne(@NotNull Context ctx, @NotNull String name) { method = HttpMethod.POST, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Lock successfully stored to CWMS.") + @OpenApiResponse(status = STATUS_201, description = "Lock successfully stored to CWMS.") } ) @Override @@ -201,7 +203,9 @@ public void create(Context ctx) { } LockDao dao = new LockDao(dsl); dao.storeLock(lock, failIfExists); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Lock"); + StatusResponse re = new StatusResponse(lock.getLocation().getOfficeId(), + "Lock successfully stored to CWMS.", lock.getLocation().getName()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } @@ -219,7 +223,7 @@ public void create(Context ctx) { method = HttpMethod.PATCH, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Lock successfully renamed in CWMS.") + @OpenApiResponse(status = STATUS_200, description = "Lock successfully renamed in CWMS.") } ) @Override @@ -230,7 +234,8 @@ public void update(@NotNull Context ctx, @NotNull String name) { DSLContext dsl = getDslContext(ctx); LockDao dao = new LockDao(dsl); dao.renameLock(CwmsId.buildCwmsId(office, name), newName); - ctx.status(HttpServletResponse.SC_OK).json("Renamed Lock"); + StatusResponse re = new StatusResponse(office, "Lock successfully renamed in CWMS.", newName); + ctx.status(HttpServletResponse.SC_OK).json(re); } } @@ -249,7 +254,7 @@ public void update(@NotNull Context ctx, @NotNull String name) { method = HttpMethod.DELETE, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Lock successfully deleted from CWMS."), + @OpenApiResponse(status = STATUS_200, description = "Lock successfully deleted from CWMS."), @OpenApiResponse(status = STATUS_404, description = "Based on the combination of " + "inputs provided the lock was not found.") } @@ -263,7 +268,8 @@ public void delete(@NotNull Context ctx, @NotNull String name) { DSLContext dsl = getDslContext(ctx); LockDao dao = new LockDao(dsl); dao.deleteLock(CwmsId.buildCwmsId(office, name), deleteMethod.getRule()); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(name + " Deleted"); + StatusResponse re = new StatusResponse(office, "Lock successfully deleted from CWMS.", name); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } \ No newline at end of file diff --git a/cwms-data-api/src/main/java/cwms/cda/api/location/kind/OutletController.java b/cwms-data-api/src/main/java/cwms/cda/api/location/kind/OutletController.java index 640eaf652b..6eb33239e3 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/location/kind/OutletController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/location/kind/OutletController.java @@ -30,7 +30,7 @@ import static cwms.cda.api.Controllers.OFFICE; import static cwms.cda.api.Controllers.PROJECT_ID; import static cwms.cda.api.Controllers.STATUS_200; -import static cwms.cda.api.Controllers.STATUS_204; +import static cwms.cda.api.Controllers.STATUS_201; import static cwms.cda.api.Controllers.STATUS_404; import static cwms.cda.api.Controllers.queryParamAsClass; import static cwms.cda.api.Controllers.requiredParam; @@ -41,6 +41,7 @@ import cwms.cda.api.BaseCrudHandler; import cwms.cda.data.dao.JooqDao; import cwms.cda.data.dao.location.kind.OutletDao; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.location.kind.Outlet; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -80,7 +81,7 @@ public OutletController(MetricRegistry metrics) { method = HttpMethod.POST, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Outlet successfully stored to CWMS.") + @OpenApiResponse(status = STATUS_201, description = "Outlet successfully stored to CWMS.") } ) @Override @@ -94,7 +95,9 @@ public void create(@NotNull Context ctx) { DSLContext dsl = getDslContext(ctx); OutletDao dao = new OutletDao(dsl); dao.storeOutlet(outlet, failIfExists); - ctx.status(HttpServletResponse.SC_CREATED).json("Created Outlet"); + StatusResponse re = new StatusResponse(outlet.getLocation().getOfficeId(), + "Outlet successfully stored to CWMS.", outlet.getLocation().getName()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } @@ -182,7 +185,7 @@ public void getOne(@NotNull Context ctx, @NotNull String name) { method = HttpMethod.PATCH, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "CWMS Outlet successfully renamed.") + @OpenApiResponse(status = STATUS_200, description = "CWMS Outlet successfully renamed.") } ) @Override @@ -193,7 +196,8 @@ public void update(@NotNull Context ctx, @NotNull String name) { DSLContext dsl = getDslContext(ctx); OutletDao dao = new OutletDao(dsl); dao.renameOutlet(office, name, newOutletId); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(name + " successfully renamed to " + newOutletId); + StatusResponse re = new StatusResponse(office, "CWMS Outlet successfully renamed.", newOutletId); + ctx.status(HttpServletResponse.SC_OK).json(re); } } @@ -212,7 +216,7 @@ public void update(@NotNull Context ctx, @NotNull String name) { method = HttpMethod.DELETE, tags = {TAG}, responses = { - @OpenApiResponse(status = STATUS_204, description = "Outlet successfully deleted from CWMS."), + @OpenApiResponse(status = STATUS_200, description = "Outlet successfully deleted from CWMS."), @OpenApiResponse(status = STATUS_404, description = "Based on the combination of " + "inputs provided the outlet was not found.") } @@ -226,7 +230,8 @@ public void delete(@NotNull Context ctx, @NotNull String name) { DSLContext dsl = getDslContext(ctx); OutletDao dao = new OutletDao(dsl); dao.deleteOutlet(office, name, deleteMethod.getRule()); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(name + " Deleted"); + StatusResponse re = new StatusResponse(office, "Outlet successfully deleted from CWMS.", name); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractCreateController.java b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractCreateController.java index db41f4791e..1748d2ed65 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractCreateController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractCreateController.java @@ -39,6 +39,7 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import cwms.cda.data.dao.watersupply.WaterContractDao; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.watersupply.WaterUserContract; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -104,7 +105,9 @@ public void handle(@NotNull Context ctx) { String newContractName = ctx.pathParam(WATER_USER); WaterContractDao contractDao = getContractDao(dsl); contractDao.storeWaterContract(waterContract, failIfExists, ignoreNulls); - ctx.status(HttpServletResponse.SC_CREATED).json(newContractName + " created successfully"); + StatusResponse re = new StatusResponse(waterContract.getOfficeId(), + "Water Contract Created Successfully", newContractName); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractDeleteController.java b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractDeleteController.java index c0bff16286..409a39aa08 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractDeleteController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractDeleteController.java @@ -40,6 +40,7 @@ import cwms.cda.data.dao.JooqDao.DeleteMethod; import cwms.cda.data.dao.watersupply.WaterContractDao; import cwms.cda.data.dto.CwmsId; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.watersupply.WaterUserContract; import io.javalin.http.Context; import io.javalin.http.Handler; @@ -89,7 +90,9 @@ public void handle(@NotNull Context ctx) { CwmsId projectLocation = CwmsId.buildCwmsId(office, locationId); WaterUserContract contract = contractDao.getWaterContract(contractName, projectLocation, entityName); contractDao.deleteWaterContract(contract, deleteMethod); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json(contractName + " deleted successfully"); + StatusResponse re = new StatusResponse(contract.getOfficeId(), + "Water Contract Deleted Successfully", contractName); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractTypeCreateController.java b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractTypeCreateController.java index a01f6bad92..3e8bc44df3 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractTypeCreateController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractTypeCreateController.java @@ -34,6 +34,7 @@ import com.codahale.metrics.Timer; import cwms.cda.data.dao.watersupply.WaterContractDao; import cwms.cda.data.dto.LookupType; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; import io.javalin.http.Context; @@ -66,7 +67,7 @@ public WaterContractTypeCreateController(MetricRegistry metrics) { + "display value already exists. Default: true") }, responses = { - @OpenApiResponse(status = "204", description = "Contract type successfully stored to CWMS."), + @OpenApiResponse(status = "201", description = "Contract type successfully stored to CWMS."), @OpenApiResponse(status = "501", description = "Requested format is not implemented.") }, description = "Create a new water contract type", @@ -86,7 +87,9 @@ public void handle(@NotNull Context ctx) { LookupType contractType = Formats.parseContent(contentType, ctx.body(), LookupType.class); WaterContractDao contractDao = getContractDao(dsl); contractDao.storeWaterContractType(contractType, failIfExists); - ctx.status(HttpServletResponse.SC_CREATED).json("Contract type successfully stored to CWMS."); + StatusResponse re = new StatusResponse(contractType.getOfficeId(), + "Contract type successfully stored to CWMS.", contractType.getDisplayValue()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractTypeDeleteController.java b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractTypeDeleteController.java index fc25b4b2c3..7a7849655d 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractTypeDeleteController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractTypeDeleteController.java @@ -34,6 +34,7 @@ import com.codahale.metrics.Timer; import cwms.cda.data.dao.watersupply.WaterContractDao; import cwms.cda.data.dto.LookupType; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; import io.javalin.http.Context; @@ -78,7 +79,8 @@ public void handle(@NotNull Context ctx) { ctx.contentType(contentType.toString()); WaterContractDao dao = new WaterContractDao(dsl); dao.deleteWaterContractType(office, displayValue); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json("Contract type successfully deleted from CWMS."); + StatusResponse re = new StatusResponse(office, "Contract type successfully deleted from CWMS.", displayValue); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractUpdateController.java b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractUpdateController.java index e9c773f751..ca6e6140d0 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractUpdateController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterContractUpdateController.java @@ -37,6 +37,7 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import cwms.cda.data.dao.watersupply.WaterContractDao; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.watersupply.WaterUser; import cwms.cda.data.dto.watersupply.WaterUserContract; import cwms.cda.formatters.ContentType; @@ -82,6 +83,7 @@ public WaterContractUpdateController(MetricRegistry metrics) { required = true) }, responses = { + @OpenApiResponse(status = "200", description = "Contract successfully renamed in CWMS."), @OpenApiResponse(status = "404", description = "The provided combination of " + "parameters did not find a contract"), @OpenApiResponse(status = "501", description = "Requested format is not implemented.") @@ -107,7 +109,9 @@ public void handle(@NotNull Context ctx) { .withProjectId(waterContract.getWaterUser().getProjectId()) .withWaterRight(waterContract.getWaterUser().getWaterRight()).build(); contractDao.renameWaterContract(ref, contractName, newName); - ctx.status(HttpServletResponse.SC_OK).json("Contract renamed successfully"); + StatusResponse re = new StatusResponse(waterContract.getOfficeId(), + "Contract Renamed Successfully", newName); + ctx.status(HttpServletResponse.SC_OK).json(re); } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserCreateController.java b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserCreateController.java index 7173052398..4516a7adaf 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserCreateController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserCreateController.java @@ -32,6 +32,7 @@ import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import cwms.cda.data.dao.watersupply.WaterContractDao; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.watersupply.WaterUser; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -65,7 +66,7 @@ public WaterUserCreateController(MetricRegistry metrics) { }, required = true), responses = { - @OpenApiResponse(status = STATUS_204, description = "Water user successfully stored to CWMS."), + @OpenApiResponse(status = STATUS_201, description = "Water user successfully stored to CWMS."), @OpenApiResponse(status = STATUS_501, description = "Requested format is not implemented") }, description = "Stores a water user to CWMS.", @@ -84,7 +85,9 @@ public void handle(@NotNull Context ctx) { boolean failIfExists = Boolean.parseBoolean(ctx.queryParam(FAIL_IF_EXISTS)); WaterContractDao contractDao = getContractDao(dsl); contractDao.storeWaterUser(user, failIfExists); - ctx.status(HttpServletResponse.SC_CREATED).json(user.getEntityName() + " user created successfully."); + StatusResponse re = new StatusResponse(user.getProjectId().getOfficeId(), + "Water user successfully stored to CWMS.", user.getEntityName()); + ctx.status(HttpServletResponse.SC_CREATED).json(re); } } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserDeleteController.java b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserDeleteController.java index eae6ff778b..2fece833ec 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserDeleteController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserDeleteController.java @@ -39,6 +39,7 @@ import cwms.cda.data.dao.JooqDao.DeleteMethod; import cwms.cda.data.dao.watersupply.WaterContractDao; import cwms.cda.data.dto.CwmsId; +import cwms.cda.data.dto.StatusResponse; import io.javalin.http.Context; import io.javalin.http.Handler; import io.javalin.plugin.openapi.annotations.HttpMethod; @@ -85,7 +86,8 @@ public void handle(@NotNull Context ctx) { CwmsId location = CwmsId.buildCwmsId(office, locationId); WaterContractDao contractDao = getContractDao(dsl); contractDao.deleteWaterUser(location, entityName, deleteMode); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json("Water user deleted successfully."); + StatusResponse re = new StatusResponse(office, "Water user deleted successfully.", entityName); + ctx.status(HttpServletResponse.SC_OK).json(re); } } } diff --git a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserUpdateController.java b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserUpdateController.java index ddfc2227ef..32bdc4a9ea 100644 --- a/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserUpdateController.java +++ b/cwms-data-api/src/main/java/cwms/cda/api/watersupply/WaterUserUpdateController.java @@ -29,7 +29,7 @@ import static cwms.cda.api.Controllers.NAME; import static cwms.cda.api.Controllers.OFFICE; import static cwms.cda.api.Controllers.PROJECT_ID; -import static cwms.cda.api.Controllers.STATUS_204; +import static cwms.cda.api.Controllers.STATUS_200; import static cwms.cda.api.Controllers.STATUS_501; import static cwms.cda.api.Controllers.UPDATE; import static cwms.cda.api.Controllers.WATER_USER; @@ -40,6 +40,7 @@ import com.codahale.metrics.Timer; import cwms.cda.data.dao.watersupply.WaterContractDao; import cwms.cda.data.dto.CwmsId; +import cwms.cda.data.dto.StatusResponse; import cwms.cda.data.dto.watersupply.WaterUser; import cwms.cda.formatters.ContentType; import cwms.cda.formatters.Formats; @@ -82,7 +83,7 @@ public WaterUserUpdateController(MetricRegistry metrics) { required = true) }, responses = { - @OpenApiResponse(status = STATUS_204, description = "Water user successfully updated in CWMS."), + @OpenApiResponse(status = STATUS_200, description = "Water user successfully updated in CWMS."), @OpenApiResponse(status = STATUS_501, description = "Requested format is not implemented") }, description = "Updates a water user in CWMS.", @@ -104,7 +105,8 @@ public void handle(@NotNull Context ctx) { CwmsId location = CwmsId.buildCwmsId(office, locationId); WaterContractDao contractDao = getContractDao(dsl); contractDao.renameWaterUser(oldName, newName, location); - ctx.status(HttpServletResponse.SC_NO_CONTENT).json("Water user renamed successfully."); + StatusResponse re = new StatusResponse(office, "Water user successfully updated in CWMS.", newName); + ctx.status(HttpServletResponse.SC_OK).json(re); } } diff --git a/cwms-data-api/src/main/java/cwms/cda/data/dto/StatusResponse.java b/cwms-data-api/src/main/java/cwms/cda/data/dto/StatusResponse.java new file mode 100644 index 0000000000..c939a93860 --- /dev/null +++ b/cwms-data-api/src/main/java/cwms/cda/data/dto/StatusResponse.java @@ -0,0 +1,48 @@ +package cwms.cda.data.dto; + +import com.fasterxml.jackson.annotation.*; +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import cwms.cda.formatters.Formats; +import cwms.cda.formatters.annotations.FormattableWith; +import cwms.cda.formatters.json.JsonV1; + +/** + * Class for creating a JSON message for when there is a successful (non-error) response + */ +@FormattableWith(contentType = Formats.JSONV1, formatter = JsonV1.class, aliases = {Formats.DEFAULT, Formats.JSON}) +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonNaming(PropertyNamingStrategies.KebabCaseStrategy.class) +public final class StatusResponse extends CwmsDTO{ + + + @JsonProperty(required = true) + private String message; + // Name or ID for identifying information + private String identifier; + + // NOT FOR USE, only for Jackson deserialization + public StatusResponse() { + super(""); + } + + public StatusResponse(String officeId, String message) { + super(officeId); + this.message = message; + this.identifier = ""; + } + + public StatusResponse(String officeId, String message, String identifier) { + super(officeId); + this.message = message; + this.identifier = identifier; + } + + public String getMessage() { + return message; + } + + public String getIdentifier() { + return identifier; + } +} diff --git a/cwms-data-api/src/test/java/cwms/cda/api/BasinControllerIT.java b/cwms-data-api/src/test/java/cwms/cda/api/BasinControllerIT.java index bb74409b55..1a7ff82ed4 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/BasinControllerIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/BasinControllerIT.java @@ -62,6 +62,9 @@ class BasinControllerIT extends DataApiTestIT private static final String OFFICE = "SWT"; private static final Basin BASIN; private static final Basin BASIN_CONNECT; + private static final String OFFICE_ID = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; static { try { BASIN = new Basin.Builder() @@ -176,6 +179,9 @@ void test_get_create_delete() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(BASIN.getBasinId().getOfficeId())) + .body(MESSAGE, equalTo("Basin successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(BASIN.getBasinId().getName())) ; if(BASIN.getParentBasinId() != null && BASIN.getPrimaryStreamId() != null){ @@ -287,7 +293,10 @@ void test_get_create_delete() { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(BASIN.getBasinId().getOfficeId())) + .body(MESSAGE, equalTo("Deleted CWMS Basin")) + .body(IDENTIFIER, equalTo(BASIN.getBasinId().getName())) ; // Retrieve basin and assert that it does not exist @@ -399,6 +408,9 @@ void test_get_all() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(BASIN.getBasinId().getOfficeId())) + .body(MESSAGE, equalTo("Basin successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(BASIN.getBasinId().getName())) ; @@ -511,7 +523,10 @@ void test_get_all() { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(BASIN.getBasinId().getOfficeId())) + .body(MESSAGE, equalTo("Deleted CWMS Basin")) + .body(IDENTIFIER, equalTo(BASIN.getBasinId().getName())) ; } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/DownstreamLocationsGetControllerIT.java b/cwms-data-api/src/test/java/cwms/cda/api/DownstreamLocationsGetControllerIT.java index 0d56519396..5f6519d3af 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/DownstreamLocationsGetControllerIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/DownstreamLocationsGetControllerIT.java @@ -261,7 +261,7 @@ void test_getDownstreamLocations() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)); // Delete the StreamLocation2 given() @@ -278,7 +278,7 @@ void test_getDownstreamLocations() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)); } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/EmbankmentControllerIT.java b/cwms-data-api/src/test/java/cwms/cda/api/EmbankmentControllerIT.java index 5ad96c44c2..8d97346235 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/EmbankmentControllerIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/EmbankmentControllerIT.java @@ -63,6 +63,9 @@ final class EmbankmentControllerIT extends DataApiTestIT { private static final Location PROJECT_LOC; private static final Location EMBANKMENT_LOC; private static final Embankment EMBANKMENT; + private static final String OFFICE_ID = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; static { try(InputStream projectStream = EmbankmentControllerIT.class.getResourceAsStream("/cwms/cda/api/project_location.json"); InputStream embankmentStream = EmbankmentControllerIT.class.getResourceAsStream("/cwms/cda/api/embankment.json")) { @@ -145,6 +148,9 @@ void test_get_create_delete() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(EMBANKMENT.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Embankment successfully stored to CWMS")) + .body(IDENTIFIER, equalTo(EMBANKMENT.getLocation().getName())) ; String office = EMBANKMENT.getLocation().getOfficeId(); // Retrieve the Embankment and assert that it exists @@ -186,7 +192,10 @@ void test_get_create_delete() { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(EMBANKMENT.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Embankment successfully deleted from CWMS")) + .body(IDENTIFIER, equalTo(EMBANKMENT.getLocation().getName())) ; // Retrieve a Embankment and assert that it does not exist @@ -267,6 +276,9 @@ void test_get_all() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(EMBANKMENT.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Embankment successfully stored to CWMS")) + .body(IDENTIFIER, equalTo(EMBANKMENT.getLocation().getName())) ; String office = EMBANKMENT.getLocation().getOfficeId(); // Retrieve the Embankment and assert that it exists @@ -309,7 +321,10 @@ void test_get_all() { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(EMBANKMENT.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Embankment successfully deleted from CWMS")) + .body(IDENTIFIER, equalTo(EMBANKMENT.getLocation().getName())) ; } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java index f404e2011b..a0ff351a24 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/LevelsControllerTestIT.java @@ -86,6 +86,9 @@ public class LevelsControllerTestIT extends DataApiTestIT { public static final String OFFICE = "SPK"; private final List levelList = new ArrayList<>(); + private static final String OFFICE_ID = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; @AfterEach void cleanup() throws Exception { @@ -952,7 +955,10 @@ void testStoreRetrieveVirtualLocationLevels() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(levelId)); //Read level with unit given() @@ -1078,7 +1084,10 @@ void testStoreRetrieveAllVirtualLocationLevels() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(levelId)); levelJson = readResourceFile("cwms/cda/api/virtuallevels/virtual_level_2.json"); @@ -1095,7 +1104,10 @@ void testStoreRetrieveAllVirtualLocationLevels() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(level1Id)); levelJson = readResourceFile("cwms/cda/api/virtuallevels/virtual_level_3.json"); @@ -1112,7 +1124,10 @@ void testStoreRetrieveAllVirtualLocationLevels() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(level2Id)); //Read level with unit given() @@ -1265,7 +1280,10 @@ void testStoreRetrieveAllVirtualLocationLevelsPaged() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(levelId)); levelJson = readResourceFile("cwms/cda/api/virtuallevels/virtual_level_2.json"); levelJson = levelJson.replace(oldLevelLoc2, levelLoc2); @@ -1283,7 +1301,10 @@ void testStoreRetrieveAllVirtualLocationLevelsPaged() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(level1Id)); levelJson = readResourceFile("cwms/cda/api/virtuallevels/virtual_level_3.json"); levelJson = levelJson.replace(oldLevelLoc3, levelLoc3); @@ -1301,7 +1322,10 @@ void testStoreRetrieveAllVirtualLocationLevelsPaged() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(level2Id)); //Read level with unit given() @@ -1488,7 +1512,10 @@ void testStoreDeleteVirtualLocationLevel(String deletionMethod) throws Exception .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(levelId)); //Read level with unit given() @@ -1551,8 +1578,11 @@ void testStoreDeleteVirtualLocationLevel(String deletionMethod) throws Exception .delete("/levels/{level-id}", levelId) .then() .log().ifValidationFails(LogDetail.ALL, true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)); + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("CWMS Location Level Deleted")) + .body(IDENTIFIER, equalTo(levelId)); break; case "no_date": given() @@ -1568,7 +1598,10 @@ void testStoreDeleteVirtualLocationLevel(String deletionMethod) throws Exception .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("CWMS Location Level Deleted")) + .body(IDENTIFIER, equalTo(levelId)); break; default: fail("Invalid deletion method: " + deletionMethod); @@ -1673,7 +1706,10 @@ void testStoreSeasonalLevel() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(levelId)); given() .log().ifValidationFails(LogDetail.ALL, true) @@ -1723,7 +1759,10 @@ void testStoreTimeSeriesLevel() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(levelId)); given() .log().ifValidationFails(LogDetail.ALL, true) @@ -1771,7 +1810,10 @@ void testStoreConstantLevel() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Created Location Level")) + .body(IDENTIFIER, equalTo(levelId)); given() .log().ifValidationFails(LogDetail.ALL, true) diff --git a/cwms-data-api/src/test/java/cwms/cda/api/LocationControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/LocationControllerTestIT.java index fc02a34e3a..88f90117a8 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/LocationControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/LocationControllerTestIT.java @@ -60,6 +60,10 @@ class LocationControllerTestIT extends DataApiTestIT { private final List categoriesToCleanup = new ArrayList<>(); private final List groupsToCleanup = new ArrayList<>(); + private static final String OFFICE_ID = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; + @AfterEach void cleanup() { @@ -139,8 +143,11 @@ void test_location_create_get_delete() throws Exception { .post("/locations") .then() .log().ifValidationFails(LogDetail.ALL,true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .assertThat() + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(officeId)) + .body(MESSAGE, equalTo("Created Location")) + .body(IDENTIFIER, equalTo("LOC_TEST")); //Create associated time series so delete fails without cascade try { createTimeseries(officeId, location.getName() + ".Flow.Inst.~1Hour.0.cda-test"); @@ -192,8 +199,11 @@ void test_location_create_get_delete() throws Exception { .delete("/locations/" + location.getName()) .then() .log().ifValidationFails(LogDetail.ALL,true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)); + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(officeId)) + .body(MESSAGE, equalTo("Deleted CWMS Location")) + .body(IDENTIFIER, equalTo("LOC_TEST")); // get it back given() @@ -381,7 +391,10 @@ void test_location_create_get_bad_units_delete() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(officeId)) + .body(MESSAGE, equalTo("Deleted CWMS Location")) + .body(IDENTIFIER, equalTo("LOC_TEST")); // get it back given() @@ -459,7 +472,10 @@ void test_create_update() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(user.getOperatingOffice())) + .body(MESSAGE, equalTo("Updated and renamed Location")) + .body(IDENTIFIER, equalTo(updatedLocationName)); // get it back given() @@ -491,7 +507,10 @@ void test_create_update() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_OK)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(user.getOperatingOffice())) + .body(MESSAGE, equalTo("Deleted CWMS Location")) + .body(IDENTIFIER, equalTo(updatedLocationName)); } @Test diff --git a/cwms-data-api/src/test/java/cwms/cda/api/LockControllerIT.java b/cwms-data-api/src/test/java/cwms/cda/api/LockControllerIT.java index ec7fd49a4e..c3bf1f487d 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/LockControllerIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/LockControllerIT.java @@ -91,6 +91,9 @@ final class LockControllerIT extends DataApiTestIT { private static final Lock STORABLE_LOCK; private static List locationLevelsToCleanup = new ArrayList<>(); private static Lock lockToCleanup; + private static final String OFFICE_ID = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; static { try ( @@ -286,6 +289,9 @@ void test_get_create_delete_EN() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(LOCK.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(LOCK.getLocation().getName())) ; String office = LOCK.getLocation().getOfficeId(); // Retrieve the Lock and assert that it exists @@ -341,7 +347,10 @@ void test_get_create_delete_EN() { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(LOCK.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(LOCK.getLocation().getName())) ; // Retrieve a Lock and assert that it does not exist @@ -423,6 +432,9 @@ void test_get_create_delete_SI() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(metricLock.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(metricLock.getLocation().getName())) ; String office = metricLock.getLocation().getOfficeId(); @@ -489,7 +501,10 @@ void test_get_create_delete_SI() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(LOCK.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(LOCK.getLocation().getName())) ; // Retrieve a Lock and assert that it does not exist @@ -642,6 +657,9 @@ void storeRetrieveSameLockNameDifferentProject() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(metricLock.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(metricLock.getLocation().getName())) ; lockToCleanup = metricLockProj2; @@ -679,6 +697,9 @@ void storeRetrieveSameLockNameDifferentProject() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(metricLock.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(metricLock.getLocation().getName())) ; String office = metricLock.getLocation().getOfficeId(); @@ -790,7 +811,10 @@ void storeRetrieveSameLockNameDifferentProject() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(LOCK.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(LOCK.getLocation().getName())) ; // Retrieve a Lock and assert that it does not exist @@ -821,7 +845,10 @@ void storeRetrieveSameLockNameDifferentProject() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(LOCK.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(LOCK.getLocation().getName())) ; // Retrieve a Lock and assert that it does not exist @@ -950,6 +977,9 @@ void test_get_all() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(LOCK.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(LOCK.getLocation().getName())) ; String office = LOCK.getLocation().getOfficeId(); // Retrieve the Lock and assert that it exists @@ -982,7 +1012,10 @@ void test_get_all() { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(LOCK.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Lock successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(LOCK.getLocation().getName())) ; } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/LookupTypeControllerIT.java b/cwms-data-api/src/test/java/cwms/cda/api/LookupTypeControllerIT.java index 7a33ad92ce..3aee70d775 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/LookupTypeControllerIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/LookupTypeControllerIT.java @@ -49,6 +49,9 @@ final class LookupTypeControllerIT extends DataApiTestIT { private static final String CATEGORY_IT = "AT_EMBANK_STRUCTURE_TYPE"; private static final String PREFIX_IT = "STRUCTURE_TYPE"; + private static final String OFFICE_ID = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; @Test void test_get_create_delete() throws IOException { InputStream resource = this.getClass().getResourceAsStream("/cwms/cda/api/lookup_type.json"); @@ -81,6 +84,9 @@ void test_get_create_delete() throws IOException { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(lookupType.getOfficeId())) + .body(MESSAGE, equalTo("Lookup Type successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(lookupType.getDisplayValue())) ; String office = user.getOperatingOffice(); // Retrieve the lookup type and assert that it exists @@ -119,7 +125,10 @@ void test_get_create_delete() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(lookupType.getOfficeId())) + .body(MESSAGE, equalTo("Lookup Type successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(lookupType.getDisplayValue())) ; // Retrieve the lookup type and assert that it does not exist diff --git a/cwms-data-api/src/test/java/cwms/cda/api/MeasurementControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/MeasurementControllerTestIT.java index cbfb1e53b8..c695c2452f 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/MeasurementControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/MeasurementControllerTestIT.java @@ -67,6 +67,9 @@ final class MeasurementControllerTestIT extends DataApiTestIT { private static final String OFFICE_ID = TestAccounts.KeyUser.SPK_NORMAL.getOperatingOffice(); private static final List TEST_STREAMS = new ArrayList<>(); private static final List TEST_STREAM_LOC_IDS = new ArrayList<>(); + private static final String OFFICE_ID_TEXT = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; @BeforeAll public static void setup() throws SQLException { @@ -156,7 +159,10 @@ void test_create_retrieve_delete_measurement() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(measurement.getOfficeId())) + .body(MESSAGE, equalTo("Measurement(s) successfully stored.")) + .body(IDENTIFIER, isEmptyString()); String locationId = measurement.getLocationId(); String number = measurement.getNumber(); @@ -235,7 +241,10 @@ void test_create_retrieve_delete_measurement() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(measurement.getOfficeId())) + .body(MESSAGE, equalTo("Measurement successfully deleted for specified location-id.")) + .body(IDENTIFIER, equalTo(measurement.getLocationId())); // Retrieve the Measurement and assert that it does not exist given() @@ -283,7 +292,10 @@ void test_create_retrieve_delete_measurement_multiple() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(measurement1.getOfficeId())) + .body(MESSAGE, equalTo("Measurement(s) successfully stored.")) + .body(IDENTIFIER, isEmptyString()); // Retrieve the Measurements and assert that they exists given() @@ -411,7 +423,10 @@ void test_create_retrieve_delete_measurement_multiple() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(measurement1.getOfficeId())) + .body(MESSAGE, equalTo("Measurement successfully deleted for specified location-id.")) + .body(IDENTIFIER, equalTo(measurement1.getLocationId())); // Retrieve the Measurements and assert that they do not exist given() diff --git a/cwms-data-api/src/test/java/cwms/cda/api/PropertyControllerIT.java b/cwms-data-api/src/test/java/cwms/cda/api/PropertyControllerIT.java index 30e3b03288..aa55ec232d 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/PropertyControllerIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/PropertyControllerIT.java @@ -46,6 +46,9 @@ @Tag("integration") final class PropertyControllerIT extends DataApiTestIT { + private static final String OFFICE_ID = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; @@ -79,6 +82,9 @@ void test_get_create_delete() throws IOException { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(property.getOfficeId())) + .body(MESSAGE, equalTo("Property successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(property.getName())) ; String office = property.getOfficeId(); // Retrieve the property and assert that it exists @@ -117,7 +123,10 @@ void test_get_create_delete() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(property.getOfficeId())) + .body(MESSAGE, equalTo("Property successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(property.getName())) ; // Retrieve a Property and assert that it does not exist @@ -216,6 +225,9 @@ void test_get_all() throws IOException { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(property.getOfficeId())) + .body(MESSAGE, equalTo("Property successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(property.getName())) ; String office = property.getOfficeId(); // Retrieve the property and assert that it exists @@ -255,7 +267,10 @@ void test_get_all() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(property.getOfficeId())) + .body(MESSAGE, equalTo("Property successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(property.getName())) ; } } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/StreamControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/StreamControllerTestIT.java index a19dd9bd64..1ffe5d803c 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/StreamControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/StreamControllerTestIT.java @@ -67,6 +67,10 @@ final class StreamControllerTestIT extends DataApiTestIT { private static final String OFFICE_ID = TestAccounts.KeyUser.SPK_NORMAL.getOperatingOffice(); private static final List STREAMS_CREATED = new ArrayList<>(); + private static final String OFFICE_ID_TEXT = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; + @BeforeAll public static void setup() throws SQLException { String testLoc = "Stream123Test"; //match the stream name in the json file @@ -142,7 +146,10 @@ void test_get_create_delete() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(stream.getOfficeId())) + .body(MESSAGE, equalTo("Stream successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(stream.getId().getName())); String streamId = stream.getId().getName(); @@ -193,7 +200,10 @@ void test_get_create_delete() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(stream.getOfficeId())) + .body(MESSAGE, equalTo("Stream successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(streamId)); // Retrieve the Stream and assert that it does not exist given() @@ -274,7 +284,10 @@ void test_get_all() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(stream.getOfficeId())) + .body(MESSAGE, equalTo("Stream successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(stream.getId().getName())); String office = stream.getId().getOfficeId(); String streamId = stream.getId().getName(); @@ -325,7 +338,10 @@ void test_get_all() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(stream.getOfficeId())) + .body(MESSAGE, equalTo("Stream successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(streamId)); } } \ No newline at end of file diff --git a/cwms-data-api/src/test/java/cwms/cda/api/StreamLocationControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/StreamLocationControllerTestIT.java index 14a8ceb27d..9e7aff3835 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/StreamLocationControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/StreamLocationControllerTestIT.java @@ -71,6 +71,10 @@ final class StreamLocationControllerTestIT extends DataApiTestIT { private static final String OFFICE_ID = TestAccounts.KeyUser.SWT_NORMAL.getOperatingOffice(); private static final List STREAMS_CREATED = new ArrayList<>(); + private static final String OFFICE_ID_TEXT = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; + @BeforeAll public static void setup() throws SQLException { String testLoc = "StreamLoc321"; // match the stream location name in the json file @@ -146,7 +150,10 @@ void test_get_create_delete() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(OFFICE_ID)) + .body(MESSAGE, equalTo("Stream Location successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(streamLocation.getId().getName())); String streamLocationId = streamLocation.getId().getName(); @@ -185,19 +192,22 @@ void test_get_create_delete() throws IOException { // Delete the StreamLocation given() - .log().ifValidationFails(LogDetail.ALL, true) - .accept(Formats.JSON) - .header(AUTH_HEADER, user.toHeaderValue()) - .queryParam(OFFICE, OFFICE_ID) - .queryParam(STREAM_ID, streamLocation.getStreamId().getName()) + .log().ifValidationFails(LogDetail.ALL, true) + .accept(Formats.JSON) + .header(AUTH_HEADER, user.toHeaderValue()) + .queryParam(OFFICE, OFFICE_ID) + .queryParam(STREAM_ID, streamLocation.getStreamId().getName()) .when() - .redirects().follow(true) - .redirects().max(3) - .delete("/stream-locations/" + streamLocationId) + .redirects().follow(true) + .redirects().max(3) + .delete("/stream-locations/" + streamLocationId) .then() - .log().ifValidationFails(LogDetail.ALL, true) + .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(OFFICE_ID)) + .body(MESSAGE, equalTo("Stream Location successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(streamLocation.getStreamId().getName())); // Retrieve the StreamLocation and assert that it does not exist given() @@ -284,7 +294,10 @@ void test_get_all() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(OFFICE_ID)) + .body(MESSAGE, equalTo("Stream Location successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(streamLocation.getId().getName())); String office = streamLocation.getId().getOfficeId(); String streamLocationId = streamLocation.getId().getName(); @@ -335,6 +348,9 @@ void test_get_all() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(OFFICE_ID)) + .body(MESSAGE, equalTo("Stream Location successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(streamLocation.getStreamId().getName())); } } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/TurbineControllerIT.java b/cwms-data-api/src/test/java/cwms/cda/api/TurbineControllerIT.java index b4f496b8a4..773a283b35 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/TurbineControllerIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/TurbineControllerIT.java @@ -66,6 +66,9 @@ final class TurbineControllerIT extends DataApiTestIT { private static final String OFFICE = TestAccounts.KeyUser.SWT_NORMAL.getOperatingOffice(); private static final Location PROJECT_LOC; private static final Turbine TURBINE; + private static final String OFFICE_ID = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; static { try(InputStream projectStream = TurbineControllerIT.class.getResourceAsStream("/cwms/cda/api/project_location_turb.json"); InputStream turbineStream = TurbineControllerIT.class.getResourceAsStream("/cwms/cda/api/turbine_phys.json")) { @@ -123,6 +126,9 @@ void test_get_create_delete() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Turbine successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo("PROJ_TURB_PHYS")) ; String office = TURBINE.getLocation().getOfficeId(); // Retrieve the Turbine and assert that it exists @@ -155,7 +161,10 @@ void test_get_create_delete() { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Turbine successfully deleted from CWMS")) + .body(IDENTIFIER, equalTo(TURBINE.getLocation().getName())) ; // Retrieve a Turbine and assert that it does not exist @@ -238,6 +247,9 @@ void test_get_all() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Turbine successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo("PROJ_TURB_PHYS")) ; String office = TURBINE.getLocation().getOfficeId(); // Retrieve the Turbine and assert that it exists @@ -271,7 +283,10 @@ void test_get_all() { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(OFFICE)) + .body(MESSAGE, equalTo("Turbine successfully deleted from CWMS")) + .body(IDENTIFIER, equalTo(TURBINE.getLocation().getName())) ; } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/UpstreamLocationsGetControllerIT.java b/cwms-data-api/src/test/java/cwms/cda/api/UpstreamLocationsGetControllerIT.java index 6c2fd9bc2e..4ae6086811 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/UpstreamLocationsGetControllerIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/UpstreamLocationsGetControllerIT.java @@ -264,7 +264,7 @@ void test_getUpstreamLocations() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)); // Delete the StreamLocation2 given() @@ -281,6 +281,6 @@ void test_getUpstreamLocations() throws IOException { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)); } } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/WaterContractControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/WaterContractControllerTestIT.java index c1e926cc5b..840e527b9b 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/WaterContractControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/WaterContractControllerTestIT.java @@ -71,6 +71,9 @@ class WaterContractControllerTestIT extends DataApiTestIT { private static final String OFFICE_ID = "SWT"; private static final WaterUserContract CONTRACT; + private static final String OFFICE_ID_TEXT = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; static { try (InputStream contractStream = WaterContractCreateController.class @@ -179,6 +182,9 @@ void test_create_get_delete_WaterUserContract() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) + .body(MESSAGE, equalTo("Water Contract Created Successfully")) + .body(IDENTIFIER, equalTo(CONTRACT.getWaterUser().getEntityName())) ; // get contract @@ -381,7 +387,10 @@ void test_create_get_delete_WaterUserContract() { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) + .body(MESSAGE, equalTo("Water Contract Deleted Successfully")) + .body(IDENTIFIER, equalTo(CONTRACT.getWaterUser().getEntityName())) ; // get contract, assert that it doesn't exist @@ -426,6 +435,9 @@ void test_rename_WaterUserContract() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) + .body(MESSAGE, equalTo("Water Contract Created Successfully")) + .body(IDENTIFIER, equalTo(CONTRACT.getWaterUser().getEntityName())) ; // rename contract @@ -445,6 +457,9 @@ void test_rename_WaterUserContract() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) + .body(MESSAGE, equalTo("Contract Renamed Successfully")) + .body(IDENTIFIER, equalTo(NEW_CONTRACT_NAME)) ; // get contract, assert name is changed @@ -462,7 +477,7 @@ void test_rename_WaterUserContract() { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_OK)) - .body("office-id", equalTo(CONTRACT.getOfficeId())) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) .body("contract-id.name", equalTo(NEW_CONTRACT_NAME)) ; @@ -481,7 +496,10 @@ void test_rename_WaterUserContract() { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) + .body(MESSAGE, equalTo("Water Contract Deleted Successfully")) + .body(IDENTIFIER, equalTo(CONTRACT.getWaterUser().getEntityName())) ; } @@ -507,6 +525,9 @@ void test_getAllWaterContracts() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) + .body(MESSAGE, equalTo("Water Contract Created Successfully")) + .body(IDENTIFIER, equalTo(CONTRACT.getWaterUser().getEntityName())) ; WaterUserContract waterContract = new WaterUserContract.Builder() @@ -540,6 +561,9 @@ void test_getAllWaterContracts() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) + .body(MESSAGE, equalTo("Water Contract Created Successfully")) + .body(IDENTIFIER, equalTo(CONTRACT.getWaterUser().getEntityName())) ; // get all contracts @@ -577,25 +601,31 @@ void test_getAllWaterContracts() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) + .body(MESSAGE, equalTo("Water Contract Deleted Successfully")) + .body(IDENTIFIER, equalTo(CONTRACT.getWaterUser().getEntityName())) ; // delete contract given() - .log().ifValidationFails(LogDetail.ALL, true) - .queryParam(METHOD, "DELETE ALL") - .header(AUTH_HEADER, user.toHeaderValue()) - .when() - .redirects().follow(true) - .redirects().max(3) - .delete("/projects/" + OFFICE_ID + "/" - + CONTRACT.getWaterUser().getProjectId().getName() + "/water-user/" - + CONTRACT.getWaterUser().getEntityName() + "/contracts/" - + "NEW CONTRACT") - .then() - .log().ifValidationFails(LogDetail.ALL, true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .log().ifValidationFails(LogDetail.ALL, true) + .queryParam(METHOD, "DELETE ALL") + .header(AUTH_HEADER, user.toHeaderValue()) + .when() + .redirects().follow(true) + .redirects().max(3) + .delete("/projects/" + OFFICE_ID + "/" + + CONTRACT.getWaterUser().getProjectId().getName() + "/water-user/" + + CONTRACT.getWaterUser().getEntityName() + "/contracts/" + + "NEW CONTRACT") + .then() + .log().ifValidationFails(LogDetail.ALL, true) + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID, equalTo(CONTRACT.getOfficeId())) + .body(MESSAGE, equalTo("Water Contract Deleted Successfully")) + .body(IDENTIFIER, equalTo(CONTRACT.getWaterUser().getEntityName())) ; } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/WaterContractTypeControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/WaterContractTypeControllerTestIT.java index 253c6c86b3..998cff8c67 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/WaterContractTypeControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/WaterContractTypeControllerTestIT.java @@ -61,6 +61,9 @@ class WaterContractTypeControllerTestIT extends DataApiTestIT { private static final String OFFICE_ID = "SWT"; private static final LookupType CONTRACT_TYPE; + private static final String OFFICE_ID_TEXT = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; public static final Logger LOGGER = Logger.getLogger(WaterContractTypeControllerTestIT.class.getName()); static { @@ -97,6 +100,9 @@ void test_create_get_WaterContractType() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(CONTRACT_TYPE.getOfficeId())) + .body(MESSAGE, equalTo("Contract type successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(CONTRACT_TYPE.getDisplayValue())) ; // get water contract type and assert that it exists @@ -145,6 +151,9 @@ void test_store_delete_WaterContractType() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(CONTRACT_TYPE.getOfficeId())) + .body(MESSAGE, equalTo("Contract type successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(CONTRACT_TYPE.getDisplayValue())) ; // get water contract type and assert that it exists @@ -178,7 +187,10 @@ void test_store_delete_WaterContractType() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(CONTRACT_TYPE.getOfficeId())) + .body(MESSAGE, equalTo("Contract type successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(CONTRACT_TYPE.getDisplayValue())) ; // get water contract type and assert that it does not exist diff --git a/cwms-data-api/src/test/java/cwms/cda/api/WaterPumpDisassociateControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/WaterPumpDisassociateControllerTestIT.java index 4b8a9faca1..85f9b77240 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/WaterPumpDisassociateControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/WaterPumpDisassociateControllerTestIT.java @@ -382,7 +382,7 @@ void test_remove_from_contract() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) ; } @@ -447,7 +447,7 @@ void test_remove_does_not_exist() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) ; } } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/WaterUserControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/WaterUserControllerTestIT.java index e4c70f0618..44b71ef6d1 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/WaterUserControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/WaterUserControllerTestIT.java @@ -69,6 +69,9 @@ class WaterUserControllerTestIT extends DataApiTestIT { private static final String OFFICE_ID = "SWT"; private static final WaterUser WATER_USER; + private static final String OFFICE_ID_TEXT = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; static { try (InputStream userStream = WaterUserContract.class.getResourceAsStream("/cwms/cda/api/wateruser.json")) { @@ -161,6 +164,9 @@ void test_create_get_delete_WaterUser() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(WATER_USER.getProjectId().getOfficeId())) + .body(MESSAGE, equalTo("Water user successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(WATER_USER.getEntityName())) ; // get WaterUser, assert that it is correct @@ -200,7 +206,10 @@ void test_create_get_delete_WaterUser() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(WATER_USER.getProjectId().getOfficeId())) + .body(MESSAGE, equalTo("Water user deleted successfully.")) + .body(IDENTIFIER, equalTo(WATER_USER.getEntityName())) ; // get water user and assert that it does not exist @@ -249,6 +258,9 @@ void test_rename_WaterUser() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(WATER_USER.getProjectId().getOfficeId())) + .body(MESSAGE, equalTo("Water user successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(WATER_USER.getEntityName())) ; // Rename WaterUser @@ -268,7 +280,10 @@ void test_rename_WaterUser() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(OFFICE_ID)) + .body(MESSAGE, equalTo("Water user successfully updated in CWMS.")) + .body(IDENTIFIER, equalTo("NEW USER NAME")) ; // Get WaterUser, assert name has changed @@ -322,7 +337,10 @@ void test_rename_WaterUser() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(WATER_USER.getProjectId().getOfficeId())) + .body(MESSAGE, equalTo("Water user deleted successfully.")) + .body(IDENTIFIER, equalTo(WATER_USER.getEntityName())) ; } @@ -351,6 +369,9 @@ void test_getAllWaterUsers() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(WATER_USER.getProjectId().getOfficeId())) + .body(MESSAGE, equalTo("Water user successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(WATER_USER.getEntityName())) ; // Create WaterUser @@ -368,6 +389,9 @@ void test_getAllWaterUsers() throws Exception { .log().ifValidationFails(LogDetail.ALL, true) .assertThat() .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(WATER_USER.getProjectId().getOfficeId())) + .body(MESSAGE, equalTo("Water user successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(waterUser.getEntityName())) ; // get water users @@ -409,7 +433,10 @@ void test_getAllWaterUsers() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(WATER_USER.getProjectId().getOfficeId())) + .body(MESSAGE, equalTo("Water user deleted successfully.")) + .body(IDENTIFIER, equalTo(WATER_USER.getEntityName())) ; // delete WaterUser @@ -428,7 +455,10 @@ void test_getAllWaterUsers() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(WATER_USER.getProjectId().getOfficeId())) + .body(MESSAGE, equalTo("Water user deleted successfully.")) + .body(IDENTIFIER, equalTo(waterUser.getEntityName())) ; } diff --git a/cwms-data-api/src/test/java/cwms/cda/api/location/kind/OutletControllerTestIT.java b/cwms-data-api/src/test/java/cwms/cda/api/location/kind/OutletControllerTestIT.java index 1d958374ed..3c4639bcbc 100644 --- a/cwms-data-api/src/test/java/cwms/cda/api/location/kind/OutletControllerTestIT.java +++ b/cwms-data-api/src/test/java/cwms/cda/api/location/kind/OutletControllerTestIT.java @@ -87,6 +87,9 @@ class OutletControllerTestIT extends BaseOutletDaoIT { = buildProjectStructureLocation(PROJECT_2_ID.getName() + "-TG2", OUTLET_KIND); private static final Outlet NEW_RATED_OUTLET_UNCONTROLLED = buildTestOutlet(RATED_OUTLET_LOCATION_UNCONTROLLED, PROJECT_LOC, RATING_GROUP_UNCONTROLLED, RATING_SPEC_ID_UNCONTROLLED); + private static final String OFFICE_ID_TEXT = "office-id"; + private static final String MESSAGE = "message"; + private static final String IDENTIFIER = "identifier"; @BeforeAll public static void setup() throws Exception { @@ -147,7 +150,10 @@ void test_outlet_rename() { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(NEW_CONDUIT_GATE_2_OUTLET.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Outlet successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(NEW_CONDUIT_GATE_2_OUTLET.getLocation().getName())); //Get the newly created outlet given() @@ -178,7 +184,10 @@ void test_outlet_rename() { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)) + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(RENAMED_CONDUIT_GATE.getOfficeId())) + .body(MESSAGE, equalTo("CWMS Outlet successfully renamed.")) + .body(IDENTIFIER, equalTo(RENAMED_CONDUIT_GATE.getName())); ; //Fail to retrieve old outlet name @@ -239,7 +248,11 @@ void test_rating_spec_id_uncontrolled() { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(NEW_RATED_OUTLET_UNCONTROLLED.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Outlet successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(NEW_RATED_OUTLET_UNCONTROLLED.getLocation().getName())) + ; // Get the outlet, assert that it has null rating spec id given() @@ -340,7 +353,10 @@ void test_rating_spec_id_uncontrolled() { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(RATED_OUTLET_LOCATION_UNCONTROLLED.getOfficeId())) + .body(MESSAGE, equalTo("Outlet successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(RATED_OUTLET_LOCATION_UNCONTROLLED.getName())); // Delete the LocationGroup given() @@ -388,7 +404,10 @@ void test_rating_spec_id_controlled() { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(NEW_RATED_OUTLET_CONTROLLED.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Outlet successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(NEW_RATED_OUTLET_CONTROLLED.getLocation().getName())); // Get the outlet, assert that it has null rating spec id given() @@ -489,7 +508,10 @@ void test_rating_spec_id_controlled() { .then() .log().ifValidationFails(LogDetail.ALL,true) .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(RATED_OUTLET_LOCATION_CONTROLLED.getOfficeId())) + .body(MESSAGE, equalTo("Outlet successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(RATED_OUTLET_LOCATION_CONTROLLED.getName())); // Delete the LocationGroup given() @@ -561,7 +583,10 @@ void test_outlet_crud() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(NEW_CONDUIT_GATE_1_OUTLET.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Outlet successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(NEW_CONDUIT_GATE_1_OUTLET.getLocation().getName())); //Get the newly created outlet given() @@ -602,7 +627,10 @@ void test_outlet_crud() throws Exception { .then() .log().ifValidationFails(LogDetail.ALL, true) .assertThat() - .statusCode(is(HttpServletResponse.SC_CREATED)); + .statusCode(is(HttpServletResponse.SC_CREATED)) + .body(OFFICE_ID_TEXT, equalTo(NEW_CONDUIT_GATE_1_OUTLET.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Outlet successfully stored to CWMS.")) + .body(IDENTIFIER, equalTo(NEW_CONDUIT_GATE_1_OUTLET.getLocation().getName())); //Get the newly modified outlet given() @@ -636,8 +664,11 @@ void test_outlet_crud() throws Exception { .delete("projects/outlets/" + NEW_CONDUIT_GATE_1_OUTLET.getLocation().getName()) .then() .log().ifValidationFails(LogDetail.ALL,true) - .assertThat() - .statusCode(is(HttpServletResponse.SC_NO_CONTENT)); + .assertThat() + .statusCode(is(HttpServletResponse.SC_OK)) + .body(OFFICE_ID_TEXT, equalTo(NEW_CONDUIT_GATE_1_OUTLET.getLocation().getOfficeId())) + .body(MESSAGE, equalTo("Outlet successfully deleted from CWMS.")) + .body(IDENTIFIER, equalTo(NEW_CONDUIT_GATE_1_OUTLET.getLocation().getName())); CwmsDatabaseContainer databaseLink = CwmsDataApiSetupCallback.getDatabaseLink(); databaseLink.connection(c -> { diff --git a/cwms-data-api/src/test/java/cwms/cda/data/dto/StatusResponseTest.java b/cwms-data-api/src/test/java/cwms/cda/data/dto/StatusResponseTest.java new file mode 100644 index 0000000000..7e4dafd411 --- /dev/null +++ b/cwms-data-api/src/test/java/cwms/cda/data/dto/StatusResponseTest.java @@ -0,0 +1,58 @@ +package cwms.cda.data.dto; + +import com.fasterxml.jackson.annotation.JsonProperty; +import cwms.cda.formatters.ContentType; +import cwms.cda.formatters.Formats; +import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; + +import static org.junit.jupiter.api.Assertions.*; + +final class StatusResponseTest { + + @Test + void createStatusResponse_allFieldsProvided_Success() { + // both fields provided + StatusResponse item = new StatusResponse("SPK", "Created Location Level", "LocationName123"); + assertAll(() -> assertEquals("SPK", item.getOfficeId(), "The office ID does not match the provided value"), + () -> assertEquals("Created Location Level", item.getMessage(), "The response message does not match the provided value"), + () -> assertEquals("LocationName123", item.getIdentifier(), "The identifier does not match the provided value")); + // only message provided + StatusResponse item2 = new StatusResponse("SPK", "Updated Location"); + assertAll(() -> assertEquals("SPK", item2.getOfficeId(), "The office ID does not match the provided value"), + () -> assertEquals("Updated Location", item2.getMessage(), "The response message does not match the provided value")); + } + + + @Test + void createStatusResponse_serialize_roundtrip() { + StatusResponse statusResponse = new StatusResponse("SPK", "Created Location Level", "LocationName123"); + ContentType contentType = new ContentType(Formats.JSON); + String json = Formats.format(contentType, statusResponse); + StatusResponse deserialized = Formats.parseContent(contentType, json, StatusResponse.class); + assertAll( + () -> assertEquals(statusResponse.getOfficeId(), deserialized.getOfficeId(), "deserialized Office ID does not match provided value"), + () -> assertEquals(statusResponse.getMessage(), deserialized.getMessage(), "deserialized response does not match provided value"), + () -> assertEquals(statusResponse.getIdentifier(), deserialized.getIdentifier(), "deserialized identifier does not match provided value") + ); + } + + @Test + void createStatusResponse_deserialize_roundtrip() throws IOException { + StatusResponse statusResponse = new StatusResponse("SPK", "Created Location Level", "LocationName123"); + InputStream resource = this.getClass().getResourceAsStream("/cwms/cda/data/dto/status_response.json"); + assertNotNull(resource); + String json = IOUtils.toString(resource, StandardCharsets.UTF_8); + ContentType contentType = new ContentType(Formats.JSON); + StatusResponse deserialized = Formats.parseContent(contentType, json, StatusResponse.class); + assertAll( + () -> assertEquals(statusResponse.getOfficeId(), deserialized.getOfficeId(), "deserialized Office ID does not match provided value"), + () -> assertEquals(statusResponse.getMessage(), deserialized.getMessage(), "deserialized response does not match provided value"), + () -> assertEquals(statusResponse.getIdentifier(), deserialized.getIdentifier(), "deserialized identifier does not match provided value") + ); + } +} diff --git a/cwms-data-api/src/test/resources/cwms/cda/data/dto/status_response.json b/cwms-data-api/src/test/resources/cwms/cda/data/dto/status_response.json new file mode 100644 index 0000000000..1eed28a8b4 --- /dev/null +++ b/cwms-data-api/src/test/resources/cwms/cda/data/dto/status_response.json @@ -0,0 +1,5 @@ +{ + "office-id": "SPK", + "message": "Created Location Level", + "identifier": "LocationName123" +} \ No newline at end of file