diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-03-23 17:19:24 +0000 |
---|---|---|
committer | Christophe Closset <christophe.closset@intl.att.com> | 2021-03-24 12:37:26 +0000 |
commit | 8a42713718e46751938a63ccdca4d16244416dd8 (patch) | |
tree | 980159a364ad4a43e07378837bb942766eee6812 /openecomp-be/lib/openecomp-sdc-action-lib | |
parent | 3338ccfb38a060b7f2e0036c1b31e24eaa31756c (diff) |
Improve test coverage
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I0ab217e32798f48a4d4463a90dd008a9fbcf64d3
Issue-ID: SDC-3428
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-action-lib')
5 files changed, 70 insertions, 73 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionErrorConstants.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionErrorConstants.java index 1acfe15dff..adabf9c896 100644 --- a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionErrorConstants.java +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionErrorConstants.java @@ -81,8 +81,7 @@ public class ActionErrorConstants { public static final String ACTION_ARTIFACT_ENTITY_NOT_EXIST = "Specified artifact is not found"; public static final String ACTION_REQUEST_ARTIFACT_CHECKSUM_ERROR = "Checksum error"; public static final String ACTION_REQUEST_ARTIFACT_INVALID_PROTECTION_VALUE = "Invalid artifact protection value"; - public static final String ACTION_ARTIFACT_INVALID_NAME = - "Artifact name cannot contain any of the following characters : #<>$+%!`&*'|{}?=/:@ including" + " whitespaces, double quotes and back-slash"; + public static final String ACTION_ARTIFACT_INVALID_NAME = "Artifact name cannot contain any of the following characters : #<>$+%!`&*'|{}?=/:@ including whitespaces, double quotes and back-slash"; public static final String ACTION_ARTIFACT_READ_FILE_ERROR = "Error Occurred while reading file"; public static final String ACTION_REQUEST_ARTIFACT_OPERATION_ALLOWED = "Artifacts cannot be created/updated using this operation"; public static final String ACTION_ARTIFACT_TOO_BIG_ERROR = "Operation is not allowed. Artifact size exceeds the maximum file size limit (20MB)."; @@ -94,15 +93,12 @@ public class ActionErrorConstants { public static final String ACTION_UNSUPPORTED_OPERATION = "Operation %s not supported"; public static final String ACTION_ENTITY_UNIQUE_VALUE_MSG = "%s with the value '%s' already exists."; public static final String ACTION_ARTIFACT_ALREADY_EXISTS = "Artifact name already exists for Action with id %s. Please use another name."; - public static final String ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG = - "The request failed due to an internal ASDC problem. Open ECOMP Component should continue the " - + "attempts, with corrected data if required, to create the resource."; + public static final String ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG = "The request failed due to an internal ASDC problem. Open ECOMP Component should continue the attempts, with corrected data if required, to create the resource."; public static final String ACTION_ARTIFACT_DELETE_READ_ONLY_MSG = "Cannot delete read only artifact."; public static final String ACTION_ARTIFACT_UPDATE_READ_ONLY_MSG = "Cannot update read only artifact."; public static final String ACTION_NOT_LOCKED_MSG = "Operation is not allowed. Action status should be Locked."; public static final String ACTION_ARTIFACT_UPDATE_NAME_INVALID = "Artifact name cannot be updated."; public static final String ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER = "Cannot delete artifact since it is locked by other user %s."; public static final String UNDO_CHECKOUT_ON_UNLOCKED_ENTITY_MSG = "Can not undo checkout on versionable entity %s with id %s since it is not checked out."; - public static final String UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER_MSG = - "Can not undo checkout on versionable entity %s with id %s since it is checked out by other " + "user: %s."; + public static final String UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER_MSG = "Can not undo checkout on versionable entity %s with id %s since it is checked out by other user: %s."; } diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionException.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionException.java index e702737753..ceb9aed962 100644 --- a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionException.java +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionException.java @@ -19,20 +19,23 @@ */ package org.openecomp.sdc.action.errors; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import org.openecomp.sdc.action.util.ActionUtil; /** * Custom Exception class for handling Action Library error scenarios. */ +@Getter +@Setter +@NoArgsConstructor public class ActionException extends RuntimeException { private String errorCode; private String description; private int logResponseCode; - public ActionException() { - } - /** * Instantiates a new Action exception. * @@ -45,27 +48,4 @@ public class ActionException extends RuntimeException { this.logResponseCode = ActionUtil.getLogResponseCode(this.errorCode); } - public String getErrorCode() { - return errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public int getLogResponseCode() { - return logResponseCode; - } - - public void setLogResponseCode(int logResponseCode) { - this.logResponseCode = logResponseCode; - } } diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionMapper.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionMapper.java index ec83fef0e1..d6970a6615 100644 --- a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionMapper.java +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionMapper.java @@ -62,10 +62,12 @@ import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_UPDATE import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; +import lombok.NoArgsConstructor; /** * Mapper class to map Action Library exceptions to corresponding HTTP Response objects. */ +@NoArgsConstructor public class ActionExceptionMapper implements ExceptionMapper<ActionException> { @Override diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionResponse.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionResponse.java index 1b9e811bbf..28aa540a1b 100644 --- a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionResponse.java +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionResponse.java @@ -19,46 +19,12 @@ */ package org.openecomp.sdc.action.errors; -public class ActionExceptionResponse { - - private String code; - private String description; - private String message; - - /** - * Instantiates a new Action exception response. - * - * @param code the code - * @param description the description - * @param message the message - */ - public ActionExceptionResponse(String code, String description, String message) { - this.code = code; - this.description = description; - this.message = message; - } - - public String getCode() { - return code; - } +import lombok.AllArgsConstructor; - public void setCode(String code) { - this.code = code; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getMessage() { - return message; - } +@AllArgsConstructor +public class ActionExceptionResponse { - public void setMessage(String message) { - this.message = message; - } + private final String code; + private final String description; + private final String message; } diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/test/java/org/openecomp/sdc/action/errors/ActionExceptionMapperTest.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/test/java/org/openecomp/sdc/action/errors/ActionExceptionMapperTest.java new file mode 100644 index 0000000000..0c701b1d31 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/test/java/org/openecomp/sdc/action/errors/ActionExceptionMapperTest.java @@ -0,0 +1,53 @@ +package org.openecomp.sdc.action.errors; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_UPDATE_READ_ONLY; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_AUTHENTICATION_ERR_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_NOT_LOCKED_CODE; + +import javax.ws.rs.core.Response; +import org.junit.jupiter.api.Test; + +class ActionExceptionMapperTest { + + private ActionExceptionMapper createTestSubject() { + return new ActionExceptionMapper(); + } + + @Test + void toResponse_test() { + final ActionExceptionMapper testSubject = createTestSubject(); + ActionException actionException; + Response response; + + actionException = new ActionException(ACTION_NOT_LOCKED_CODE, "ACT1021"); + response = testSubject.toResponse(actionException); + assertNotNull(response); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + + actionException = new ActionException(ACTION_AUTHENTICATION_ERR_CODE, "ACT1000"); + response = testSubject.toResponse(actionException); + assertNotNull(response); + assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), response.getStatus()); + + actionException = new ActionException(ACTION_ARTIFACT_UPDATE_READ_ONLY, "ACT1026"); + response = testSubject.toResponse(actionException); + assertNotNull(response); + assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus()); + + actionException = new ActionException(ACTION_ARTIFACT_ENTITY_NOT_EXIST_CODE, "ACT1046"); + response = testSubject.toResponse(actionException); + assertNotNull(response); + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + + actionException = new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, "ACT1060"); + response = testSubject.toResponse(actionException); + assertNotNull(response); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); + + } + +} |