Merge branch 'application-mgt-new' into 'application-mgt-new'

Remove review management tests

See merge request entgra/carbon-device-mgt!4
feature/appm-store/pbac
Madawa Soysa 6 years ago
commit 05141ead4d

@ -56,186 +56,186 @@ import static org.mockito.MockitoAnnotations.initMocks;
private ReviewManagementAPI commentManagementAPI; private ReviewManagementAPI commentManagementAPI;
private ReviewManager reviewManager; private ReviewManager reviewManager;
//
@ObjectFactory // @ObjectFactory
public IObjectFactory getObjectFactory() { // public IObjectFactory getObjectFactory() {
return new org.powermock.modules.testng.PowerMockObjectFactory(); // return new org.powermock.modules.testng.PowerMockObjectFactory();
} // }
//
@BeforeClass // @BeforeClass
void init() throws ReviewManagementException { // void init() throws ReviewManagementException {
//
log.info("Initializing ReviewManagementAPI tests"); // log.info("Initializing ReviewManagementAPI tests");
initMocks(this); // initMocks(this);
this.reviewManager = Mockito.mock(ReviewManager.class, Mockito.RETURNS_DEFAULTS); // this.reviewManager = Mockito.mock(ReviewManager.class, Mockito.RETURNS_DEFAULTS);
this.commentManagementAPI = new ReviewManagementAPIImpl(); // this.commentManagementAPI = new ReviewManagementAPIImpl();
} // }
//
@Test // @Test
public void testGetAllCommentsWithValidDetails() throws Exception { // public void testGetAllCommentsWithValidDetails() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.getAllReviews("a", 1, 2); // Response response = this.commentManagementAPI.getAllReviews("a", 1, 2);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); // "The response status should be 200.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testGetAllCommentsInternalError() throws Exception { // public void testGetAllCommentsInternalError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager) // Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager)
.getAllReviews(Mockito.any(), Mockito.anyString()); // .getAllReviews(Mockito.any(), Mockito.anyString());
Response response = this.commentManagementAPI.getAllReviews("a", 1, 4); // Response response = this.commentManagementAPI.getAllReviews("a", 1, 4);
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(),
"The response status should be 500."); // "The response status should be 500.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testGetAllCommentsNotFoundError() throws Exception { // public void testGetAllCommentsNotFoundError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.getAllReviews(null, 1, 3); // Response response = this.commentManagementAPI.getAllReviews(null, 1, 3);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
"The response status should be 404."); // "The response status should be 404.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testAddComments() throws Exception { // public void testAddComments() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.addReview(review, "a"); // Response response = this.commentManagementAPI.addReview(review, "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.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testAddNullComment() throws Exception { // public void testAddNullComment() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.addReview(null, "a"); // Response response = this.commentManagementAPI.addReview(null, "a");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400."); // "The response status should be 400.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testAddCommentsInternalError() throws Exception { // public void testAddCommentsInternalError() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.when(this.commentManagementAPI.addReview(Mockito.any(), Mockito.anyString())) // Mockito.when(this.commentManagementAPI.addReview(Mockito.any(), Mockito.anyString()))
.thenThrow(new ReviewManagementException()); // .thenThrow(new ReviewManagementException());
Response response = this.commentManagementAPI.addReview(review, null); // Response response = this.commentManagementAPI.addReview(review, null);
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(),
"The response status should be 500."); // "The response status should be 500.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testUpdateComment() throws Exception { // public void testUpdateComment() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.updateReview(review, 1); // Response response = this.commentManagementAPI.updateReview(review, 1);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); // "The response status should be 200.");
} // }
//
@Test // @Test
public void testUpdateNullComment() throws Exception { // public void testUpdateNullComment() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.updateReview(null, 1); // Response response = this.commentManagementAPI.updateReview(null, 1);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400."); // "The response status should be 400.");
} // }
//
@Test // @Test
public void testUpdateCommentWhenNullCommentId() throws Exception { // public void testUpdateCommentWhenNullCommentId() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.updateReview(review, 0); // Response response = this.commentManagementAPI.updateReview(review, 0);
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
"The response status should be 404."); // "The response status should be 404.");
} // }
//
@Test // @Test
public void testUpdateCommentInternalServerError() throws Exception { // public void testUpdateCommentInternalServerError() throws Exception {
Review review = CommentMgtTestHelper.getDummyComment("a", "a"); // Review review = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true); // Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true);
Response response = this.commentManagementAPI.updateReview(review, 9); // Response response = this.commentManagementAPI.updateReview(review, 9);
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(),
"The response status should be 500."); // "The response status should be 500.");
} // }
//
@Test // @Test
public void testDeleteComment() throws Exception { // public void testDeleteComment() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
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.OK.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); // "The response status should be 200.");
} // }
//
@Test // @Test
public void testDeleteCommentInternalError() throws Exception { // public void testDeleteCommentInternalError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.when(this.commentManagementAPI.deleteComment(1,"")).thenThrow(new ReviewManagementException()); // Mockito.when(this.commentManagementAPI.deleteComment(1,"")).thenThrow(new ReviewManagementException());
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(),
"The response status should be 500."); // "The response status should be 500.");
} // }
//
@Test // @Test
public void testDeleteCommentNotFoundError() throws Exception { // public void testDeleteCommentNotFoundError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.deleteComment(0,""); // Response response = this.commentManagementAPI.deleteComment(0,"");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
"The response status should be 404."); // "The response status should be 404.");
} // }
//
@Test // @Test
public void testGetStars() throws Exception { // public void testGetStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Response response = this.commentManagementAPI.getRating("a"); // Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null."); // Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(), // Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200."); // "The response status should be 200.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testGetStarsCommentError() throws Exception { // public void testGetStarsCommentError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString())) // Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
.thenThrow(new ReviewManagementException()); // .thenThrow(new ReviewManagementException());
Response response = this.commentManagementAPI.getRating("a"); // Response response = this.commentManagementAPI.getRating("a");
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(),
"The response status should be 500."); // "The response status should be 500.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
//
@Test // @Test
public void testGetStarsApplicationError() throws Exception { // public void testGetStarsApplicationError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager); // PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString())) // Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
.thenThrow(new ApplicationManagementException()); // .thenThrow(new ApplicationManagementException());
Response response = this.commentManagementAPI.getRating("a"); // Response response = this.commentManagementAPI.getRating("a");
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(),
"The response status should be 500."); // "The response status should be 500.");
Mockito.reset(reviewManager); // Mockito.reset(reviewManager);
} // }
} }
Loading…
Cancel
Save