Search in sources :

Example 26 with Comment

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

the class APIStoreImplTestCase method testDeleteCommentMissingException.

@Test(description = "Comment not found in db when retrieving comment before delete", expectedExceptions = APIMgtResourceNotFoundException.class)
public void testDeleteCommentMissingException() 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(randomUUIDForComment, api.getId())).thenReturn(null);
    apiStore.deleteComment(randomUUIDForComment, api.getId(), "admin");
}
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 27 with Comment

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

the class APIStoreImplTestCase method testGetComment.

@Test(description = "Get comment")
public void testGetComment() 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.getCommentByUUID(comment.getUuid(), api.getId());
    Mockito.verify(apiDAO, Mockito.times(1)).isAPIExists(api.getId());
    Mockito.verify(apiDAO, Mockito.times(1)).getCommentByUUID(comment.getUuid(), 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)

Example 28 with Comment

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

the class CommentMappingUtilTestCase method testFromCommentListToDTO.

@Test
public void testFromCommentListToDTO() {
    Comment comment1 = new Comment();
    comment1.setUuid(UUID.randomUUID().toString());
    comment1.setCommentedUser("commentedUser1");
    comment1.setCommentText("this is a comment 1");
    comment1.setCreatedUser("createdUser1");
    comment1.setUpdatedUser("updatedUser1");
    comment1.setCreatedTime(LocalDateTime.now().minusHours(1));
    comment1.setUpdatedTime(LocalDateTime.now());
    Comment comment2 = new Comment();
    comment2.setUuid(UUID.randomUUID().toString());
    comment2.setCommentedUser("commentedUser2");
    comment2.setCommentText("this is a comment 2");
    comment2.setCreatedUser("createdUser2");
    comment2.setUpdatedUser("updatedUser2");
    comment2.setCreatedTime(LocalDateTime.now().minusHours(1));
    comment2.setUpdatedTime(LocalDateTime.now());
    List<Comment> commentList = new ArrayList<>();
    commentList.add(comment1);
    commentList.add(comment2);
    CommentListDTO commentListDTO = commentMappingUtil.fromCommentListToDTO(commentList, 10, 0);
    Assert.assertEquals(commentListDTO.getList().get(0).getUsername().toString(), "commentedUser1");
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) ArrayList(java.util.ArrayList) CommentListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CommentListDTO) Test(org.junit.Test)

Example 29 with Comment

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

the class TaskOperationsImpl method deleteComment.

/**
 * Deletes the identified comment.
 * @param taskIdURI : task identifier
 * @param commentId : comment identifier
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void deleteComment(final URI taskIdURI, final URI commentId) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                DeleteComment deleteComment = new DeleteComment(getCaller(), taskId, new Long(commentId.toString()));
                deleteComment.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : DeleteComment(org.wso2.carbon.humantask.core.engine.commands.DeleteComment) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)

Example 30 with Comment

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

the class WorkflowTaskService method getComment.

@GET
@Path("/{taskId}/comments/{commentId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getComment(@PathParam("taskId") String taskId, @PathParam("commentId") String commentId) {
    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    Comment comment = taskService.getComment(commentId);
    if (comment == null || !task.getId().equals(comment.getTaskId())) {
        throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
    }
    return Response.ok().entity(new RestResponseFactory().createRestComment(comment, uriInfo.getBaseUri().toString())).build();
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

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