mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Add new methods
Exception handling test methods for rating methods
This commit is contained in:
parent
dab9208168
commit
55a005e992
@ -31,22 +31,25 @@ import org.testng.annotations.BeforeClass;
|
|||||||
import org.testng.annotations.ObjectFactory;
|
import org.testng.annotations.ObjectFactory;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
import org.wso2.carbon.device.application.mgt.common.Comment;
|
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.exception.CommentManagementException;
|
||||||
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
|
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.APIUtil;
|
||||||
import org.wso2.carbon.device.application.mgt.store.api.services.impl.CommentManagementAPIImpl;
|
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.device.application.mgt.store.api.services.util.CommentMgtTestHelper;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
|
||||||
|
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.mockito.MockitoAnnotations.initMocks;
|
import static org.mockito.MockitoAnnotations.initMocks;
|
||||||
|
|
||||||
@PowerMockIgnore("javax.ws.rs.*")
|
@PowerMockIgnore("javax.ws.rs.*")
|
||||||
@SuppressStaticInitializationFor({
|
@SuppressStaticInitializationFor({
|
||||||
"org.wso2.carbon.device.application.mgt.api.APIUtil" })
|
"org.wso2.carbon.device.application.mgt.api.APIUtil" })
|
||||||
@PrepareForTest({ APIUtil.class, CommentsManager.class,
|
@PrepareForTest({ APIUtil.class, CommentsManager.class,
|
||||||
CommentManagementAPITest.class, MultitenantUtils.class })
|
CommentManagementAPITest.class})
|
||||||
public class CommentManagementAPITest {
|
public class CommentManagementAPITest {
|
||||||
private static final Log log = LogFactory.getLog(CommentManagementAPI.class);
|
private static final Log log = LogFactory.getLog(CommentManagementAPI.class);
|
||||||
|
|
||||||
@ -152,7 +155,8 @@ public class CommentManagementAPITest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDeleteCommentInternalError() throws Exception {
|
public void testDeleteCommentInternalError() throws Exception {
|
||||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
|
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);
|
Response response = this.commentManagementAPI.deleteComment(1);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
@ -169,6 +173,28 @@ public class CommentManagementAPITest {
|
|||||||
Mockito.reset(commentsManager);
|
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
|
@Test
|
||||||
public void testGetRatedUser() throws Exception {
|
public void testGetRatedUser() throws Exception {
|
||||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
|
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
|
||||||
@ -179,6 +205,28 @@ public class CommentManagementAPITest {
|
|||||||
Mockito.reset(commentsManager);
|
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
|
@Test
|
||||||
public void testUpdateStars() throws Exception {
|
public void testUpdateStars() throws Exception {
|
||||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
|
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user