Search in sources :

Example 56 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class APIStoreImpl method getCommentsForApi.

@Override
public List<Comment> getCommentsForApi(String apiId) throws APICommentException, APIMgtResourceNotFoundException {
    try {
        failIfApiNotExists(apiId);
        List<Comment> commentList = getApiDAO().getCommentsForApi(apiId);
        return commentList;
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while retrieving comments for api " + apiId;
        log.error(errorMsg, e);
        throw new APICommentException(errorMsg, e, e.getErrorHandler());
    }
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APICommentException(org.wso2.carbon.apimgt.core.exception.APICommentException)

Example 57 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class ApiDAOImplIT method testAddGetCommentsOfAPI.

@Test
public void testAddGetCommentsOfAPI() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    Comment comment1 = SampleTestObjectCreator.createDefaultComment(api.getId());
    Comment comment2 = SampleTestObjectCreator.createAlternativeComment(api.getId());
    apiDAO.addComment(comment1, api.getId());
    apiDAO.addComment(comment2, api.getId());
    List<Comment> commentsFromDB = apiDAO.getCommentsForApi(api.getId());
    Assert.assertEquals(commentsFromDB.size(), 2);
    Assert.assertTrue(commentsFromDB.get(0).getCommentText().equals(comment1.getCommentText()) || commentsFromDB.get(0).getCommentText().equals(comment2.getCommentText()));
    Assert.assertTrue(commentsFromDB.get(1).getCommentText().equals(comment1.getCommentText()) || commentsFromDB.get(1).getCommentText().equals(comment2.getCommentText()));
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 58 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testUpdateCommentApiMissingException.

@Test(description = "Exception when updating a comment due to missing api", expectedExceptions = APIManagementException.class)
public void testUpdateCommentApiMissingException() 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.updateComment(comment, comment.getUuid(), randomUUIDForApi, "admin");
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 59 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testGetCommentMissingException.

@Test(description = "Comment not found in db when retrieving comment", expectedExceptions = APIMgtResourceNotFoundException.class)
public void testGetCommentMissingException() 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.when(apiDAO.getCommentByUUID(api.getId(), randomUUIDForComment)).thenReturn(null);
    apiStore.getCommentByUUID(randomUUIDForComment, api.getId());
}
Also used : CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 60 with Comment

use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testUpdateComment.

@Test(description = "Update comment")
public void testUpdateComment() 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(UUID, api.getId())).thenReturn(comment);
    apiStore.updateComment(comment, UUID, api.getId(), "admin");
    Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
    Mockito.verify(apiDAO, Mockito.times(1)).updateComment(comment, UUID, api.getId());
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Comment (org.wso2.carbon.apimgt.core.models.Comment)36 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)28 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)23 Test (org.testng.annotations.Test)22 SQLException (java.sql.SQLException)18 BeforeTest (org.testng.annotations.BeforeTest)18 API (org.wso2.carbon.apimgt.core.models.API)17 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)17 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 Comment (org.wso2.carbon.apimgt.api.model.Comment)16 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)15 PreparedStatement (java.sql.PreparedStatement)13 Connection (java.sql.Connection)12 HashMap (java.util.HashMap)12 Map (java.util.Map)12 ArrayList (java.util.ArrayList)10 CommentDTO (org.wso2.carbon.apimgt.rest.api.store.dto.CommentDTO)9 URI (java.net.URI)8 URISyntaxException (java.net.URISyntaxException)8 Test (org.junit.Test)8