Improve test coverage 50/119650/4
authorvasraz <vasyl.razinkov@est.tech>
Tue, 23 Mar 2021 17:19:24 +0000 (17:19 +0000)
committerChristophe Closset <christophe.closset@intl.att.com>
Wed, 24 Mar 2021 12:37:26 +0000 (12:37 +0000)
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I0ab217e32798f48a4d4463a90dd008a9fbcf64d3
Issue-ID: SDC-3428

openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionErrorConstants.java
openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionException.java
openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionMapper.java
openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/main/java/org/openecomp/sdc/action/errors/ActionExceptionResponse.java
openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-api/src/test/java/org/openecomp/sdc/action/errors/ActionExceptionMapperTest.java [new file with mode: 0644]

index 1acfe15..adabf9c 100644 (file)
@@ -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.";
 }
index e702737..ceb9aed 100644 (file)
  */
 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;
-    }
 }
index ec83fef..d6970a6 100644 (file)
@@ -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
index 1b9e811..28aa540 100644 (file)
  */
 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 (file)
index 0000000..0c701b1
--- /dev/null
@@ -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());
+
+    }
+
+}