Add new methods

Exception handling test methods for rating methods
merge-requests/7/head
nishadi 7 years ago
parent 55a005e992
commit e70899a193

@ -31,7 +31,6 @@ 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;
@ -41,8 +40,6 @@ import org.wso2.carbon.device.application.mgt.store.api.services.util.CommentMgt
import javax.ws.rs.core.Response;
import java.util.List;
import static org.mockito.MockitoAnnotations.initMocks;
@PowerMockIgnore("javax.ws.rs.*")
@ -80,6 +77,17 @@ public class CommentManagementAPITest {
Mockito.reset(commentsManager);
}
@Test
public void testGetAllCommentsInternalError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.doThrow(new CommentManagementException()).when(this.commentsManager).getAllComments(Mockito.any(),Mockito.anyString());
Response response = this.commentManagementAPI.getAllComments("a", 1, 4);
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500.");
Mockito.reset(commentsManager);
Assert.assertNotNull(response, "The response object is null.");
}
@Test
public void testAddComments() throws Exception {
Comment comment = CommentMgtTestHelper.getDummyComment("a", "a");
@ -143,6 +151,17 @@ public class CommentManagementAPITest {
"The response status should be 404.");
}
@Test
public void testUpdateCommentInternalServerError() throws Exception {
Comment comment = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.doThrow(new CommentManagementException()).when(this.commentsManager).updateComment(comment, 9);
Response response = this.commentManagementAPI.updateComment(comment, 9);
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 testDeleteComment() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
@ -187,7 +206,8 @@ public class CommentManagementAPITest {
@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());
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(),
@ -208,7 +228,8 @@ public class CommentManagementAPITest {
@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());
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(),
@ -219,7 +240,8 @@ public class CommentManagementAPITest {
@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());
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(),
@ -247,4 +269,15 @@ public class CommentManagementAPITest {
Mockito.reset(commentsManager);
}
@Test
public void testUpdateStarsApplicationError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.doThrow(new ApplicationManagementException()).when(this.commentsManager)
.updateStars(Mockito.anyInt(), Mockito.anyString());
Response response = this.commentManagementAPI.updateStars(3, "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);
}
}
Loading…
Cancel
Save