use of org.opencastproject.event.comment.EventComment in project opencast by opencast.
the class EventCommentDatabaseImplTest method testUpdateCommentReplies.
@Test
public void testUpdateCommentReplies() throws Exception {
final EventComment persistedComment = persistence.updateComment(COMMENT_1);
assertEquals(COMMENT_1, persistedComment);
persistedComment.addReply(EventCommentReply.create(none(Long.class), "comment1", USER));
persistedComment.addReply(EventCommentReply.create(none(Long.class), "comment2", USER));
final EventComment updatedComment = persistence.updateComment(persistedComment);
updatedComment.removeReply(updatedComment.getReplies().get(0));
updatedComment.addReply(EventCommentReply.create(none(Long.class), "comment3", USER));
final EventComment modifiedComment = persistence.updateComment(updatedComment);
assertEquals(2, modifiedComment.getReplies().size());
assertEquals("comment2", modifiedComment.getReplies().get(0).getText());
assertEquals("comment3", modifiedComment.getReplies().get(1).getText());
}
use of org.opencastproject.event.comment.EventComment in project opencast by opencast.
the class CommentWorkflowOperationHandlerTest method testDuplicateComments.
@Test
public void testDuplicateComments() throws WorkflowOperationException, EventCommentException {
// Testing that a duplicate comment won't be created but a different one will still be created.
Long workflowId = 10L;
String mediaPackageId = "abc-def";
String action = "create";
String reason = "Waiting for Trim";
String description = "The comment description";
Organization org = createNiceMock(Organization.class);
expect(org.getId()).andStubReturn("demo");
replay(org);
SecurityService secSrv = createNiceMock(SecurityService.class);
expect(secSrv.getOrganization()).andStubReturn(org);
replay(secSrv);
// Setup WorkflowOperation Instance
WorkflowOperationInstance workflowOperationInstance = EasyMock.createMock(WorkflowOperationInstance.class);
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(action).anyTimes();
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.REASON)).andReturn(reason).anyTimes();
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.DESCRIPTION)).andReturn(description).anyTimes();
// Setup mediaPackage
MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
EasyMock.expect(mediaPackage.getIdentifier()).andReturn(new IdImpl(mediaPackageId)).anyTimes();
// Setup user
User creator = EasyMock.createMock(User.class);
// Setup WorkflowInstance
WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getId()).andReturn(workflowId).anyTimes();
EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(workflowOperationInstance).anyTimes();
EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
EasyMock.expect(workflowInstance.getCreator()).andReturn(creator).anyTimes();
// Test no previous comments
EventCommentService eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>());
Capture<EventComment> comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
EasyMock.replay(creator, eventCommentService, mediaPackage, workflowInstance, workflowOperationInstance);
CommentWorkflowOperationHandler commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
assertTrue(comment.hasCaptured());
assertEquals(creator, comment.getValue().getAuthor());
assertEquals(description, comment.getValue().getText());
assertEquals(reason, comment.getValue().getReason());
// Test previous comment with same reason and description
List<EventComment> comments = new ArrayList<EventComment>();
comments.add(EventComment.create(Option.option(13L), mediaPackageId, org.getId(), description, creator, reason, true));
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments);
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.start(workflowInstance, null);
assertTrue(comment.hasCaptured());
assertEquals(creator, comment.getValue().getAuthor());
assertEquals(description, comment.getValue().getText());
assertEquals(reason, comment.getValue().getReason());
// Test previous comment with different reasons and descriptions
comments = new ArrayList<EventComment>();
comments.add(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), "Different description", creator, reason, true));
comments.add(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator, "Different reason", true));
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments);
comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
assertTrue(comment.hasCaptured());
assertEquals(creator, comment.getValue().getAuthor());
assertEquals(description, comment.getValue().getText());
assertEquals(reason, comment.getValue().getReason());
}
use of org.opencastproject.event.comment.EventComment in project opencast by opencast.
the class CommentWorkflowOperationHandler method createComment.
/**
* Create a new comment if one doesn't already exist with the reason and description.
*
* @param workflowInstance
* The {@link WorkflowInstance} to handle.
* @param reason
* The reason for the comment.
* @param description
* The descriptive text of the comment.
* @throws EventCommentException
* Thrown if unable to create the comment.
*/
private void createComment(WorkflowInstance workflowInstance, String reason, String description) throws EventCommentException {
Opt<EventComment> optComment = findComment(workflowInstance.getMediaPackage().getIdentifier().toString(), reason, description);
if (optComment.isNone()) {
EventComment comment = EventComment.create(Option.<Long>none(), workflowInstance.getMediaPackage().getIdentifier().toString(), securityService.getOrganization().getId(), description, workflowInstance.getCreator(), reason, false);
eventCommentService.updateComment(comment);
} else {
logger.debug("Not creating comment with '{}' text and '{}' reason as it already exists for this event.", description, reason);
}
}
Aggregations