Search in sources :

Example 46 with Comment

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

the class APIStoreImplTestCase method testCommentModeratorWhileDeleteComment.

@Test(description = "check if user is comment moderator while delete comment", expectedExceptions = APIMgtResourceNotFoundException.class)
public void testCommentModeratorWhileDeleteComment() 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);
    apiStore.deleteComment(comment.getUuid(), api.getId(), "john");
}
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)

Example 47 with Comment

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

the class APIStoreImplTestCase method searchAPIsWithException.

@Test(description = "Search API", expectedExceptions = APIManagementException.class)
public void searchAPIsWithException() throws Exception {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIStore apiStore = getApiStoreImpl(apiDAO);
    List<String> statuses = new ArrayList<>();
    statuses.add(APIStatus.PUBLISHED.getStatus());
    statuses.add(APIStatus.PROTOTYPED.getStatus());
    Set<String> roles = new HashSet<>();
    roles.add("admin");
    roles.add("comment-moderator");
    roles.add("EVERYONE");
    List<String> labels = new ArrayList<>();
    // TODO
    PowerMockito.mockStatic(APIUtils.class);
    Mockito.doThrow(new APIMgtDAOException("Error occurred while getting APIs by statuses")).when(apiDAO).getAPIsByStatus(roles, statuses, labels);
    // doThrow(new Exception()).when(APIUtils).logAndThrowException(null, null, null)).
    apiStore.searchAPIsByStoreLabels(null, 1, 2, new ArrayList<>());
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) ArrayList(java.util.ArrayList) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 48 with Comment

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

the class APIStoreImplTestCase method testUpdateCommentMissingException.

@Test(description = "Comment not found in db when retrieving comment before update", expectedExceptions = APIMgtResourceNotFoundException.class)
public void testUpdateCommentMissingException() 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(null);
    apiStore.updateComment(comment, comment.getUuid(), api.getId(), "admin");
}
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)

Example 49 with Comment

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

the class APIStoreImplTestCase method testGetAllCommentsForApi.

@Test(description = "Get all comments for an api")
public void testGetAllCommentsForApi() 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);
    List<Comment> commentList = new ArrayList<>();
    Comment comment1 = SampleTestObjectCreator.createDefaultComment(api.getId());
    Comment comment2 = SampleTestObjectCreator.createDefaultComment(api.getId());
    commentList.add(comment1);
    commentList.add(comment2);
    Mockito.when(apiDAO.getCommentsForApi(api.getId())).thenReturn(commentList);
    List<Comment> commentListFromDB = apiStore.getCommentsForApi(api.getId());
    Assert.assertNotNull(commentListFromDB);
    Assert.assertEquals(commentList.size(), commentListFromDB.size());
    Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
    Mockito.verify(apiDAO, Mockito.times(1)).getCommentsForApi(api.getId());
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) ArrayList(java.util.ArrayList) 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 50 with Comment

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

the class APIStoreImplTestCase method testGetCommentApiMissingException.

@Test(description = "Exception when retrieving a specific comment due to missing api", expectedExceptions = APIManagementException.class)
public void testGetCommentApiMissingException() 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.getCommentByUUID(randomUUIDForComment, randomUUIDForApi);
}
Also used : 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 BeforeTest (org.testng.annotations.BeforeTest)18 API (org.wso2.carbon.apimgt.core.models.API)17 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)17 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)15 SQLException (java.sql.SQLException)9 CommentDTO (org.wso2.carbon.apimgt.rest.api.store.dto.CommentDTO)9 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 APICommentException (org.wso2.carbon.apimgt.core.exception.APICommentException)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)6 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 Response (javax.ws.rs.core.Response)4