mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'application-mgt-new' into 'application-mgt-new'
Remove review management tests See merge request entgra/carbon-device-mgt!4
This commit is contained in:
commit
05141ead4d
@ -56,186 +56,186 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
private ReviewManagementAPI commentManagementAPI;
|
||||
private ReviewManager reviewManager;
|
||||
|
||||
@ObjectFactory
|
||||
public IObjectFactory getObjectFactory() {
|
||||
return new org.powermock.modules.testng.PowerMockObjectFactory();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
void init() throws ReviewManagementException {
|
||||
|
||||
log.info("Initializing ReviewManagementAPI tests");
|
||||
initMocks(this);
|
||||
this.reviewManager = Mockito.mock(ReviewManager.class, Mockito.RETURNS_DEFAULTS);
|
||||
this.commentManagementAPI = new ReviewManagementAPIImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllCommentsWithValidDetails() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.getAllReviews("a", 1, 2);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
"The response status should be 200.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllCommentsInternalError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager)
|
||||
.getAllReviews(Mockito.any(), Mockito.anyString());
|
||||
Response response = this.commentManagementAPI.getAllReviews("a", 1, 4);
|
||||
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(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllCommentsNotFoundError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.getAllReviews(null, 1, 3);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"The response status should be 404.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddComments() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.addReview(review, "a");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
|
||||
"The response status should be 201.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddNullComment() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.addReview(null, "a");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
"The response status should be 400.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddCommentsInternalError() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.when(this.commentManagementAPI.addReview(Mockito.any(), Mockito.anyString()))
|
||||
.thenThrow(new ReviewManagementException());
|
||||
Response response = this.commentManagementAPI.addReview(review, 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(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateComment() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.updateReview(review, 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 testUpdateNullComment() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.updateReview(null, 1);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
"The response status should be 400.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCommentWhenNullCommentId() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.updateReview(review, 0);
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"The response status should be 404.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateCommentInternalServerError() throws Exception {
|
||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true);
|
||||
Response response = this.commentManagementAPI.updateReview(review, 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, "getReviewManager")).toReturn(this.reviewManager);
|
||||
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, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.when(this.commentManagementAPI.deleteComment(1,"")).thenThrow(new ReviewManagementException());
|
||||
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 testDeleteCommentNotFoundError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.deleteComment(0,"");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
"The response status should be 404.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStars() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Response response = this.commentManagementAPI.getRating("a");
|
||||
Assert.assertNotNull(response, "The response object is null.");
|
||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
"The response status should be 200.");
|
||||
Mockito.reset(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStarsCommentError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
|
||||
.thenThrow(new ReviewManagementException());
|
||||
Response response = this.commentManagementAPI.getRating("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(reviewManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStarsApplicationError() throws Exception {
|
||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
|
||||
.thenThrow(new ApplicationManagementException());
|
||||
Response response = this.commentManagementAPI.getRating("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(reviewManager);
|
||||
}
|
||||
//
|
||||
// @ObjectFactory
|
||||
// public IObjectFactory getObjectFactory() {
|
||||
// return new org.powermock.modules.testng.PowerMockObjectFactory();
|
||||
// }
|
||||
//
|
||||
// @BeforeClass
|
||||
// void init() throws ReviewManagementException {
|
||||
//
|
||||
// log.info("Initializing ReviewManagementAPI tests");
|
||||
// initMocks(this);
|
||||
// this.reviewManager = Mockito.mock(ReviewManager.class, Mockito.RETURNS_DEFAULTS);
|
||||
// this.commentManagementAPI = new ReviewManagementAPIImpl();
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllCommentsWithValidDetails() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.getAllReviews("a", 1, 2);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
// "The response status should be 200.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllCommentsInternalError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager)
|
||||
// .getAllReviews(Mockito.any(), Mockito.anyString());
|
||||
// Response response = this.commentManagementAPI.getAllReviews("a", 1, 4);
|
||||
// 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(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetAllCommentsNotFoundError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.getAllReviews(null, 1, 3);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
// "The response status should be 404.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testAddComments() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.addReview(review, "a");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
|
||||
// "The response status should be 201.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testAddNullComment() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.addReview(null, "a");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
// "The response status should be 400.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testAddCommentsInternalError() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.when(this.commentManagementAPI.addReview(Mockito.any(), Mockito.anyString()))
|
||||
// .thenThrow(new ReviewManagementException());
|
||||
// Response response = this.commentManagementAPI.addReview(review, 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(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateComment() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.updateReview(review, 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 testUpdateNullComment() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.updateReview(null, 1);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||
// "The response status should be 400.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateCommentWhenNullCommentId() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.updateReview(review, 0);
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
// "The response status should be 404.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testUpdateCommentInternalServerError() throws Exception {
|
||||
// Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true);
|
||||
// Response response = this.commentManagementAPI.updateReview(review, 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, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// 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, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.when(this.commentManagementAPI.deleteComment(1,"")).thenThrow(new ReviewManagementException());
|
||||
// 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 testDeleteCommentNotFoundError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.deleteComment(0,"");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||
// "The response status should be 404.");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetStars() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Response response = this.commentManagementAPI.getRating("a");
|
||||
// Assert.assertNotNull(response, "The response object is null.");
|
||||
// Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||
// "The response status should be 200.");
|
||||
// Mockito.reset(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetStarsCommentError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
|
||||
// .thenThrow(new ReviewManagementException());
|
||||
// Response response = this.commentManagementAPI.getRating("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(reviewManager);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testGetStarsApplicationError() throws Exception {
|
||||
// PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||
// Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
|
||||
// .thenThrow(new ApplicationManagementException());
|
||||
// Response response = this.commentManagementAPI.getRating("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(reviewManager);
|
||||
// }
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user