From 55a005e9921868ce3027a845a431882cfb2f7db7 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 27 Feb 2018 15:36:27 +0530 Subject: [PATCH] Add new methods Exception handling test methods for rating methods --- .../services/CommentManagementAPITest.java | 54 +++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) 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 877c7a387fa..42ccb831498 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 @@ -31,22 +31,25 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.ObjectFactory; import org.testng.annotations.Test; import org.wso2.carbon.device.application.mgt.common.Comment; +import org.wso2.carbon.device.application.mgt.common.PaginationRequest; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException; import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; import org.wso2.carbon.device.application.mgt.store.api.APIUtil; import org.wso2.carbon.device.application.mgt.store.api.services.impl.CommentManagementAPIImpl; import org.wso2.carbon.device.application.mgt.store.api.services.util.CommentMgtTestHelper; -import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import javax.ws.rs.core.Response; +import java.util.List; + import static org.mockito.MockitoAnnotations.initMocks; @PowerMockIgnore("javax.ws.rs.*") @SuppressStaticInitializationFor({ "org.wso2.carbon.device.application.mgt.api.APIUtil" }) @PrepareForTest({ APIUtil.class, CommentsManager.class, - CommentManagementAPITest.class, MultitenantUtils.class }) + CommentManagementAPITest.class}) public class CommentManagementAPITest { private static final Log log = LogFactory.getLog(CommentManagementAPI.class); @@ -152,7 +155,8 @@ public class CommentManagementAPITest { @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()); + 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(), @@ -169,6 +173,28 @@ public class CommentManagementAPITest { Mockito.reset(commentsManager); } + @Test + public void testGetStarsCommentError() throws Exception { + PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); + Mockito.when(this.commentManagementAPI.getStars(Mockito.anyString())).thenThrow(new CommentManagementException()); + Response response = this.commentManagementAPI.getStars("a"); + 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 testGetStarsApplicationError() throws Exception { + PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); + Mockito.when(this.commentManagementAPI.getStars(Mockito.anyString())).thenThrow(new ApplicationManagementException()); + Response response = this.commentManagementAPI.getStars("a"); + 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 testGetRatedUser() throws Exception { PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); @@ -179,6 +205,28 @@ public class CommentManagementAPITest { Mockito.reset(commentsManager); } + @Test + public void testGetRatedUserCommentError() throws Exception { + PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); + Mockito.when(this.commentManagementAPI.getRatedUser(Mockito.anyString())).thenThrow(new CommentManagementException()); + Response response = this.commentManagementAPI.getRatedUser("a"); + 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 testGetRatedUserApplicationError() throws Exception { + PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); + Mockito.when(this.commentManagementAPI.getRatedUser(Mockito.anyString())).thenThrow(new ApplicationManagementException()); + Response response = this.commentManagementAPI.getRatedUser("a"); + 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 testUpdateStars() throws Exception { PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);