diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/test/java/org/wso2/carbon/device/application/mgt/store/api/services/CommentManagementAPITest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/test/java/org/wso2/carbon/device/application/mgt/store/api/services/CommentManagementAPITest.java index 8e8d6db1db9..877c7a387fa 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/test/java/org/wso2/carbon/device/application/mgt/store/api/services/CommentManagementAPITest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/test/java/org/wso2/carbon/device/application/mgt/store/api/services/CommentManagementAPITest.java @@ -81,7 +81,7 @@ public class CommentManagementAPITest { public void testAddComments() throws Exception { Comment comment = CommentMgtTestHelper.getDummyComment("a", "a"); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); - Response response = this.commentManagementAPI.addComments(comment, null); + Response response = this.commentManagementAPI.addComments(comment, "a"); Assert.assertNotNull(response, "The response object is null."); Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), "The response status should be 201."); @@ -98,6 +98,19 @@ public class CommentManagementAPITest { Mockito.reset(commentsManager); } + @Test + public void testAddCommentsInternalError() throws Exception { + Comment comment = CommentMgtTestHelper.getDummyComment("a", "a"); + PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); + Mockito.when(this.commentManagementAPI.addComments(Mockito.any(), Mockito.anyString())) + .thenThrow(new CommentManagementException()); + Response response = this.commentManagementAPI.addComments(comment, null); + Assert.assertNotNull(response, "The response object is null."); + Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), + "The response status should be 500."); + Mockito.reset(commentsManager); + } + @Test public void testUpdateComment() throws Exception { Comment comment = CommentMgtTestHelper.getDummyComment("a", "a"); @@ -127,6 +140,25 @@ public class CommentManagementAPITest { "The response status should be 404."); } + @Test + public void testDeleteComment() throws Exception { + PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); + Response response = this.commentManagementAPI.deleteComment(1); + Assert.assertNotNull(response, "The response object is null."); + Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), + "The response status should be 200."); + } + + @Test + public void testDeleteCommentInternalError() throws Exception { + PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); + Mockito.when(this.commentManagementAPI.deleteComment(Mockito.anyInt())).thenThrow(new CommentManagementException()); + Response response = this.commentManagementAPI.deleteComment(1); + Assert.assertNotNull(response, "The response object is null."); + Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), + "The response status should be 500."); + } + @Test public void testGetStars() throws Exception { PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); @@ -158,7 +190,7 @@ public class CommentManagementAPITest { } @Test - public void testUpdateInvalideStars() throws Exception { + public void testUpdateInvalidStars() throws Exception { PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); Response response = this.commentManagementAPI.updateStars(0, "a"); Assert.assertNotNull(response, "The response object is null.");