use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddCommentApiMissingException.
@Test(description = "Exception when adding a comment due to missing api", expectedExceptions = APIManagementException.class)
public void testAddCommentApiMissingException() 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);
Comment comment = SampleTestObjectCreator.createDefaultComment(randomUUIDForApi);
apiStore.addComment(comment, randomUUIDForApi);
}
use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddComment.
@Test(description = "Add comment")
public void testAddComment() 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());
apiStore.addComment(comment, api.getId());
Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
Mockito.verify(apiDAO, Mockito.times(1)).addComment(comment, api.getId());
}
use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testUpdateCommentDaoException.
@Test(description = "Exception in dao when updating a specific comment", expectedExceptions = APIMgtResourceNotFoundException.class)
public void testUpdateCommentDaoException() 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 updating comment " + comment.getUuid(), new SQLException())).when(apiDAO).updateComment(comment, comment.getUuid(), api.getId());
apiStore.updateComment(comment, comment.getUuid(), api.getId(), "admin");
}
use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddCommentException.
@Test(description = "Exception in dao when adding a comment", expectedExceptions = APIManagementException.class)
public void testAddCommentException() 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.doThrow(new APIMgtDAOException("Error occurred while adding comment for api id " + api.getId(), new SQLException())).when(apiDAO).addComment(comment, api.getId());
apiStore.addComment(comment, api.getId());
}
use of org.wso2.carbon.apimgt.api.model.Comment in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetCommentDaoException.
@Test(description = "Exception in dao when retrieving a specific comment", expectedExceptions = APIManagementException.class)
public void testGetCommentDaoException() 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);
String randomUUIDForComment = java.util.UUID.randomUUID().toString();
Mockito.doThrow(new APIMgtDAOException("Error occurred while retrieving comment " + randomUUIDForComment, new SQLException())).when(apiDAO).getCommentByUUID(randomUUIDForComment, api.getId());
apiStore.getCommentByUUID(randomUUIDForComment, api.getId());
}
Aggregations