Add new methods

TestAddCommentInternalError and TestDeleteComment.
feature/appm-store/pbac
nishadi 7 years ago
parent dff3cf7645
commit dab9208168

@ -81,7 +81,7 @@ public class CommentManagementAPITest {
public void testAddComments() throws Exception { public void testAddComments() throws Exception {
Comment comment = CommentMgtTestHelper.getDummyComment("a", "a"); Comment comment = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); 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.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
"The response status should be 201."); "The response status should be 201.");
@ -98,6 +98,19 @@ public class CommentManagementAPITest {
Mockito.reset(commentsManager); 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 @Test
public void testUpdateComment() throws Exception { public void testUpdateComment() throws Exception {
Comment comment = CommentMgtTestHelper.getDummyComment("a", "a"); Comment comment = CommentMgtTestHelper.getDummyComment("a", "a");
@ -127,6 +140,25 @@ public class CommentManagementAPITest {
"The response status should be 404."); "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 @Test
public void testGetStars() throws Exception { public void testGetStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
@ -158,7 +190,7 @@ public class CommentManagementAPITest {
} }
@Test @Test
public void testUpdateInvalideStars() throws Exception { public void testUpdateInvalidStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager); PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.updateStars(0, "a"); Response response = this.commentManagementAPI.updateStars(0, "a");
Assert.assertNotNull(response, "The response object is null."); Assert.assertNotNull(response, "The response object is null.");

Loading…
Cancel
Save