From 41609d11d8cb7bab33c3d3f9758034a57d3c0368 Mon Sep 17 00:00:00 2001 From: Lars Johansson <lars.johansson@ess.eu> Date: Tue, 31 Jan 2023 15:36:16 +0100 Subject: [PATCH] Update response status codes and handling for names and structures Update response status codes and handling for names and structures. Update integration tests. --- .../GlobalControllerExceptionHandler.java | 21 +- .../openepics/names/rest/api/v1/INames.java | 132 +++--- .../names/rest/api/v1/IStructures.java | 164 ++----- .../org/openepics/names/util/TextUtil.java | 21 +- .../names/util/ValidateNameElementUtil.java | 26 +- .../util/ValidateStructureElementUtil.java | 90 ++-- .../names/docker/ITUtilNameElement.java | 226 +++++----- .../names/docker/ITUtilStructureElement.java | 422 ++++++++++-------- .../org/openepics/names/docker/NamesIT.java | 63 ++- .../names/docker/StructuresDeviceGroupIT.java | 137 +++++- .../names/docker/StructuresDeviceTypeIT.java | 125 +++++- .../names/docker/StructuresDisciplineIT.java | 111 ++++- .../names/docker/StructuresSubsystemIT.java | 121 ++++- .../names/docker/StructuresSystemGroupIT.java | 119 ++++- .../names/docker/StructuresSystemIT.java | 121 ++++- 15 files changed, 1266 insertions(+), 633 deletions(-) diff --git a/src/main/java/org/openepics/names/exception/handler/GlobalControllerExceptionHandler.java b/src/main/java/org/openepics/names/exception/handler/GlobalControllerExceptionHandler.java index 3ad405ef..23ecfd4b 100644 --- a/src/main/java/org/openepics/names/exception/handler/GlobalControllerExceptionHandler.java +++ b/src/main/java/org/openepics/names/exception/handler/GlobalControllerExceptionHandler.java @@ -71,7 +71,8 @@ public class GlobalControllerExceptionHandler extends ResponseEntityExceptionHan response.setMessage(StringUtils.trimToEmpty(ex.getMessage())); response.setDetails(StringUtils.trimToEmpty(se.getDetails())); response.setField(StringUtils.trimToEmpty(se.getField())); - resultStatus = HttpStatus.BAD_REQUEST; + + // HttpStatus.BAD_REQUEST handled by Spring if (ex instanceof InputNotAvailableException || ex instanceof InputNotCorrectException @@ -80,20 +81,20 @@ public class GlobalControllerExceptionHandler extends ResponseEntityExceptionHan resultStatus = HttpStatus.UNPROCESSABLE_ENTITY; } - if (ex instanceof DataNotAvailableException || ex instanceof DataNotFoundException) { + if (ex instanceof DataNotAvailableException + || ex instanceof DataNotFoundException) { resultStatus = HttpStatus.NOT_FOUND; } - if (ex instanceof DataNotCorrectException || ex instanceof DataNotValidException) { - resultStatus = HttpStatus.UNPROCESSABLE_ENTITY; - } - - if (ex instanceof DataDeletedException) { - resultStatus = HttpStatus.UNPROCESSABLE_ENTITY; + if (ex instanceof DataConflictException + || ex instanceof DataDeletedException + || ex instanceof DataExistException + || ex instanceof DataNotValidException) { + resultStatus = HttpStatus.CONFLICT; } - if (ex instanceof DataConflictException || ex instanceof DataExistException) { - resultStatus = HttpStatus.CONFLICT; + if (ex instanceof DataNotCorrectException) { + resultStatus = HttpStatus.UNPROCESSABLE_ENTITY; } } diff --git a/src/main/java/org/openepics/names/rest/api/v1/INames.java b/src/main/java/org/openepics/names/rest/api/v1/INames.java index 20d8d42a..8742dc74 100644 --- a/src/main/java/org/openepics/names/rest/api/v1/INames.java +++ b/src/main/java/org/openepics/names/rest/api/v1/INames.java @@ -167,6 +167,18 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "409", + description = "Conflict. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "422", description = "Unprocessable entity. Reason and information such as message, details, field are available.", @@ -234,6 +246,18 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "409", + description = "Conflict. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "422", description = "Unprocessable entity. Reason and information such as message, details, field are available.", @@ -631,12 +655,6 @@ public interface INames { content = @Content( mediaType = "text/plain", schema = @Schema(implementation = String.class))), - @ApiResponse( - responseCode = "400", - description = "Bad request. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "422", description = "Unprocessable entity. Reason and information such as message, details, field are available.", @@ -684,24 +702,6 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = ResponseBoolean.class))), - @ApiResponse( - responseCode = "400", - description = "Bad request. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -744,24 +744,6 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = ResponseBoolean.class))), - @ApiResponse( - responseCode = "400", - description = "Bad request. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "404", - description = "Not Found. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -804,18 +786,6 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = ResponseBoolean.class))), - @ApiResponse( - responseCode = "400", - description = "Bad request. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -878,12 +848,6 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -954,12 +918,6 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -1026,12 +984,6 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -1095,6 +1047,18 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "409", + description = "Conflict. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "422", description = "Unprocessable entity. Reason and information such as message, details, field are available.", @@ -1161,6 +1125,18 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "409", + description = "Conflict. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "422", description = "Unprocessable entity. Reason and information such as message, details, field are available.", @@ -1221,6 +1197,12 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "422", description = "Unprocessable entity. Reason and information such as message, details, field are available.", @@ -1283,6 +1265,12 @@ public interface INames { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "422", description = "Unprocessable entity. Reason and information such as message, details, field are available.", diff --git a/src/main/java/org/openepics/names/rest/api/v1/IStructures.java b/src/main/java/org/openepics/names/rest/api/v1/IStructures.java index 2055bbfe..c2bb834a 100644 --- a/src/main/java/org/openepics/names/rest/api/v1/IStructures.java +++ b/src/main/java/org/openepics/names/rest/api/v1/IStructures.java @@ -178,6 +178,12 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "409", description = "Conflict. Reason and information such as message, details, field are available.", @@ -250,6 +256,12 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "409", description = "Conflict. Reason and information such as message, details, field are available.", @@ -681,12 +693,6 @@ public interface IStructures { content = @Content( mediaType = "text/plain", schema = @Schema(implementation = String.class))), - @ApiResponse( - responseCode = "400", - description = "Bad request. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "422", description = "Unprocessable entity. Reason and information such as message, details, field are available.", @@ -753,18 +759,6 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = ResponseBoolean.class))), - @ApiResponse( - responseCode = "400", - description = "Bad request. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -815,24 +809,6 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = ResponseBoolean.class))), - @ApiResponse( - responseCode = "400", - description = "Bad request. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -899,18 +875,6 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -986,18 +950,6 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -1069,18 +1021,6 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -1152,18 +1092,6 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -1235,18 +1163,6 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -1318,18 +1234,6 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), - @ApiResponse( - responseCode = "422", - description = "Unprocessable entity. Reason and information such as message, details, field are available.", - content = @Content( - mediaType = "application/json", - schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "500", description = "Internal server error. Reason and information such as message, details, field are available.", @@ -1392,6 +1296,12 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "409", description = "Conflict. Reason and information such as message, details, field are available.", @@ -1463,6 +1373,12 @@ public interface IStructures { content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), + @ApiResponse( + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", + content = @Content( + mediaType = "application/json", + schema = @Schema(implementation = Response.class))), @ApiResponse( responseCode = "409", description = "Conflict. Reason and information such as message, details, field are available.", @@ -1531,8 +1447,8 @@ public interface IStructures { mediaType = "application/json", schema = @Schema(implementation = Response.class))), @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), @@ -1600,8 +1516,8 @@ public interface IStructures { mediaType = "application/json", schema = @Schema(implementation = Response.class))), @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), @@ -1670,8 +1586,8 @@ public interface IStructures { mediaType = "application/json", schema = @Schema(implementation = Response.class))), @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), @@ -1744,8 +1660,8 @@ public interface IStructures { mediaType = "application/json", schema = @Schema(implementation = Response.class))), @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), @@ -1807,8 +1723,8 @@ public interface IStructures { mediaType = "application/json", schema = @Schema(implementation = Response.class))), @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), @@ -1875,8 +1791,8 @@ public interface IStructures { mediaType = "application/json", schema = @Schema(implementation = Response.class))), @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), @@ -1938,8 +1854,8 @@ public interface IStructures { mediaType = "application/json", schema = @Schema(implementation = Response.class))), @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), @@ -2006,8 +1922,8 @@ public interface IStructures { mediaType = "application/json", schema = @Schema(implementation = Response.class))), @ApiResponse( - responseCode = "409", - description = "Conflict. Reason and information such as message, details, field are available.", + responseCode = "404", + description = "Not Found. Reason and information such as message, details, field are available.", content = @Content( mediaType = "application/json", schema = @Schema(implementation = Response.class))), diff --git a/src/main/java/org/openepics/names/util/TextUtil.java b/src/main/java/org/openepics/names/util/TextUtil.java index d75fa277..008fec0c 100644 --- a/src/main/java/org/openepics/names/util/TextUtil.java +++ b/src/main/java/org/openepics/names/util/TextUtil.java @@ -59,6 +59,7 @@ public class TextUtil { public static final String MNEMONIC_PATH = "mnemonic path"; public static final String MNEMONIC_PATH_EQUIVALENCE = "mnemonic path equivalence"; public static final String SYSTEM_STRUCTURE = "system structure"; + public static final String DEVICE_STRUCTURE = "device structure"; // common @@ -70,18 +71,17 @@ public class TextUtil { public static final String HAS_DUPLICATE = "has duplicate"; public static final String IS_NOT_AVAILABLE = "is not available"; public static final String IS_NOT_CORRECT = "is not correct"; + public static final String IS_NOT_FOUND = "is not found"; public static final String IS_NOT_VALID = "is not valid"; public static final String DATA_IS_DELETED = "data is deleted"; - public static final String DATA_IS_NOT_AVAILABLE = "data is not available"; - public static final String DATA_IS_NOT_CORRECT = "data is not correct"; + public static final String DATA_IS_NOT_FOUND = "data is not found"; public static final String DATA_IS_NOT_VALID = "data is not valid"; public static final String VALUE_IS_NOT_AVAILABLE = "value is not available"; public static final String VALUE_IS_NOT_CORRECT = "value is not correct"; public static final String VALUE_IS_NOT_EMPTY = "value is not empty"; public static final String VALUE_IS_NOT_VALID = "value is not valid"; - public static final String VALUES_ARE_NOT_CORRECT = "values are not correct"; // validation message @@ -91,21 +91,17 @@ public class TextUtil { public static final String MNEMONIC_PATH_HAS_DUPLICATE = MNEMONIC_PATH + SPACE + HAS_DUPLICATE; public static final String MNEMONIC_PATH_IS_NOT_AVAILABLE = MNEMONIC_PATH + SPACE + IS_NOT_AVAILABLE; + public static final String MNEMONIC_PATH_IS_NOT_CORRECT = MNEMONIC_PATH + SPACE + IS_NOT_CORRECT; + public static final String MNEMONIC_PATH_IS_NOT_FOUND = MNEMONIC_PATH + SPACE + IS_NOT_FOUND; public static final String MNEMONIC_PATH_IS_NOT_VALID = MNEMONIC_PATH + SPACE + IS_NOT_VALID; public static final String MNEMONIC_PATH_EQUIVALENCE_HAS_DUPLICATE = MNEMONIC_PATH_EQUIVALENCE + SPACE + HAS_DUPLICATE; - public static final String STRUCTURE_MNEMONIC_PATH_IS_NOT_VALID = STRUCTURE + SPACE + MNEMONIC_PATH_IS_NOT_VALID; + public static final String STRUCTURE_MNEMONIC_PATH_IS_NOT_CORRECT = STRUCTURE + SPACE + MNEMONIC_PATH_IS_NOT_CORRECT; public static final String DEVICETYPE_OR_INDEX_IS_NOT_AVAILABLE = "device type or index is not available"; public static final String ONE_OR_MORE_ELEMENTS_ARE_NOT_CORRECT = "one or more elements are not correct"; public static final String OPERATION_COULD_NOT_BE_PERFORMED = "operation could not be performed"; public static final String PARENT_IS_NOT_AVAILABLE = PARENT + SPACE + IS_NOT_AVAILABLE; - public static final String SYSTEMGROUP_IS_NOT_AVAILABLE = SYSTEMGROUP + SPACE + IS_NOT_AVAILABLE; - public static final String SYSTEM_IS_NOT_AVAILABLE = SYSTEM + SPACE + IS_NOT_AVAILABLE; - public static final String SUBSYSTEM_IS_NOT_AVAILABLE = SUBSYSTEM + SPACE + IS_NOT_AVAILABLE; - public static final String DISCIPLINE_IS_NOT_AVAILABLE = DISCIPLINE + SPACE + IS_NOT_AVAILABLE; - public static final String DEVICEGROUP_IS_NOT_AVAILABLE = DEVICEGROUP + SPACE + IS_NOT_AVAILABLE; - public static final String DEVICETYPE_IS_NOT_AVAILABLE = DEVICETYPE + SPACE + IS_NOT_AVAILABLE; public static final String PARENT_IS_NOT_CORRECT = PARENT + SPACE + IS_NOT_CORRECT; public static final String SYSTEM_STRUCTURE_IS_NOT_CORRECT = SYSTEM_STRUCTURE + SPACE + IS_NOT_CORRECT; @@ -116,7 +112,10 @@ public class TextUtil { public static final String DEVICEGROUP_IS_NOT_CORRECT = DEVICEGROUP + SPACE + IS_NOT_CORRECT; public static final String DEVICETYPE_IS_NOT_CORRECT = DEVICETYPE + SPACE + IS_NOT_CORRECT; - public static final String DISCIPLINE_IS_NOT_VALID = DISCIPLINE + SPACE + IS_NOT_VALID; + public static final String SYSTEM_STRUCTURE_IS_NOT_FOUND = SYSTEM_STRUCTURE + SPACE + IS_NOT_FOUND; + public static final String DEVICE_STRUCTURE_IS_NOT_FOUND = DEVICE_STRUCTURE + SPACE + IS_NOT_FOUND; + public static final String DISCIPLINE_IS_NOT_FOUND = DISCIPLINE + SPACE + IS_NOT_FOUND; + public static final String DEVICEGROUP_IS_NOT_VALID = DEVICEGROUP + SPACE + IS_NOT_VALID; public static final String INDEX_IS_NOT_VALID = INDEX + SPACE + IS_NOT_VALID; public static final String MNEMONIC_IS_NOT_VALID = MNEMONIC + SPACE + IS_NOT_VALID; diff --git a/src/main/java/org/openepics/names/util/ValidateNameElementUtil.java b/src/main/java/org/openepics/names/util/ValidateNameElementUtil.java index b75b8e84..b347fa91 100644 --- a/src/main/java/org/openepics/names/util/ValidateNameElementUtil.java +++ b/src/main/java/org/openepics/names/util/ValidateNameElementUtil.java @@ -249,8 +249,8 @@ public class ValidateNameElementUtil { // retrieve for uuid and check if (ValidateUtil.isAnyEqual(nameCommand, NameCommand.UPDATE, NameCommand.DELETE)) { List<Name> names = nameRepository.readNames(false, uuid.toString(), null, null, null, null, null, null); - ExceptionUtil.validateConditionDataNotCorrectException(ValidateUtil.isSize(names, 1), - TextUtil.VALUE_IS_NOT_CORRECT, details, TextUtil.UUID); + ExceptionUtil.validateConditionDataNotFoundException(ValidateUtil.isSize(names, 1), + TextUtil.DATA_IS_NOT_FOUND, details, TextUtil.UUID); } SystemGroup systemGroup = null; @@ -290,8 +290,8 @@ public class ValidateNameElementUtil { if (parentDevicestructure != null) { countDevicestructureIndex++; deviceType = holderIRepositories.getDeviceTypeRepository().findLatestByUuid(parentDevicestructure.toString()); - ExceptionUtil.validateConditionDataNotAvailableException(deviceType != null, - TextUtil.DATA_IS_NOT_AVAILABLE, details, TextUtil.PARENTDEVICESTRUCTURE); + ExceptionUtil.validateConditionDataNotFoundException(deviceType != null, + TextUtil.DATA_IS_NOT_FOUND, details, TextUtil.PARENTDEVICESTRUCTURE); ExceptionUtil.validateConditionDataDeletedException(!deviceType.isDeleted(), TextUtil.DATA_IS_DELETED, details, TextUtil.PARENTDEVICESTRUCTURE); } @@ -310,7 +310,7 @@ public class ValidateNameElementUtil { TextUtil.DATA_IS_DELETED, details, TextUtil.PARENTSYSTEMSTRUCTURE); derivedName = NameUtil.getName(subsystem, deviceType, index, holder); } else { - throw ExceptionUtil.createDataNotCorrectException(TextUtil.DATA_IS_NOT_CORRECT, details, TextUtil.PARENTSYSTEMSTRUCTURE); + throw ExceptionUtil.createDataNotFoundException(TextUtil.DATA_IS_NOT_FOUND, details, TextUtil.PARENTSYSTEMSTRUCTURE); } // index @@ -323,7 +323,7 @@ public class ValidateNameElementUtil { } condition = countDevicestructureIndex == 0 || countDevicestructureIndex == 2; - ExceptionUtil.validateConditionDataNotAvailableException(condition, + ExceptionUtil.validateConditionDataNotCorrectException(condition, TextUtil.DEVICETYPE_OR_INDEX_IS_NOT_AVAILABLE, details, TextUtil.PARENTDEVICESTRUCTURE); // name @@ -335,7 +335,7 @@ public class ValidateNameElementUtil { // NameCommand.UPDATE.equals(nameCommand) condition = ValidateUtil.isNullOrEmpty(names) || names.size() == 1 && names.get(0).getUuid().equals(uuid); } - ExceptionUtil.validateConditionDataExistException(condition, + ExceptionUtil.validateConditionDataConflictException(condition, TextUtil.CONVENTION_NAME_EXISTS, details, TextUtil.PARENTSYSTEMSTRUCTURE); names = nameRepository.readNames(false, null, null, namingConvention.equivalenceClassRepresentative(derivedName), null, null, null, null); @@ -345,7 +345,7 @@ public class ValidateNameElementUtil { // NameCommand.UPDATE.equals(nameCommand) condition = ValidateUtil.isNullOrEmpty(names) || names.size() == 1 && names.get(0).getUuid().equals(uuid); } - ExceptionUtil.validateConditionDataExistException(condition, + ExceptionUtil.validateConditionDataConflictException(condition, TextUtil.CONVENTION_NAME_EQUIVALENCE_EXISTS, details, TextUtil.PARENTSYSTEMSTRUCTURE); } else if (NameCommand.DELETE.equals(nameCommand)) { // n.a. @@ -430,8 +430,8 @@ public class ValidateNameElementUtil { // device structure if (!StringUtils.isEmpty(dt)) { List<DeviceType> deviceTypes = holderRepositories.getDeviceTypeRepository().readDeviceTypes(Status.APPROVED, false, null, null, null, null, null, mnemonicPathDeviceStructure, null); - ExceptionUtil.validateConditionDataNotAvailableException(ValidateUtil.isSize(deviceTypes, 1), - TextUtil.DEVICETYPE_IS_NOT_AVAILABLE, details, field); + ExceptionUtil.validateConditionDataNotFoundException(ValidateUtil.isSize(deviceTypes, 1), + TextUtil.DEVICE_STRUCTURE_IS_NOT_FOUND, details, field); deviceType = deviceTypes.get(0); } @@ -450,7 +450,7 @@ public class ValidateNameElementUtil { systemGroup = systemGroups.get(0); derivedName = NameUtil.getName(systemGroup, deviceType, NamingConventionUtil.extractInstanceIndex(name), holder); } else { - throw ExceptionUtil.createDataNotCorrectException(TextUtil.SYSTEM_STRUCTURE_IS_NOT_CORRECT, details, field); + throw ExceptionUtil.createDataNotFoundException(TextUtil.SYSTEM_STRUCTURE_IS_NOT_FOUND, details, field); } // index @@ -468,11 +468,11 @@ public class ValidateNameElementUtil { TextUtil.CONVENTION_NAME_IS_NOT_CORRECT, details, field); List<Name> names = holderRepositories.getNameRepository().readNames(false, null, name, null, null, null, null, null); - ExceptionUtil.validateConditionDataExistException(names.isEmpty(), + ExceptionUtil.validateConditionDataConflictException(names.isEmpty(), TextUtil.CONVENTION_NAME_EXISTS, details, field); names = holderRepositories.getNameRepository().readNames(false, null, null, namingConvention.equivalenceClassRepresentative(name), null, null, null, null); - ExceptionUtil.validateConditionDataExistException(names.isEmpty(), + ExceptionUtil.validateConditionDataConflictException(names.isEmpty(), TextUtil.CONVENTION_NAME_EQUIVALENCE_EXISTS, details, field); } diff --git a/src/main/java/org/openepics/names/util/ValidateStructureElementUtil.java b/src/main/java/org/openepics/names/util/ValidateStructureElementUtil.java index 89ded2c3..d8287198 100644 --- a/src/main/java/org/openepics/names/util/ValidateStructureElementUtil.java +++ b/src/main/java/org/openepics/names/util/ValidateStructureElementUtil.java @@ -348,28 +348,34 @@ public class ValidateStructureElementUtil { if (ValidateUtil.isAnyEqual(type, Type.SYSTEMGROUP, Type.DISCIPLINE) && parent != null) { throw ExceptionUtil.createDataNotCorrectException(TextUtil.PARENT_IS_NOT_CORRECT, details, field); } else if (ValidateUtil.isAnyEqual(structureCommand, StructureCommand.UPDATE, StructureCommand.DELETE)) { - validateStructuresStatusSize0(uuid, type, Status.PENDING, null, + validateStructuresFound(uuid, type, holderRepositories, message, details, field); - - validateStructuresStatusSize1(uuid, type, Status.APPROVED, Boolean.FALSE, + validateStructuresValidSize0(uuid, type, Status.PENDING, null, + holderRepositories, message, details, field); + validateStructuresValidSize1(uuid, type, Status.APPROVED, Boolean.FALSE, holderRepositories, message, details, field); } else if (ValidateUtil.isAnyEqual(structureCommand, StructureCommand.APPROVE, StructureCommand.CANCEL, StructureCommand.REJECT)) { - validateStructuresStatusSize1(uuid, type, Status.PENDING, null, + validateStructuresFound(uuid, type, + holderRepositories, message, details, field); + validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); } } - private static void validateStructuresStatusSize0(UUID uuid, Type type, Status status, Boolean deleted, + private static void validateStructuresFound(UUID uuid, Type type, + HolderRepositories holderRepositories, String message, String details, String field) { + ExceptionUtil.validateConditionDataNotFoundException( + getStructuresSize(uuid, type, null, null, holderRepositories) > 0, message, details, field); + } + private static void validateStructuresValidSize0(UUID uuid, Type type, Status status, Boolean deleted, HolderRepositories holderRepositories, String message, String details, String field) { - ExceptionUtil.validateConditionDataNotCorrectException( - getStructuresSize(uuid, type, status, deleted, holderRepositories) == 0, - message, details, field); + ExceptionUtil.validateConditionDataNotValidException( + getStructuresSize(uuid, type, status, deleted, holderRepositories) == 0, message, details, field); } - private static void validateStructuresStatusSize1(UUID uuid, Type type, Status status, Boolean deleted, + private static void validateStructuresValidSize1(UUID uuid, Type type, Status status, Boolean deleted, HolderRepositories holderRepositories, String message, String details, String field) { - ExceptionUtil.validateConditionDataNotCorrectException( - getStructuresSize(uuid, type, status, deleted, holderRepositories) == 1, - message, details, field); + ExceptionUtil.validateConditionDataNotValidException( + getStructuresSize(uuid, type, status, deleted, holderRepositories) == 1, message, details, field); } private static int getStructuresSize(UUID uuid, Type type, Status status, Boolean deleted, HolderRepositories holderRepositories) { @@ -499,7 +505,7 @@ public class ValidateStructureElementUtil { // status, parent message = TextUtil.DISCIPLINE_IS_NOT_CORRECT; List<Discipline> disciplines = holderRepositories.getDisciplineRepository().readDisciplines(Status.APPROVED, false, parent.toString(), null, null, null, null, null); - ExceptionUtil.validateConditionDataConflictException(ValidateUtil.isSize(disciplines, 1), + ExceptionUtil.validateConditionDataNotFoundException(ValidateUtil.isSize(disciplines, 1), message, details, TextUtil.PARENT); // note rules for mnemonic for device group @@ -529,60 +535,80 @@ public class ValidateStructureElementUtil { if (Type.SYSTEMGROUP.equals(type)) { // status, uuid message = TextUtil.SYSTEMGROUP_IS_NOT_CORRECT; - validateStructuresStatusSize1(uuid, type, Status.PENDING, null, + validateStructuresFound(uuid, type, + holderRepositories, message, details, field); + validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); } else if (Type.SYSTEM.equals(type)) { // status, uuid message = TextUtil.SYSTEM_IS_NOT_CORRECT; - validateStructuresStatusSize1(uuid, type, Status.PENDING, null, + validateStructuresFound(uuid, type, + holderRepositories, message, details, field); + validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); List<System> systems = holderRepositories.getSystemRepository().readSystems(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null); // status, parent message = TextUtil.SYSTEMGROUP_IS_NOT_CORRECT; - validateStructuresStatusSize1(systems.get(0).getParentUuid(), Type.SYSTEMGROUP, Status.APPROVED, false, + validateStructuresFound(systems.get(0).getParentUuid(), Type.SYSTEMGROUP, + holderRepositories, message, details, field); + validateStructuresValidSize1(systems.get(0).getParentUuid(), Type.SYSTEMGROUP, Status.APPROVED, false, holderRepositories, message, details, field); } else if (Type.SUBSYSTEM.equals(type)) { // status, uuid message = TextUtil.SUBSYSTEM_IS_NOT_CORRECT; - validateStructuresStatusSize1(uuid, type, Status.PENDING, null, + validateStructuresFound(uuid, type, + holderRepositories, message, details, field); + validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); List<Subsystem> subsystems = holderRepositories.getSubsystemRepository().readSubsystems(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null); // status, parent message = TextUtil.SYSTEM_IS_NOT_CORRECT; - validateStructuresStatusSize1(subsystems.get(0).getParentUuid(), Type.SYSTEM, Status.APPROVED, false, + validateStructuresFound(subsystems.get(0).getParentUuid(), Type.SYSTEM, + holderRepositories, message, details, field); + validateStructuresValidSize1(subsystems.get(0).getParentUuid(), Type.SYSTEM, Status.APPROVED, false, holderRepositories, message, details, field); } else if (Type.DISCIPLINE.equals(type)) { // status, uuid message = TextUtil.DISCIPLINE_IS_NOT_CORRECT; - validateStructuresStatusSize1(uuid, type, Status.PENDING, null, + validateStructuresFound(uuid, type, + holderRepositories, message, details, field); + validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); } else if (Type.DEVICEGROUP.equals(type)) { // status, uuid message = TextUtil.DEVICEGROUP_IS_NOT_CORRECT; - validateStructuresStatusSize1(uuid, type, Status.PENDING, null, + validateStructuresFound(uuid, type, + holderRepositories, message, details, field); + validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); List<DeviceGroup> deviceGroups = holderRepositories.getDeviceGroupRepository().readDeviceGroups(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null); // status, parent message = TextUtil.DISCIPLINE_IS_NOT_CORRECT; - validateStructuresStatusSize1(deviceGroups.get(0).getParentUuid(), Type.DISCIPLINE, Status.APPROVED, false, + validateStructuresFound(deviceGroups.get(0).getParentUuid(), Type.DISCIPLINE, + holderRepositories, message, details, field); + validateStructuresValidSize1(deviceGroups.get(0).getParentUuid(), Type.DISCIPLINE, Status.APPROVED, false, holderRepositories, message, details, field); } else if (Type.DEVICETYPE.equals(type)) { // status, uuid message = TextUtil.DEVICETYPE_IS_NOT_CORRECT; - validateStructuresStatusSize1(uuid, type, Status.PENDING, null, + validateStructuresFound(uuid, type, + holderRepositories, message, details, field); + validateStructuresValidSize1(uuid, type, Status.PENDING, null, holderRepositories, message, details, field); List<DeviceType> deviceTypes = holderRepositories.getDeviceTypeRepository().readDeviceTypes(Status.PENDING, null, uuid.toString(), null, null, null, null, null, null); // status, parent message = TextUtil.DISCIPLINE_IS_NOT_CORRECT; - validateStructuresStatusSize1(deviceTypes.get(0).getParentUuid(), Type.DEVICEGROUP, Status.APPROVED, false, + validateStructuresFound(deviceTypes.get(0).getParentUuid(), Type.DEVICEGROUP, + holderRepositories, message, details, field); + validateStructuresValidSize1(deviceTypes.get(0).getParentUuid(), Type.DEVICEGROUP, Status.APPROVED, false, holderRepositories, message, details, field); } } @@ -592,7 +618,7 @@ public class ValidateStructureElementUtil { HolderRepositories holderRepositories, String message, String details, String field){ // about finding out if structures are in place in order for structure operation to be allowed - ExceptionUtil.validateConditionDataConflictException( + ExceptionUtil.validateConditionDataNotFoundException( getStructuresParentSize(type, parent, status, deleted, holderRepositories) == 1, message, details, field); } private static void validateStructuresStatusMnemonic(UUID uuid, Type type, UUID parent, String mnemonic, @@ -741,8 +767,8 @@ public class ValidateStructureElementUtil { String mnemonicpathEquivalence = namingConvention.equivalenceClassRepresentative(mnemonicPath); // validate path, including null check - ExceptionUtil.validateConditionDataNotValidException(path != null && path.length >= 1 && path.length <= 2, - TextUtil.STRUCTURE_MNEMONIC_PATH_IS_NOT_VALID, details, field); + ExceptionUtil.validateConditionDataNotCorrectException(path != null && path.length >= 1 && path.length <= 2, + TextUtil.STRUCTURE_MNEMONIC_PATH_IS_NOT_CORRECT, details, field); if (Type.SYSTEMGROUP.equals(type)) { validateStructuresMnemonicpathNotValid(path.length == 1, type, details, field); @@ -801,7 +827,7 @@ public class ValidateStructureElementUtil { validateStructuresMnemonicpathNotValid(path.length == 2, type, details, field); System sys = holderIRepositories.getSystemRepository().findLatestNotDeletedByMnemonic(path[0]); - validateStructuresMnemonicpathNotAvailable(sys != null, type, details, field); + validateStructuresMnemonicpathNotFound(sys != null, type, details, field); SystemGroup sg = holderIRepositories.getSystemGroupRepository().findLatestNotDeletedByUuid(sys.getParentUuid().toString()); // mnemonic path @@ -863,8 +889,8 @@ public class ValidateStructureElementUtil { // discipline Discipline discipline = holderIRepositories.getDisciplineRepository().findLatestNotDeletedByMnemonic(path[0]); - ExceptionUtil.validateConditionDataNotValidException(discipline != null, - TextUtil.DISCIPLINE_IS_NOT_VALID, details, field); + ExceptionUtil.validateConditionDataNotFoundException(discipline != null, + TextUtil.DISCIPLINE_IS_NOT_FOUND, details, field); // mnemonic path validateStructuresMnemonicpathDuplicate(!StringUtils.equals(path[0], path[1]), type, details, field); @@ -890,9 +916,9 @@ public class ValidateStructureElementUtil { } } - private static void validateStructuresMnemonicpathNotAvailable(boolean condition, Type type, String details, String field) { - ExceptionUtil.validateConditionDataNotValidException(condition, - type.toString().toLowerCase() + TextUtil.SPACE + TextUtil.MNEMONIC_PATH_IS_NOT_AVAILABLE, + private static void validateStructuresMnemonicpathNotFound(boolean condition, Type type, String details, String field) { + ExceptionUtil.validateConditionDataNotFoundException(condition, + type.toString().toLowerCase() + TextUtil.SPACE + TextUtil.MNEMONIC_PATH_IS_NOT_FOUND, details, field); } diff --git a/src/test/java/org/openepics/names/docker/ITUtilNameElement.java b/src/test/java/org/openepics/names/docker/ITUtilNameElement.java index 13823edd..8cc5a56f 100644 --- a/src/test/java/org/openepics/names/docker/ITUtilNameElement.java +++ b/src/test/java/org/openepics/names/docker/ITUtilNameElement.java @@ -599,104 +599,79 @@ public class ITUtilNameElement { // ---------------------------------------------------------------------------------------------------- /** - * Utility method to (try to) create a name element and assert result response code. - * Method expected to NOT succeed to create a name element - * but instead assert response code (possibly also a non-empty message). + * Utility method to create a name element and assert result. * * @param nameElementCommand name element command - * @param responseCode response code - * @throws JsonProcessingException - */ - public static void assertCreate(NameElementCommandCreate nameElementCommand, int responseCode) throws JsonProcessingException { - assertCreate(AuthorizationChoice.NONE, object2Json(new NameElementCommandCreate[] {nameElementCommand}), responseCode); - } - /** - * Utility method to (try to) create a name element from given json and assert result response code. - * Method expected to NOT succeed to create a name element - * but instead assert response code (possibly also a non-empty message). - * - * @param json json - * @param responseCode response code + * @return created name element */ - public static void assertCreate(String json, int responseCode) { - assertCreate(AuthorizationChoice.NONE, json, responseCode); + public static NameElement assertCreate(NameElementCommandCreate nameElementCommand) { + NameElement[] createdNameElements = assertCreate(AuthorizationChoice.NONE, object2Json(new NameElementCommandCreate[] {nameElementCommand}), HttpURLConnection.HTTP_CREATED); + return createdNameElements != null + ? createdNameElements[0] + : null; } /** - * Utility method to (try to) create a name element from given json and assert result response code. - * Method expected to NOT succeed to create a name element - * but instead assert response code (possibly also a non-empty message). + * Utility method to create a name element and assert result and response code. * - * @param authorizationChoice authorization choice (none, user, admin) - * @param json json + * @param nameElementCommand name element command * @param responseCode response code + * @return created name element */ - public static void assertCreate(AuthorizationChoice authorizationChoice, String json, int responseCode) { - try { - String[] response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(authorizationChoice, EndpointChoice.NAMES, "", json)); - ITUtil.assertResponseLength2Code(response, responseCode); - // ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); - } catch (IOException e) { - fail(); - } catch (InterruptedException e) { - fail(); - } catch (Exception e) { - fail(); - } + public static NameElement assertCreate(NameElementCommandCreate nameElementCommand, int responseCode) { + NameElement[] createdNameElements = assertCreate(AuthorizationChoice.NONE, object2Json(new NameElementCommandCreate[] {nameElementCommand}), responseCode); + return createdNameElements != null + ? createdNameElements[0] + : null; } - - // -------------------- - /** - * Utility method to create a name element and assert result. + * Utility method to create name elements and assert result. * - * @param nameElementCommand name element command + * @param nameElementCommands name element commands * @return created name element */ - public static NameElement assertCreate(NameElementCommandCreate nameElementCommand) { - return assertCreate(AuthorizationChoice.NONE, new NameElementCommandCreate[] {nameElementCommand})[0]; + public static NameElement[] assertCreate(NameElementCommandCreate[] nameElementCommands) { + return assertCreate(AuthorizationChoice.NONE, object2Json(nameElementCommands), HttpURLConnection.HTTP_CREATED); } /** - * Utility method to create name elements and assert result. + * Utility method to create name elements and assert result and response code. * - * @param nameElementCommands name element commands + * @param json json + * @param responseCode response code * @return created name element */ - public static NameElement[] assertCreate(NameElementCommandCreate[] nameElementCommands) { - return assertCreate(AuthorizationChoice.NONE, nameElementCommands); + public static NameElement[] assertCreate(String json, int responseCode) { + return assertCreate(AuthorizationChoice.NONE, json, responseCode); } /** - * Utility method to create name elements and assert result. + * Utility method to create json (name elements) and assert result and response code. * * @param authorizationChoice authorization choice (none, user, admin) - * @param nameElementCommands name element commands + * @param json json + * @param responseCode response code * @return created name element */ - public static NameElement[] assertCreate(AuthorizationChoice authorizationChoice, NameElementCommandCreate[] nameElementCommands) { - String path = getValidatePath(NameCommand.CREATE); + public static NameElement[] assertCreate(AuthorizationChoice authorizationChoice, String json, int responseCode) { + NameElement[] createdNameElements = null; try { String[] response = null; - NameElement[] createdNameElements = null; - response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.NAMES, path, object2Json(nameElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); - - response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(authorizationChoice, EndpointChoice.NAMES, "", object2Json(nameElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_CREATED); - createdNameElements = mapper.readValue(response[1], NameElement[].class); + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(authorizationChoice, EndpointChoice.NAMES, "", json)); + ITUtil.assertResponseLength2Code(response, responseCode); - for (NameElement createdNameElement : createdNameElements) { - assertNotNull(createdNameElement.getUuid()); - assertEquals(Boolean.TRUE, createdNameElement.isLatest()); - assertEquals(Boolean.FALSE, createdNameElement.isDeleted()); - assertNotNull(createdNameElement.getWhen()); - } + if (HttpURLConnection.HTTP_CREATED == responseCode) { + createdNameElements = mapper.readValue(response[1], NameElement[].class); - // not set uuid for input parameter(s) - // convenience, easy when array length 1, otherwise not easy + for (NameElement createdNameElement : createdNameElements) { + assertNotNull(createdNameElement.getUuid()); + assertEquals(Boolean.TRUE, createdNameElement.isLatest()); + assertEquals(Boolean.FALSE, createdNameElement.isDeleted()); + assertNotNull(createdNameElement.getWhen()); + } - return createdNameElements; + // not set uuid for input parameter(s) + // convenience, easy when array length 1, otherwise not easy + } } catch (IOException e) { fail(); } catch (InterruptedException e) { @@ -705,9 +680,11 @@ public class ITUtilNameElement { fail(); } - return null; + return createdNameElements; } + // ---------------------------------------------------------------------------------------------------- + /** * Utility method to update a name element and assert result. * @@ -715,7 +692,23 @@ public class ITUtilNameElement { * @return updated name element */ public static NameElement assertUpdate(NameElementCommandUpdate nameElementCommand) { - return assertUpdate(AuthorizationChoice.NONE, new NameElementCommandUpdate[] {nameElementCommand})[0]; + NameElement[] updatedNameElements = assertUpdate(AuthorizationChoice.NONE, object2Json(new NameElementCommandUpdate[] {nameElementCommand}), HttpURLConnection.HTTP_OK); + return updatedNameElements != null + ? updatedNameElements[0] + : null; + } + /** + * Utility method to update a name element and assert result and response code. + * + * @param nameElementCommand name element command + * @param responseCode response code + * @return updated name element + */ + public static NameElement assertUpdate(NameElementCommandUpdate nameElementCommand, int responseCode) { + NameElement[] updatedNameElements = assertUpdate(AuthorizationChoice.NONE, object2Json(new NameElementCommandUpdate[] {nameElementCommand}), responseCode); + return updatedNameElements != null + ? updatedNameElements[0] + : null; } /** * Utility method to update name elements and assert result. @@ -724,38 +717,35 @@ public class ITUtilNameElement { * @return updated name element */ public static NameElement[] assertUpdate(NameElementCommandUpdate[] nameElementCommands) { - return assertUpdate(AuthorizationChoice.NONE, nameElementCommands); + return assertUpdate(AuthorizationChoice.NONE, object2Json(nameElementCommands), HttpURLConnection.HTTP_OK); } /** - * Utility method to update name elements and assert result. + * Utility method to update json (name elements) and assert result and response code. * * @param authorizationChoice authorization choice (none, user, admin) - * @param nameElementCommands name element commands + * @param json json + * @param responseCode response code * @return updated name element */ - public static NameElement[] assertUpdate(AuthorizationChoice authorizationChoice, NameElementCommandUpdate[] nameElementCommands) { - String path = getValidatePath(NameCommand.UPDATE); + public static NameElement[] assertUpdate(AuthorizationChoice authorizationChoice, String json, int responseCode) { + NameElement[] updatedNameElements = null; try { String[] response = null; - NameElement[] updatedNameElements = null; - response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.NAMES, path, object2Json(nameElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + response = ITUtil.runShellCommand(ITUtil.curlPutPathJson(authorizationChoice, EndpointChoice.NAMES, "", json)); + ITUtil.assertResponseLength2Code(response, responseCode); - response = ITUtil.runShellCommand(ITUtil.curlPutPathJson(authorizationChoice, EndpointChoice.NAMES, "", object2Json(nameElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - updatedNameElements = mapper.readValue(response[1], NameElement[].class); + if (HttpURLConnection.HTTP_OK == responseCode) { + updatedNameElements = mapper.readValue(response[1], NameElement[].class); - for (NameElement updatedNameElement : updatedNameElements) { - assertNotNull(updatedNameElement.getUuid()); - assertEquals(Boolean.TRUE, updatedNameElement.isLatest()); - assertEquals(Boolean.FALSE, updatedNameElement.isDeleted()); - assertNotNull(updatedNameElement.getWhen()); + for (NameElement updatedNameElement : updatedNameElements) { + assertNotNull(updatedNameElement.getUuid()); + assertEquals(Boolean.TRUE, updatedNameElement.isLatest()); + assertEquals(Boolean.FALSE, updatedNameElement.isDeleted()); + assertNotNull(updatedNameElement.getWhen()); + } } - - return updatedNameElements; } catch (IOException e) { fail(); } catch (InterruptedException e) { @@ -764,9 +754,11 @@ public class ITUtilNameElement { fail(); } - return null; + return updatedNameElements; } + // ---------------------------------------------------------------------------------------------------- + /** * Utility method to delete a name element and assert result. * @@ -774,7 +766,23 @@ public class ITUtilNameElement { * @return deleted name element */ public static NameElement assertDelete(NameElementCommandConfirm nameElementCommand) { - return assertDelete(AuthorizationChoice.NONE, new NameElementCommandConfirm[] {nameElementCommand})[0]; + NameElement[] deletedNameElements = assertDelete(AuthorizationChoice.NONE, object2Json(new NameElementCommandConfirm[] {nameElementCommand}), HttpURLConnection.HTTP_OK); + return deletedNameElements != null + ? deletedNameElements[0] + : null; + } + /** + * Utility method to delete a name element and assert result and response code. + * + * @param nameElementCommand name element command + * @param responseCode response code + * @return deleted name element + */ + public static NameElement assertDelete(NameElementCommandConfirm nameElementCommand, int responseCode) { + NameElement[] deletedNameElements = assertDelete(AuthorizationChoice.NONE, object2Json(new NameElementCommandConfirm[] {nameElementCommand}), responseCode); + return deletedNameElements != null + ? deletedNameElements[0] + : null; } /** * Utility method to delete name elements and assert result. @@ -783,38 +791,36 @@ public class ITUtilNameElement { * @return deleted name elements */ public static NameElement[] assertDelete(NameElementCommandConfirm[] nameElementCommands) { - return assertDelete(AuthorizationChoice.NONE, nameElementCommands); + return assertDelete(AuthorizationChoice.NONE, object2Json(nameElementCommands), HttpURLConnection.HTTP_OK); } /** - * Utility method to delete name elements and assert result. + * Utility method to delete json (name elements) and assert result and response code. * * @param authorizationChoice authorization choice (none, user, admin) - * @param nameElementCommands name element commands + * @param json json + * @param responseCode response code * @return deleted name elements */ - public static NameElement[] assertDelete(AuthorizationChoice authorizationChoice, NameElementCommandConfirm[] nameElementCommands) { - String path = getValidatePath(NameCommand.DELETE); + public static NameElement[] assertDelete(AuthorizationChoice authorizationChoice, String json, int responseCode) { + NameElement[] deletedNameElements = null; try { String[] response = null; - NameElement[] deletedNameElements = null; - response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.NAMES, path, object2Json(nameElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + response = ITUtil.runShellCommand(ITUtil.curlDeletePathJson(authorizationChoice, EndpointChoice.NAMES, "", json)); + ITUtil.assertResponseLength2Code(response, responseCode); - response = ITUtil.runShellCommand(ITUtil.curlDeletePathJson(authorizationChoice, EndpointChoice.NAMES, "", object2Json(nameElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - deletedNameElements = mapper.readValue(response[1], NameElement[].class); + if (HttpURLConnection.HTTP_OK == responseCode) { + deletedNameElements = mapper.readValue(response[1], NameElement[].class); - for (NameElement deletedNameElement : deletedNameElements) { - assertNotNull(deletedNameElement.getUuid()); - assertEquals(Boolean.TRUE, deletedNameElement.isLatest()); - assertEquals(Boolean.TRUE, deletedNameElement.isDeleted()); - assertNotNull(deletedNameElement.getWhen()); - } + for (NameElement deletedNameElement : deletedNameElements) { + assertNotNull(deletedNameElement.getUuid()); + assertEquals(Boolean.TRUE, deletedNameElement.isLatest()); + assertEquals(Boolean.TRUE, deletedNameElement.isDeleted()); + assertNotNull(deletedNameElement.getWhen()); + } - return deletedNameElements; + } } catch (IOException e) { fail(); } catch (InterruptedException e) { @@ -823,7 +829,7 @@ public class ITUtilNameElement { fail(); } - return null; + return deletedNameElements; } } diff --git a/src/test/java/org/openepics/names/docker/ITUtilStructureElement.java b/src/test/java/org/openepics/names/docker/ITUtilStructureElement.java index 112b1134..26d78dd8 100644 --- a/src/test/java/org/openepics/names/docker/ITUtilStructureElement.java +++ b/src/test/java/org/openepics/names/docker/ITUtilStructureElement.java @@ -564,105 +564,80 @@ public class ITUtilStructureElement { // ---------------------------------------------------------------------------------------------------- /** - * Utility method to (try to) create a structure element and assert result response code. - * Method expected to NOT succeed to create a structure element - * but instead assert response code (possibly also a non-empty message). + * Utility method to create a structure element and assert result. * * @param structureElementCommand structure element command - * @param responseCode response code - * @throws JsonProcessingException + * @return created structure element */ - public static void assertCreate(StructureElementCommandCreate structureElementCommand, int responseCode) throws JsonProcessingException { - assertCreate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandCreate[] {structureElementCommand}), responseCode); + public static StructureElement assertCreate(StructureElementCommandCreate structureElementCommand) { + StructureElement[] createdStructureElements = assertCreate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandCreate[] {structureElementCommand}), HttpURLConnection.HTTP_CREATED); + return createdStructureElements != null + ? createdStructureElements[0] + : null; } /** - * Utility method to (try to) create a structure element from given json and assert result response code. - * Method expected to NOT succeed to create a structure element - * but instead assert response code (possibly also a non-empty message). + * Utility method to create a structure element and assert result and response code. * - * @param json json + * @param structureElementCommand structure element command * @param responseCode response code + * @return created structure element */ - public static void assertCreate(String json, int responseCode) { - assertCreate(AuthorizationChoice.NONE, json, responseCode); + public static StructureElement assertCreate(StructureElementCommandCreate structureElementCommand, int responseCode) { + StructureElement[] createdStructureElements = assertCreate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandCreate[] {structureElementCommand}), responseCode); + return createdStructureElements != null + ? createdStructureElements[0] + : null; } /** - * Utility method to (try to) create a structure element from given json and assert result response code. - * Method expected to NOT succeed to create a structure element - * but instead assert response code (possibly also a non-empty message). - * - * @param authorizationChoice authorization choice (none, user, admin) - * @param json json - * @param responseCode response code - */ - public static void assertCreate(AuthorizationChoice authorizationChoice, String json, int responseCode) { - try { - String[] response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "", json)); - ITUtil.assertResponseLength2Code(response, responseCode); - // ITUtil.assertMessageNotEmpty(mapper.readValue(response[1], Response.class)); - } catch (IOException e) { - fail(); - } catch (InterruptedException e) { - fail(); - } catch (Exception e) { - fail(); - } - } - - // -------------------- - - /** - * Utility method to create a structure element and assert result. + * Utility method to create structure elements and assert result. * - * @param structureElementCommand structure element command + * @param structureElementCommands structure element commands * @return created structure element */ - public static StructureElement assertCreate(StructureElementCommandCreate structureElementCommand) { - return assertCreate(AuthorizationChoice.NONE, new StructureElementCommandCreate[] {structureElementCommand})[0]; + public static StructureElement[] assertCreate(StructureElementCommandCreate[] structureElementCommands) { + return assertCreate(AuthorizationChoice.NONE, object2Json(structureElementCommands), HttpURLConnection.HTTP_CREATED); } /** - * Utility method to create structure elements and assert result. + * Utility method to create json (structure elements) and assert result and response code. * - * @param structureElementCommands structure element commands + * @param json json + * @param responseCode response code * @return created structure element */ - public static StructureElement[] assertCreate(StructureElementCommandCreate[] structureElementCommands) { - return assertCreate(AuthorizationChoice.NONE, structureElementCommands); + public static StructureElement[] assertCreate(String json, int responseCode) { + return assertCreate(AuthorizationChoice.NONE, json, responseCode); } /** - * Utility method to create structure elements and assert result. + * Utility method to create json (structure elements) and assert result and response code. * * @param authorizationChoice authorization choice (none, user, admin) - * @param structureElementCommands structure element commands + * @param json json + * @param responseCode response code * @return created structure element */ - public static StructureElement[] assertCreate(AuthorizationChoice authorizationChoice, StructureElementCommandCreate[] structureElementCommands) { - String path = getValidatePath(StructureCommand.CREATE); + public static StructureElement[] assertCreate(AuthorizationChoice authorizationChoice, String json, int responseCode) { + StructureElement[] createdStructureElements = null; try { String[] response = null; - StructureElement[] createdStructureElements = null; - response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.STRUCTURES, path, object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); - - response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "", object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_CREATED); - createdStructureElements = mapper.readValue(response[1], StructureElement[].class); - - for (StructureElement createdStructureElement : createdStructureElements) { - assertNotNull(createdStructureElement.getUuid()); - assertEquals(Status.PENDING, createdStructureElement.getStatus()); - assertEquals(Boolean.FALSE, createdStructureElement.isLatest()); - assertEquals(Boolean.FALSE, createdStructureElement.isDeleted()); - assertNotNull(createdStructureElement.getWhen()); - } + response = ITUtil.runShellCommand(ITUtil.curlPostPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "", json)); + ITUtil.assertResponseLength2Code(response, responseCode); - // not set uuid for input parameter(s) - // convenience, easy when array length 1, otherwise not easy + if (HttpURLConnection.HTTP_CREATED == responseCode) { + createdStructureElements = mapper.readValue(response[1], StructureElement[].class); - return createdStructureElements; + for (StructureElement createdStructureElement : createdStructureElements) { + assertNotNull(createdStructureElement.getUuid()); + assertEquals(Status.PENDING, createdStructureElement.getStatus()); + assertEquals(Boolean.FALSE, createdStructureElement.isLatest()); + assertEquals(Boolean.FALSE, createdStructureElement.isDeleted()); + assertNotNull(createdStructureElement.getWhen()); + } + + // not set uuid for input parameter(s) + // convenience, easy when array length 1, otherwise not easy + } } catch (IOException e) { fail(); } catch (InterruptedException e) { @@ -671,9 +646,11 @@ public class ITUtilStructureElement { fail(); } - return null; + return createdStructureElements; } + // ---------------------------------------------------------------------------------------------------- + /** * Utility method to update a structure element and assert result. * @@ -681,7 +658,23 @@ public class ITUtilStructureElement { * @return updated structure element */ public static StructureElement assertUpdate(StructureElementCommandUpdate structureElementCommand) { - return assertUpdate(AuthorizationChoice.NONE, new StructureElementCommandUpdate[] {structureElementCommand})[0]; + StructureElement[] updatedStructureElements = assertUpdate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandUpdate[] {structureElementCommand}), HttpURLConnection.HTTP_OK); + return updatedStructureElements != null + ? updatedStructureElements[0] + : null; + } + /** + * Utility method to update a structure element and assert result and response code. + * + * @param structureElementCommand structure element command + * @param responseCode response code + * @return updated structure element + */ + public static StructureElement assertUpdate(StructureElementCommandUpdate structureElementCommand, int responseCode) { + StructureElement[] updatedStructureElements = assertUpdate(AuthorizationChoice.NONE, object2Json(new StructureElementCommandUpdate[] {structureElementCommand}), responseCode); + return updatedStructureElements != null + ? updatedStructureElements[0] + : null; } /** * Utility method to update structure elements and assert result. @@ -690,39 +683,36 @@ public class ITUtilStructureElement { * @return updated structure element */ public static StructureElement[] assertUpdate(StructureElementCommandUpdate[] structureElementCommands) { - return assertUpdate(AuthorizationChoice.NONE, structureElementCommands); + return assertUpdate(AuthorizationChoice.NONE, object2Json(structureElementCommands), HttpURLConnection.HTTP_OK); } /** - * Utility method to update structure elements and assert result. + * Utility method to update json (structure elements) and assert result and response code. * * @param authorizationChoice authorization choice (none, user, admin) - * @param structureElementCommands structure element commands + * @param json json + * @param responseCode response code * @return updated structure element */ - public static StructureElement[] assertUpdate(AuthorizationChoice authorizationChoice, StructureElementCommandUpdate[] structureElementCommands) { - String path = getValidatePath(StructureCommand.UPDATE); + public static StructureElement[] assertUpdate(AuthorizationChoice authorizationChoice, String json, int responseCode) { + StructureElement[] updatedStructureElements = null; try { String[] response = null; - StructureElement[] updatedStructureElements = null; - response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.STRUCTURES, path, object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + response = ITUtil.runShellCommand(ITUtil.curlPutPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "", json)); + ITUtil.assertResponseLength2Code(response, responseCode); - response = ITUtil.runShellCommand(ITUtil.curlPutPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "", object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - updatedStructureElements = mapper.readValue(response[1], StructureElement[].class); - - for (StructureElement updatedStructureElement : updatedStructureElements) { - assertNotNull(updatedStructureElement.getUuid()); - assertEquals(Status.PENDING, updatedStructureElement.getStatus()); - assertEquals(Boolean.FALSE, updatedStructureElement.isLatest()); - assertEquals(Boolean.FALSE, updatedStructureElement.isDeleted()); - assertNotNull(updatedStructureElement.getWhen()); - } + if (HttpURLConnection.HTTP_OK == responseCode) { + updatedStructureElements = mapper.readValue(response[1], StructureElement[].class); - return updatedStructureElements; + for (StructureElement updatedStructureElement : updatedStructureElements) { + assertNotNull(updatedStructureElement.getUuid()); + assertEquals(Status.PENDING, updatedStructureElement.getStatus()); + assertEquals(Boolean.FALSE, updatedStructureElement.isLatest()); + assertEquals(Boolean.FALSE, updatedStructureElement.isDeleted()); + assertNotNull(updatedStructureElement.getWhen()); + } + } } catch (IOException e) { fail(); } catch (InterruptedException e) { @@ -731,9 +721,11 @@ public class ITUtilStructureElement { fail(); } - return null; + return updatedStructureElements; } + // ---------------------------------------------------------------------------------------------------- + /** * Utility method to delete a structure element and assert result. * @@ -741,7 +733,23 @@ public class ITUtilStructureElement { * @return deleted structure element */ public static StructureElement assertDelete(StructureElementCommandConfirm structureElementCommand) { - return assertDelete(AuthorizationChoice.NONE, new StructureElementCommandConfirm[] {structureElementCommand})[0]; + StructureElement[] deletedStructureElements = assertDelete(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), HttpURLConnection.HTTP_OK); + return deletedStructureElements != null + ? deletedStructureElements[0] + : null; + } + /** + * Utility method to delete a structure element and assert result and response code. + * + * @param structureElementCommand structure element command + * @param responseCode response code + * @return deleted structure element + */ + public static StructureElement assertDelete(StructureElementCommandConfirm structureElementCommand, int responseCode) { + StructureElement[] deletedStructureElements = assertDelete(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), responseCode); + return deletedStructureElements != null + ? deletedStructureElements[0] + : null; } /** * Utility method to delete structure elements and assert result. @@ -750,39 +758,36 @@ public class ITUtilStructureElement { * @return deleted structure element */ public static StructureElement[] assertDelete(StructureElementCommandConfirm[] structureElementCommands) { - return assertDelete(AuthorizationChoice.NONE, structureElementCommands); + return assertDelete(AuthorizationChoice.NONE, object2Json(structureElementCommands), HttpURLConnection.HTTP_OK); } /** - * Utility method to delete structure elements and assert result. + * Utility method to delete json (structure elements) and assert result and response code. * * @param authorizationChoice authorization choice (none, user, admin) - * @param structureElementCommands structure element commands + * @param json json + * @param responseCode response code * @return deleted structure element */ - public static StructureElement[] assertDelete(AuthorizationChoice authorizationChoice, StructureElementCommandConfirm[] structureElementCommands) { - String path = getValidatePath(StructureCommand.DELETE); + public static StructureElement[] assertDelete(AuthorizationChoice authorizationChoice, String json, int responseCode) { + StructureElement[] deletedStructureElements = null; try { String[] response = null; - StructureElement[] deletedStructureElements = null; - response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.STRUCTURES, path, object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + response = ITUtil.runShellCommand(ITUtil.curlDeletePathJson(authorizationChoice, EndpointChoice.STRUCTURES, "", json)); + ITUtil.assertResponseLength2Code(response, responseCode); - response = ITUtil.runShellCommand(ITUtil.curlDeletePathJson(authorizationChoice, EndpointChoice.STRUCTURES, "", object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - deletedStructureElements = mapper.readValue(response[1], StructureElement[].class); - - for (StructureElement deletedStructureElement : deletedStructureElements) { - assertNotNull(deletedStructureElement.getUuid()); - assertEquals(Status.PENDING, deletedStructureElement.getStatus()); - assertEquals(Boolean.FALSE, deletedStructureElement.isLatest()); - assertEquals(Boolean.TRUE, deletedStructureElement.isDeleted()); - assertNotNull(deletedStructureElement.getWhen()); - } + if (HttpURLConnection.HTTP_OK == responseCode) { + deletedStructureElements = mapper.readValue(response[1], StructureElement[].class); - return deletedStructureElements; + for (StructureElement deletedStructureElement : deletedStructureElements) { + assertNotNull(deletedStructureElement.getUuid()); + assertEquals(Status.PENDING, deletedStructureElement.getStatus()); + assertEquals(Boolean.FALSE, deletedStructureElement.isLatest()); + assertEquals(Boolean.TRUE, deletedStructureElement.isDeleted()); + assertNotNull(deletedStructureElement.getWhen()); + } + } } catch (IOException e) { fail(); } catch (InterruptedException e) { @@ -791,9 +796,11 @@ public class ITUtilStructureElement { fail(); } - return null; + return deletedStructureElements; } + // ---------------------------------------------------------------------------------------------------- + /** * Utility method to approve a structure element and assert result. * @@ -801,7 +808,23 @@ public class ITUtilStructureElement { * @return approved structure element */ public static StructureElement assertApprove(StructureElementCommandConfirm structureElementCommand) { - return assertApprove(AuthorizationChoice.NONE, new StructureElementCommandConfirm[] {structureElementCommand})[0]; + StructureElement[] approvedStructureElements = assertApprove(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), HttpURLConnection.HTTP_OK); + return approvedStructureElements != null + ? approvedStructureElements[0] + : null; + } + /** + * Utility method to approve a structure element and assert result and response code. + * + * @param structureElementCommand structure element command + * @param responseCode response code + * @return approved structure element + */ + public static StructureElement assertApprove(StructureElementCommandConfirm structureElementCommand, int responseCode) { + StructureElement[] approvedStructureElements = assertApprove(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), responseCode); + return approvedStructureElements != null + ? approvedStructureElements[0] + : null; } /** * Utility method to approve structure elements and assert result. @@ -810,39 +833,36 @@ public class ITUtilStructureElement { * @return approved structure element */ public static StructureElement[] assertApprove(StructureElementCommandConfirm[] structureElementCommands) { - return assertApprove(AuthorizationChoice.NONE, structureElementCommands); + return assertApprove(AuthorizationChoice.NONE, object2Json(structureElementCommands), HttpURLConnection.HTTP_OK); } /** - * Utility method to approve structure elements and assert result. + * Utility method to approve json (structure elements) and assert result and response code. * * @param authorizationChoice authorization choice (none, user, admin) - * @param structureElementCommands structure element commands + * @param json json + * @param responseCode response code * @return approved structure element */ - public static StructureElement[] assertApprove(AuthorizationChoice authorizationChoice, StructureElementCommandConfirm[] structureElementCommands) { - String path = getValidatePath(StructureCommand.APPROVE); + public static StructureElement[] assertApprove(AuthorizationChoice authorizationChoice, String json, int responseCode) { + StructureElement[] approvedStructureElements = null; try { String[] response = null; - StructureElement[] approvedStructureElements = null; - response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.STRUCTURES, path, object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + response = ITUtil.runShellCommand(ITUtil.curlPatchPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "/approve", json)); + ITUtil.assertResponseLength2Code(response, responseCode); - response = ITUtil.runShellCommand(ITUtil.curlPatchPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "/approve", object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - approvedStructureElements = mapper.readValue(response[1], StructureElement[].class); - - for (StructureElement approvedStructureElement : approvedStructureElements) { - assertNotNull(approvedStructureElement.getUuid()); - assertEquals(Status.APPROVED, approvedStructureElement.getStatus()); - assertEquals(Boolean.TRUE, approvedStructureElement.isLatest()); - // not known if deleted - assertNotNull(approvedStructureElement.getWhen()); - } + if (HttpURLConnection.HTTP_OK == responseCode) { + approvedStructureElements = mapper.readValue(response[1], StructureElement[].class); - return approvedStructureElements; + for (StructureElement approvedStructureElement : approvedStructureElements) { + assertNotNull(approvedStructureElement.getUuid()); + assertEquals(Status.APPROVED, approvedStructureElement.getStatus()); + assertEquals(Boolean.TRUE, approvedStructureElement.isLatest()); + // not known if deleted + assertNotNull(approvedStructureElement.getWhen()); + } + } } catch (IOException e) { fail(); } catch (InterruptedException e) { @@ -851,9 +871,11 @@ public class ITUtilStructureElement { fail(); } - return null; + return approvedStructureElements; } + // ---------------------------------------------------------------------------------------------------- + /** * Utility method to cancel a structure element and assert result. * @@ -861,7 +883,23 @@ public class ITUtilStructureElement { * @return cancelled structure element */ public static StructureElement assertCancel(StructureElementCommandConfirm structureElementCommand) { - return assertCancel(AuthorizationChoice.NONE, new StructureElementCommandConfirm[] {structureElementCommand})[0]; + StructureElement[] cancelledStructureElements = assertCancel(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), HttpURLConnection.HTTP_OK); + return cancelledStructureElements != null + ? cancelledStructureElements[0] + : null; + } + /** + * Utility method to cancel a structure element and assert result and response code. + * + * @param structureElementCommand structure element command + * @param responseCode response code + * @return cancelled structure element + */ + public static StructureElement assertCancel(StructureElementCommandConfirm structureElementCommand, int responseCode) { + StructureElement[] cancelledStructureElements = assertCancel(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), responseCode); + return cancelledStructureElements != null + ? cancelledStructureElements[0] + : null; } /** * Utility method to cancel structure elements and assert result. @@ -870,39 +908,36 @@ public class ITUtilStructureElement { * @return cancelled structure element */ public static StructureElement[] assertCancel(StructureElementCommandConfirm[] structureElementCommands) { - return assertCancel(AuthorizationChoice.NONE, structureElementCommands); + return assertCancel(AuthorizationChoice.NONE, object2Json(structureElementCommands), HttpURLConnection.HTTP_OK); } /** - * Utility method to cancel structure elements and assert result. + * Utility method to cancel json (structure elements) and assert result and response code. * * @param authorizationChoice authorization choice (none, user, admin) - * @param structureElementCommands structure element commands + * @param json json + * @param responseCode response code * @return cancelled structure element */ - public static StructureElement[] assertCancel(AuthorizationChoice authorizationChoice, StructureElementCommandConfirm[] structureElementCommands) { - String path = getValidatePath(StructureCommand.CANCEL); + public static StructureElement[] assertCancel(AuthorizationChoice authorizationChoice, String json, int responseCode) { + StructureElement[] cancelledStructureElements = null; try { String[] response = null; - StructureElement[] cancelledStructureElements = null; - response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.STRUCTURES, path, object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + response = ITUtil.runShellCommand(ITUtil.curlPatchPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "/cancel", json)); + ITUtil.assertResponseLength2Code(response, responseCode); - response = ITUtil.runShellCommand(ITUtil.curlPatchPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "/cancel", object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - cancelledStructureElements = mapper.readValue(response[1], StructureElement[].class); - - for (StructureElement cancelledStructureElement : cancelledStructureElements) { - assertNotNull(cancelledStructureElement.getUuid()); - assertEquals(Status.CANCELLED, cancelledStructureElement.getStatus()); - assertEquals(Boolean.FALSE, cancelledStructureElement.isLatest()); - // not known if deleted - assertNotNull(cancelledStructureElement.getWhen()); - } + if (HttpURLConnection.HTTP_OK == responseCode) { + cancelledStructureElements = mapper.readValue(response[1], StructureElement[].class); - return cancelledStructureElements; + for (StructureElement cancelledStructureElement : cancelledStructureElements) { + assertNotNull(cancelledStructureElement.getUuid()); + assertEquals(Status.CANCELLED, cancelledStructureElement.getStatus()); + assertEquals(Boolean.FALSE, cancelledStructureElement.isLatest()); + // not known if deleted + assertNotNull(cancelledStructureElement.getWhen()); + } + } } catch (IOException e) { fail(); } catch (InterruptedException e) { @@ -911,9 +946,11 @@ public class ITUtilStructureElement { fail(); } - return null; + return cancelledStructureElements; } + // ---------------------------------------------------------------------------------------------------- + /** * Utility method to reject a structure element and assert result. * @@ -921,7 +958,23 @@ public class ITUtilStructureElement { * @return rejected structure element */ public static StructureElement assertReject(StructureElementCommandConfirm structureElementCommand) { - return assertReject(AuthorizationChoice.NONE, new StructureElementCommandConfirm[] {structureElementCommand})[0]; + StructureElement[] rejectedStructureElements = assertReject(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), HttpURLConnection.HTTP_OK); + return rejectedStructureElements != null + ? rejectedStructureElements[0] + : null; + } + /** + * Utility method to reject a structure element and assert result and response code. + * + * @param structureElementCommand structure element command + * @param responseCode response code + * @return rejected structure element + */ + public static StructureElement assertReject(StructureElementCommandConfirm structureElementCommand, int responseCode) { + StructureElement[] rejectedStructureElements = assertReject(AuthorizationChoice.NONE, object2Json(new StructureElementCommandConfirm[] {structureElementCommand}), responseCode); + return rejectedStructureElements != null + ? rejectedStructureElements[0] + : null; } /** * Utility method to reject structure elements and assert result. @@ -930,39 +983,36 @@ public class ITUtilStructureElement { * @return rejected structure element */ public static StructureElement[] assertReject(StructureElementCommandConfirm[] structureElementCommands) { - return assertReject(AuthorizationChoice.NONE, structureElementCommands); + return assertReject(AuthorizationChoice.NONE, object2Json(structureElementCommands), HttpURLConnection.HTTP_OK); } /** - * Utility method to reject structure elements and assert result. + * Utility method to reject json (structure elements) and assert result and response code. * * @param authorizationChoice authorization choice (none, user, admin) - * @param structureElementCommands structure element commands + * @param json json + * @param responseCode response code * @return rejected structure element */ - public static StructureElement[] assertReject(AuthorizationChoice authorizationChoice, StructureElementCommandConfirm[] structureElementCommands) { - String path = getValidatePath(StructureCommand.REJECT); + public static StructureElement[] assertReject(AuthorizationChoice authorizationChoice, String json, int responseCode) { + StructureElement[] rejectedStructureElements = null; try { String[] response = null; - StructureElement[] rejectedStructureElements = null; - response = ITUtil.runShellCommand(ITUtil.curlGetPathJson(authorizationChoice, EndpointChoice.STRUCTURES, path, object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - ITUtil.assertEqualsResponseBoolean(mapper.readValue(response[1], ResponseBooleanList.class), Boolean.TRUE); + response = ITUtil.runShellCommand(ITUtil.curlPatchPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "/reject", json)); + ITUtil.assertResponseLength2Code(response, responseCode); - response = ITUtil.runShellCommand(ITUtil.curlPatchPathJson(authorizationChoice, EndpointChoice.STRUCTURES, "/reject", object2Json(structureElementCommands))); - ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_OK); - rejectedStructureElements = mapper.readValue(response[1], StructureElement[].class); - - for (StructureElement rejectedStructureElement : rejectedStructureElements) { - assertNotNull(rejectedStructureElement.getUuid()); - assertEquals(Status.REJECTED, rejectedStructureElement.getStatus()); - assertEquals(Boolean.FALSE, rejectedStructureElement.isLatest()); - // not known if deleted - assertNotNull(rejectedStructureElement.getWhen()); - } + if (HttpURLConnection.HTTP_OK == responseCode) { + rejectedStructureElements = mapper.readValue(response[1], StructureElement[].class); - return rejectedStructureElements; + for (StructureElement rejectedStructureElement : rejectedStructureElements) { + assertNotNull(rejectedStructureElement.getUuid()); + assertEquals(Status.REJECTED, rejectedStructureElement.getStatus()); + assertEquals(Boolean.FALSE, rejectedStructureElement.isLatest()); + // not known if deleted + assertNotNull(rejectedStructureElement.getWhen()); + } + } } catch (IOException e) { fail(); } catch (InterruptedException e) { @@ -971,10 +1021,10 @@ public class ITUtilStructureElement { fail(); } - return null; + return rejectedStructureElements; } - // -------------------- + // ---------------------------------------------------------------------------------------------------- /** * Utility method to create, approve a structure element and assert result. diff --git a/src/test/java/org/openepics/names/docker/NamesIT.java b/src/test/java/org/openepics/names/docker/NamesIT.java index 3bf0952d..810c4a48 100644 --- a/src/test/java/org/openepics/names/docker/NamesIT.java +++ b/src/test/java/org/openepics/names/docker/NamesIT.java @@ -70,6 +70,8 @@ class NamesIT { // create - parentSystemStructure, parentDeviceStructure, index, description, comment // update - uuid, parentSystemStructure, parentDeviceStructure, index, description, comment // delete - uuid, comment + // + // response status codes @Container public static final DockerComposeContainer<?> ENVIRONMENT = @@ -338,6 +340,7 @@ class NamesIT { // already exists since create subsystem was approved nameElementCommandCreate.setParentSystemStructure(subsystem010PRL); ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.FALSE); + ITUtilNameElement.assertCreate(nameElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); // ---------- // system structure + device structure + index @@ -371,6 +374,7 @@ class NamesIT { // already exists since create system was approved nameElementCommandCreate.setParentSystemStructure(systemRFQ); ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.FALSE); + ITUtilNameElement.assertCreate(nameElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); // ---------- // system structure + device structure + index @@ -440,14 +444,26 @@ class NamesIT { // already exists since create system was approved nameElementCommandCreate.setParentSystemStructure(systemRFQ); ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.FALSE); + ITUtilNameElement.assertCreate(nameElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); nameElementCommandCreate.setParentDeviceStructure(deviceTypeRFA); ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.FALSE); + ITUtilNameElement.assertCreate(nameElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); nameElementCommandCreate.setIndex("051"); ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.TRUE); - } catch (IOException e) { - fail(); + + // ---------- + // random uuid + + nameElementCommandCreate.setParentSystemStructure(UUID.randomUUID()); + ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.FALSE); + ITUtilNameElement.assertCreate(nameElementCommandCreate, HttpURLConnection.HTTP_NOT_FOUND); + + nameElementCommandCreate.setParentSystemStructure(systemRFQ); + nameElementCommandCreate.setParentDeviceStructure(UUID.randomUUID()); + ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.FALSE); + ITUtilNameElement.assertCreate(nameElementCommandCreate, HttpURLConnection.HTTP_NOT_FOUND); } catch (Exception e) { fail(); } @@ -487,7 +503,7 @@ class NamesIT { ITUtilNameElement.assertIsValidToCreate("RFQ-010PRL:EMR-RFA-052", Boolean.TRUE); ITUtilNameElement.assertValidate( - "[" + mapper.writeValueAsString(nameElementCommandCreate) + ","+mapper.writeValueAsString(nameElementCommandCreate2) +"]", + "[" + mapper.writeValueAsString(nameElementCommandCreate) + "," + mapper.writeValueAsString(nameElementCommandCreate2) + "]", NameCommand.CREATE, HttpURLConnection.HTTP_OK, Boolean.TRUE, Boolean.TRUE); ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.TRUE); @@ -501,6 +517,7 @@ class NamesIT { ITUtilNameElement.assertIsValidToCreate("RFQ-010PRL:EMR-RFA-052", Boolean.FALSE); ITUtilNameElement.assertValidate(nameElementCommandCreate, NameCommand.CREATE, Boolean.FALSE); + ITUtilNameElement.assertCreate(nameElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); } catch (IOException e) { fail(); } catch (Exception e) { @@ -548,18 +565,21 @@ class NamesIT { nameElementCommandUpdate.setUuid(null); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); nameElementCommandUpdate.setUuid(createdNameElement.getUuid()); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.TRUE); nameElementCommandUpdate.setDescription(null); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); nameElementCommandUpdate.setDescription("checkUpdate"); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.TRUE); nameElementCommandUpdate.setComment(null); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); nameElementCommandUpdate.setComment("checkUpdate"); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.TRUE); @@ -568,18 +588,21 @@ class NamesIT { nameElementCommandUpdate.setParentSystemStructure(null); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); nameElementCommandUpdate.setParentSystemStructure(systemGroupAcc); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.TRUE); nameElementCommandUpdate.setParentSystemStructure(null); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); nameElementCommandUpdate.setParentSystemStructure(systemRFQ); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.TRUE); nameElementCommandUpdate.setParentSystemStructure(null); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); // subsystemN1U1 used in isLegacyName but not here // order of tests not guaranteed @@ -591,17 +614,21 @@ class NamesIT { nameElementCommandUpdate.setParentDeviceStructure(null); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); // convention name exists // already exists since create subsystem was approved nameElementCommandUpdate.setIndex(null); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); nameElementCommandUpdate.setIndex("053"); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); nameElementCommandUpdate.setParentDeviceStructure(deviceGroupEMR); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); nameElementCommandUpdate.setParentDeviceStructure(deviceTypeFS); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.TRUE); @@ -614,11 +641,29 @@ class NamesIT { nameElementCommandUpdate.setIndex(null); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); nameElementCommandUpdate.setIndex("053"); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.TRUE); // system structure, device structure not used for validation + + // ---------- + // random uuid + + nameElementCommandUpdate.setUuid(UUID.randomUUID()); + ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); + nameElementCommandUpdate.setUuid(createdNameElement.getUuid()); + + nameElementCommandUpdate.setParentSystemStructure(UUID.randomUUID()); + ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); + nameElementCommandUpdate.setParentSystemStructure(subsystem010PRL); + + nameElementCommandUpdate.setParentDeviceStructure(UUID.randomUUID()); + ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); } catch (Exception e) { fail(); } @@ -654,6 +699,11 @@ class NamesIT { // create createdNameElement = ITUtilNameElement.assertCreate(nameElementCommandCreate); + + // status code + nameElementCommandUpdate.setUuid(UUID.randomUUID()); + ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.FALSE); + ITUtilNameElement.assertUpdate(nameElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); nameElementCommandUpdate.setUuid(createdNameElement.getUuid()); ITUtilNameElement.assertValidate(nameElementCommandUpdate, NameCommand.UPDATE, Boolean.TRUE); @@ -711,12 +761,18 @@ class NamesIT { nameElementCommandConfirm.setUuid(null); ITUtilNameElement.assertValidate(nameElementCommandConfirm, NameCommand.DELETE, Boolean.FALSE); + ITUtilNameElement.assertDelete(nameElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + nameElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilNameElement.assertValidate(nameElementCommandConfirm, NameCommand.DELETE, Boolean.FALSE); + ITUtilNameElement.assertDelete(nameElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); nameElementCommandConfirm.setUuid(createdNameElement.getUuid()); ITUtilNameElement.assertValidate(nameElementCommandConfirm, NameCommand.DELETE, Boolean.TRUE); nameElementCommandConfirm.setComment(null); ITUtilNameElement.assertValidate(nameElementCommandConfirm, NameCommand.DELETE, Boolean.FALSE); + ITUtilNameElement.assertDelete(nameElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); nameElementCommandConfirm.setComment("checkDelete"); ITUtilNameElement.assertValidate(nameElementCommandConfirm, NameCommand.DELETE, Boolean.TRUE); @@ -764,6 +820,7 @@ class NamesIT { ITUtilNameElement.assertDelete(nameElementCommandConfirm); ITUtilNameElement.assertValidate(nameElementCommandConfirm, NameCommand.DELETE, Boolean.FALSE); + ITUtilNameElement.assertDelete(nameElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); } catch (Exception e) { fail(); } diff --git a/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java b/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java index 661c6761..ee720aaf 100644 --- a/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresDeviceGroupIT.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import java.io.IOException; import java.net.HttpURLConnection; import java.util.UUID; @@ -84,6 +83,8 @@ class StructuresDeviceGroupIT { // approve - uuid, type, comment // cancel - uuid, type, comment // reject - uuid, type, comment + // + // response status codes @Container public static final DockerComposeContainer<?> ENVIRONMENT = @@ -180,12 +181,12 @@ class StructuresDeviceGroupIT { structureElementCommandCreate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setType(Type.DEVICEGROUP); structureElementCommandCreate.setMnemonic("Cc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); - } catch (IOException e) { - fail(); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -221,83 +222,109 @@ class StructuresDeviceGroupIT { structureElementCommandCreate.setMnemonic("C"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Cc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Ccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Cccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Ccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Cccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Ccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Cccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Ccccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); // mnemonic rules (2) structureElementCommandCreate.setMnemonic(" "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Grp "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Grp"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("000"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Grp0"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic(":"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Grp:"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Grp: "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("1"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("12"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("123"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("1234"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("12345"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("123456"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("1234567"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("12345678"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("123456789"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -332,7 +359,6 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICEGROUP, "Di", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); @@ -343,9 +369,9 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICEGROUP, "Di", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -355,9 +381,15 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICEGROUP, "Di", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(createdStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -392,7 +424,6 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICEGROUP, "Di", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); @@ -403,9 +434,9 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICEGROUP, "Di", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -415,9 +446,15 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICEGROUP, "Di", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -452,7 +489,6 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICEGROUP, "Di", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); @@ -463,9 +499,9 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICEGROUP, "Di", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -475,9 +511,15 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertExists(Type.DEVICEGROUP, "Di", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICEGROUP, "Di", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -530,45 +572,57 @@ class StructuresDeviceGroupIT { structureElementCommandUpdate.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandUpdate.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setType(Type.SYSTEM); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setType(Type.DEVICEGROUP); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setParent(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setParent(disciplineUuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setName(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setName("name"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setMnemonic("Cu"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setMnemonic(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setDescription(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setDescription("description"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); @@ -618,12 +672,20 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -672,12 +734,20 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -726,12 +796,20 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -780,18 +858,29 @@ class StructuresDeviceGroupIT { structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setType(Type.SYSTEM); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setType(Type.DEVICEGROUP); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandConfirm.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); @@ -839,12 +928,20 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -891,12 +988,20 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -943,12 +1048,20 @@ class StructuresDeviceGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } diff --git a/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java b/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java index 59cb99d5..602a9a80 100644 --- a/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresDeviceTypeIT.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import java.io.IOException; import java.net.HttpURLConnection; import java.util.UUID; @@ -84,6 +83,8 @@ class StructuresDeviceTypeIT { // approve - uuid, type, comment // cancel - uuid, type, comment // reject - uuid, type, comment + // + // response status codes @Container public static final DockerComposeContainer<?> ENVIRONMENT = @@ -196,8 +197,7 @@ class StructuresDeviceTypeIT { structureElementCommandCreate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); - } catch (IOException e) { - fail(); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -227,9 +227,11 @@ class StructuresDeviceTypeIT { structureElementCommandCreate.setMnemonic(null); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic(""); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("C"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -251,20 +253,25 @@ class StructuresDeviceTypeIT { structureElementCommandCreate.setMnemonic("Ccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Cccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Ccccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); // mnemonic rules (2) structureElementCommandCreate.setMnemonic(" "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Dev "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Dev"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -277,12 +284,15 @@ class StructuresDeviceTypeIT { structureElementCommandCreate.setMnemonic(":"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Dev:"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Dev: "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("1"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -304,12 +314,15 @@ class StructuresDeviceTypeIT { structureElementCommandCreate.setMnemonic("1234567"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("12345678"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("123456789"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -344,7 +357,6 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICETYPE, "Di-Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); @@ -354,18 +366,24 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICETYPE, "Di-Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-Ca", Boolean.TRUE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICETYPE, "Di-Ca", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(createdStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -400,7 +418,6 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICETYPE, "Di-Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); @@ -411,9 +428,10 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICETYPE, "Di-Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -423,9 +441,15 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICETYPE, "Di-Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -460,7 +484,6 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICETYPE, "Di-Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); @@ -471,9 +494,10 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICETYPE, "Di-Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -483,9 +507,15 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertExists(Type.DEVICETYPE, "Di-Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DEVICETYPE, "Di-Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -538,45 +568,57 @@ class StructuresDeviceTypeIT { structureElementCommandUpdate.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandUpdate.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setType(Type.SUBSYSTEM); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setType(Type.DEVICETYPE); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setParent(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setParent(deviceGroupUuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setName(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setName("name"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setMnemonic(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setMnemonic("Cu"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setDescription(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setDescription("description"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); @@ -626,12 +668,20 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -680,12 +730,20 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -734,12 +792,20 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -788,18 +854,29 @@ class StructuresDeviceTypeIT { structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setType(Type.SUBSYSTEM); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setType(Type.DEVICETYPE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandConfirm.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); @@ -847,12 +924,20 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -899,12 +984,27 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -951,6 +1051,7 @@ class StructuresDeviceTypeIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); diff --git a/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java b/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java index cf4b64f3..c4d96269 100644 --- a/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresDisciplineIT.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import java.io.IOException; import java.net.HttpURLConnection; import java.util.UUID; @@ -83,6 +82,8 @@ class StructuresDisciplineIT { // approve - uuid, type, comment // cancel - uuid, type, comment // reject - uuid, type, comment + // + // response status codes @Container public static final DockerComposeContainer<?> ENVIRONMENT = @@ -153,8 +154,7 @@ class StructuresDisciplineIT { structureElementCommandCreate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); - } catch (IOException e) { - fail(); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -300,7 +300,6 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertExists(Type.DISCIPLINE, "Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DISCIPLINE, "Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); @@ -310,18 +309,24 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertExists(Type.DISCIPLINE, "Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DISCIPLINE, "Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertExists(Type.DISCIPLINE, "Ca", Boolean.TRUE); ITUtilStructureElement.assertIsValidToCreate(Type.DISCIPLINE, "Ca", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(createdStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -356,7 +361,6 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertExists(Type.DISCIPLINE, "Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DISCIPLINE, "Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); @@ -367,9 +371,10 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertExists(Type.DISCIPLINE, "Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DISCIPLINE, "Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -379,9 +384,15 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertExists(Type.DISCIPLINE, "Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DISCIPLINE, "Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -416,7 +427,6 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertExists(Type.DISCIPLINE, "Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DISCIPLINE, "Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); @@ -427,9 +437,10 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertExists(Type.DISCIPLINE, "Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DISCIPLINE, "Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -439,9 +450,15 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertExists(Type.DISCIPLINE, "Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.DISCIPLINE, "Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -493,39 +510,50 @@ class StructuresDisciplineIT { structureElementCommandUpdate.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandUpdate.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setType(Type.SYSTEMGROUP); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setType(Type.DISCIPLINE); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setName(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setName("name"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setMnemonic(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setMnemonic("Cu"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setDescription(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setDescription("description"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); @@ -575,12 +603,20 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -629,12 +665,20 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -683,12 +727,20 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -737,18 +789,29 @@ class StructuresDisciplineIT { structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setType(Type.SYSTEMGROUP); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setType(Type.DISCIPLINE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandConfirm.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); @@ -796,12 +859,20 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -848,12 +919,20 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -900,12 +979,20 @@ class StructuresDisciplineIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } diff --git a/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java b/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java index e973b42c..503718a2 100644 --- a/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresSubsystemIT.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import java.io.IOException; import java.net.HttpURLConnection; import java.util.UUID; @@ -84,6 +83,8 @@ class StructuresSubsystemIT { // approve - uuid, type, comment // cancel - uuid, type, comment // reject - uuid, type, comment + // + // response status codes @Container public static final DockerComposeContainer<?> ENVIRONMENT = @@ -198,8 +199,7 @@ class StructuresSubsystemIT { structureElementCommandCreate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); - } catch (IOException e) { - fail(); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -229,9 +229,11 @@ class StructuresSubsystemIT { structureElementCommandCreate.setMnemonic(null); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic(""); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("C"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -259,14 +261,17 @@ class StructuresSubsystemIT { structureElementCommandCreate.setMnemonic("Ccccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); // mnemonic rules (2) structureElementCommandCreate.setMnemonic(" "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sub "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sub"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -279,12 +284,15 @@ class StructuresSubsystemIT { structureElementCommandCreate.setMnemonic(":"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sub:"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sub: "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("1"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -312,6 +320,7 @@ class StructuresSubsystemIT { structureElementCommandCreate.setMnemonic("123456789"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -346,7 +355,6 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SUBSYSTEM, "Sys-Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); @@ -356,18 +364,24 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SUBSYSTEM, "Sys-Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-Ca", Boolean.TRUE); ITUtilStructureElement.assertIsValidToCreate(Type.SUBSYSTEM, "Sys-Ca", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(createdStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -402,7 +416,6 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SUBSYSTEM, "Sys-Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); @@ -413,9 +426,10 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SUBSYSTEM, "Sys-Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -425,9 +439,15 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SUBSYSTEM, "Sys-Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -462,7 +482,6 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SUBSYSTEM, "Sys-Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); @@ -473,9 +492,10 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SUBSYSTEM, "Sys-Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -485,9 +505,15 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertExists(Type.SUBSYSTEM, "Sys-Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SUBSYSTEM, "Sys-Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -540,45 +566,57 @@ class StructuresSubsystemIT { structureElementCommandUpdate.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandUpdate.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setType(Type.DEVICETYPE); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setType(Type.SUBSYSTEM); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setParent(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setParent(systemUuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setName(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setName("name"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setMnemonic(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setMnemonic("Cu"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setDescription(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setDescription("description"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); @@ -628,12 +666,20 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -682,12 +728,20 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -736,12 +790,20 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -790,18 +852,29 @@ class StructuresSubsystemIT { structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setType(Type.DEVICETYPE); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setType(Type.SUBSYSTEM); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandConfirm.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); @@ -849,12 +922,20 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -901,12 +982,20 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -953,12 +1042,20 @@ class StructuresSubsystemIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } diff --git a/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java b/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java index ac7b78f0..fa664190 100644 --- a/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresSystemGroupIT.java @@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import java.io.IOException; import java.net.HttpURLConnection; import java.util.UUID; @@ -165,8 +164,7 @@ class StructuresSystemGroupIT { structureElementCommandCreate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); - } catch (IOException e) { - fail(); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -219,20 +217,25 @@ class StructuresSystemGroupIT { structureElementCommandCreate.setMnemonic("Ccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Cccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Ccccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); // mnemonic rules (2) structureElementCommandCreate.setMnemonic(" "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sys "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sys"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -245,12 +248,15 @@ class StructuresSystemGroupIT { structureElementCommandCreate.setMnemonic(":"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sys:"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sys: "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("1"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -272,12 +278,15 @@ class StructuresSystemGroupIT { structureElementCommandCreate.setMnemonic("1234567"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("12345678"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("123456789"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Ac1"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -320,7 +329,6 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEMGROUP, "Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); @@ -331,19 +339,25 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEMGROUP, "Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "Ca", Boolean.TRUE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEMGROUP, "Ca", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); + // create structureElementCommandCreate = new StructureElementCommandCreate( Type.SYSTEMGROUP, null, @@ -397,7 +411,6 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEMGROUP, "Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); @@ -408,9 +421,10 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEMGROUP, "Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -430,9 +444,15 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEMGROUP, "Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -467,7 +487,6 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEMGROUP, "Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); @@ -478,9 +497,10 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEMGROUP, "Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -490,9 +510,15 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertExists(Type.SYSTEMGROUP, "Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEMGROUP, "Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -544,21 +570,29 @@ class StructuresSystemGroupIT { structureElementCommandUpdate.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandUpdate.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setType(Type.DISCIPLINE); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setType(Type.SYSTEMGROUP); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setName(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setName("name"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); @@ -571,12 +605,14 @@ class StructuresSystemGroupIT { structureElementCommandUpdate.setDescription(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setDescription("description"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); @@ -627,12 +663,20 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -682,12 +726,20 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -737,12 +789,20 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -791,18 +851,29 @@ class StructuresSystemGroupIT { structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setType(Type.DISCIPLINE); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setType(Type.SYSTEMGROUP); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandConfirm.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); @@ -850,12 +921,20 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -902,12 +981,20 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -954,12 +1041,20 @@ class StructuresSystemGroupIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } diff --git a/src/test/java/org/openepics/names/docker/StructuresSystemIT.java b/src/test/java/org/openepics/names/docker/StructuresSystemIT.java index 6ee4db77..2930268a 100644 --- a/src/test/java/org/openepics/names/docker/StructuresSystemIT.java +++ b/src/test/java/org/openepics/names/docker/StructuresSystemIT.java @@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import java.io.IOException; import java.net.HttpURLConnection; import java.util.UUID; @@ -84,6 +83,8 @@ class StructuresSystemIT { // approve - uuid, type, comment // cancel - uuid, type, comment // reject - uuid, type, comment + // + // response status codes @Container public static final DockerComposeContainer<?> ENVIRONMENT = @@ -182,8 +183,7 @@ class StructuresSystemIT { structureElementCommandCreate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); - } catch (IOException e) { - fail(); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -213,8 +213,10 @@ class StructuresSystemIT { structureElementCommandCreate.setMnemonic(null); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("C"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -242,14 +244,17 @@ class StructuresSystemIT { structureElementCommandCreate.setMnemonic("Ccccccccc"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); // mnemonic rules (2) structureElementCommandCreate.setMnemonic(" "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sys "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sys"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -262,12 +267,15 @@ class StructuresSystemIT { structureElementCommandCreate.setMnemonic(":"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sys:"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("Sys: "); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandCreate.setMnemonic("1"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); @@ -295,6 +303,7 @@ class StructuresSystemIT { structureElementCommandCreate.setMnemonic("123456789"); ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); } catch (Exception e) { fail(); } @@ -329,7 +338,6 @@ class StructuresSystemIT { ITUtilStructureElement.assertExists(Type.SYSTEM, "Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEM, "Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); @@ -339,18 +347,24 @@ class StructuresSystemIT { ITUtilStructureElement.assertExists(Type.SYSTEM, "Ca", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEM, "Ca", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertExists(Type.SYSTEM, "Ca", Boolean.TRUE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEM, "Ca", Boolean.FALSE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(createdStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -385,7 +399,6 @@ class StructuresSystemIT { ITUtilStructureElement.assertExists(Type.SYSTEM, "Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEM, "Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); @@ -396,9 +409,10 @@ class StructuresSystemIT { ITUtilStructureElement.assertExists(Type.SYSTEM, "Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEM, "Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -408,9 +422,15 @@ class StructuresSystemIT { ITUtilStructureElement.assertExists(Type.SYSTEM, "Cc", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEM, "Cc", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -445,7 +465,6 @@ class StructuresSystemIT { ITUtilStructureElement.assertExists(Type.SYSTEM, "Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEM, "Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); @@ -456,9 +475,10 @@ class StructuresSystemIT { ITUtilStructureElement.assertExists(Type.SYSTEM, "Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEM, "Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertCreate(structureElementCommandCreate, HttpURLConnection.HTTP_CONFLICT); + structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); structureElementCommandConfirm.setUuid(uuid); @@ -468,9 +488,15 @@ class StructuresSystemIT { ITUtilStructureElement.assertExists(Type.SYSTEM, "Cr", Boolean.FALSE); ITUtilStructureElement.assertIsValidToCreate(Type.SYSTEM, "Cr", Boolean.TRUE); - ITUtilStructureElement.assertValidate(structureElementCommandCreate, StructureCommand.CREATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(uuid); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -523,45 +549,57 @@ class StructuresSystemIT { structureElementCommandUpdate.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandUpdate.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandUpdate.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setType(Type.DEVICEGROUP); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setType(Type.SYSTEM); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setParent(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setParent(systemGroupUuid); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setName(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setName("name"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setMnemonic(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setMnemonic("Cu"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setDescription(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setDescription("description"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); structureElementCommandUpdate.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandUpdate.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); @@ -611,12 +649,20 @@ class StructuresSystemIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -665,12 +711,20 @@ class StructuresSystemIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -719,12 +773,20 @@ class StructuresSystemIT { ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertUpdate(structureElementCommandUpdate, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandUpdate, StructureCommand.UPDATE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -773,18 +835,29 @@ class StructuresSystemIT { structureElementCommandConfirm.setUuid(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setUuid(uuid); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setType(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + + structureElementCommandConfirm.setType(Type.DEVICEGROUP); + ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.UPDATE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); structureElementCommandConfirm.setType(Type.SYSTEM); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); structureElementCommandConfirm.setComment(null); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); structureElementCommandConfirm.setComment("comment"); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); @@ -832,12 +905,20 @@ class StructuresSystemIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // approve ITUtilStructureElement.assertApprove(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.APPROVE, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertApprove(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -884,12 +965,20 @@ class StructuresSystemIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // cancel ITUtilStructureElement.assertCancel(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.CANCEL, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertCancel(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } @@ -936,12 +1025,20 @@ class StructuresSystemIT { ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.FALSE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.TRUE); + ITUtilStructureElement.assertDelete(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); // reject ITUtilStructureElement.assertReject(structureElementCommandConfirm); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.DELETE, Boolean.TRUE); ITUtilStructureElement.assertValidate(structureElementCommandConfirm, StructureCommand.REJECT, Boolean.FALSE); + + structureElementCommandConfirm.setUuid(null); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, ITUtil.HTTP_UNPROCESSABLE_ENTITY); + structureElementCommandConfirm.setUuid(UUID.randomUUID()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_NOT_FOUND); + structureElementCommandConfirm.setUuid(approvedStructureElement.getUuid()); + ITUtilStructureElement.assertReject(structureElementCommandConfirm, HttpURLConnection.HTTP_CONFLICT); } catch (Exception e) { fail(); } -- GitLab