use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class APIStoreImpl method addComment.
@Override
public String addComment(Comment comment, String apiId) throws APICommentException, APIMgtResourceNotFoundException {
validateCommentMaxCharacterLength(comment.getCommentText());
String generatedUuid = UUID.randomUUID().toString();
comment.setUuid(generatedUuid);
try {
failIfApiNotExists(apiId);
getApiDAO().addComment(comment, apiId);
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while adding comment for api - " + apiId;
log.error(errorMsg, e);
throw new APICommentException(errorMsg, e, e.getErrorHandler());
}
return comment.getUuid();
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class APIStoreImpl method deleteComment.
@Override
public void deleteComment(String commentId, String apiId, String username) throws APICommentException, APIMgtResourceNotFoundException {
try {
ApiDAO apiDAO = getApiDAO();
failIfApiNotExists(apiId);
Comment comment = apiDAO.getCommentByUUID(commentId, apiId);
if (comment != null) {
// if the delete operation is done by a user who isn't the owner of the comment
if (!comment.getCommentedUser().equals(username)) {
checkIfUserIsCommentModerator(username);
}
apiDAO.deleteComment(commentId, apiId);
} else {
String errorMsg = "Couldn't find comment with comment_id : " + commentId;
log.error(errorMsg);
throw new APIMgtResourceNotFoundException(errorMsg, ExceptionCodes.COMMENT_NOT_FOUND);
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error occurred while deleting comment " + commentId;
log.error(errorMsg, e);
throw new APICommentException(errorMsg, e, e.getErrorHandler());
}
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteCommentDaoException.
@Test(description = "Exception in dao when deleting a specific comment", expectedExceptions = APIMgtResourceNotFoundException.class)
public void testDeleteCommentDaoException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
Mockito.when(apiDAO.getCommentByUUID(comment.getUuid(), api.getId())).thenReturn(comment);
Mockito.doThrow(new APIMgtDAOException("Error occurred while deleting comment " + comment.getUuid(), new SQLException())).when(apiDAO).deleteComment(comment.getUuid(), api.getId());
apiStore.deleteComment(comment.getUuid(), api.getId(), "admin");
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteCommentApiMissingException.
@Test(description = "Exception when deleting a comment due to missing api", expectedExceptions = APIManagementException.class)
public void testDeleteCommentApiMissingException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO);
String randomUUIDForApi = java.util.UUID.randomUUID().toString();
Mockito.when(apiDAO.getAPI(randomUUIDForApi)).thenReturn(null);
String randomUUIDForComment = java.util.UUID.randomUUID().toString();
apiStore.deleteComment(randomUUIDForComment, randomUUIDForApi, "admin");
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteComment.
@Test(description = "Delete comment")
public void testDeleteComment() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.when(apiDAO.isAPIExists(api.getId())).thenReturn(true);
Comment comment = SampleTestObjectCreator.createDefaultComment(api.getId());
Mockito.when(apiDAO.getCommentByUUID(comment.getUuid(), api.getId())).thenReturn(comment);
apiStore.deleteComment(comment.getUuid(), api.getId(), "admin");
Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
Mockito.verify(apiDAO, Mockito.times(1)).deleteComment(comment.getUuid(), api.getId());
}
Aggregations