use of org.opencastproject.event.comment.EventCommentService in project opencast by opencast.
the class CommentWorkflowOperationHandlerTest method testDifferentCaseAction.
@Test
public void testDifferentCaseAction() 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 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);
// Standard
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn("create");
// Mixed case
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn("CrEaTe");
// All Caps
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn("CREATE");
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();
EasyMock.replay(creator, mediaPackage, workflowInstance, workflowOperationInstance);
// Test no previous comments
EventCommentService eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
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(eventCommentService);
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());
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(17L), 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());
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(19L), mediaPackageId, org.getId(), description, creator));
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
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.EventCommentService in project opencast by opencast.
the class CommentWorkflowOperationHandlerTest method testPossibleActions.
@Test
public void testPossibleActions() throws WorkflowOperationException, EventCommentException, NotFoundException {
// Testing that a duplicate comment won't be created but a different one will still be created.
Long workflowId = 10L;
Long deleteCommentId = 21L;
String mediaPackageId = "abc-def";
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);
// Create
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.create.toString());
// Resolve
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.resolve.toString());
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.resolve.toString());
// Deletes
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.delete.toString());
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.delete.toString());
EasyMock.expect(workflowOperationInstance.getConfiguration(CommentWorkflowOperationHandler.ACTION)).andReturn(CommentWorkflowOperationHandler.Operation.delete.toString());
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();
EasyMock.replay(creator, mediaPackage, workflowInstance, workflowOperationInstance);
// Test create
EventCommentService eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
Capture<EventComment> comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(15L), mediaPackageId, org.getId(), description, creator));
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(17L), mediaPackageId, org.getId(), description, creator));
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(19L), mediaPackageId, org.getId(), description, creator));
EasyMock.replay(eventCommentService);
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());
assertEquals(false, comment.getValue().isResolvedStatus());
// Test resolve
eventCommentService = EasyMock.createMock(EventCommentService.class);
List<EventComment> comments = new ArrayList<EventComment>();
comments.add(EventComment.create(Option.option(deleteCommentId), mediaPackageId, org.getId(), description, creator, reason, false));
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments).anyTimes();
comment = EasyMock.newCapture();
EasyMock.expect(eventCommentService.updateComment(EasyMock.capture(comment))).andReturn(EventComment.create(Option.option(17L), 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());
assertEquals(true, comment.getValue().isResolvedStatus());
// Test resolve with no comment
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
// Test delete with no result, no delete
eventCommentService = EasyMock.createMock(EventCommentService.class);
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(new ArrayList<EventComment>()).anyTimes();
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
// Test delete with result
eventCommentService = EasyMock.createMock(EventCommentService.class);
comments = new ArrayList<EventComment>();
comments.add(EventComment.create(Option.option(deleteCommentId), mediaPackageId, org.getId(), description, creator, reason, false));
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments).anyTimes();
eventCommentService.deleteComment(deleteCommentId);
EasyMock.expectLastCall();
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
// Test delete with unrelated comments
eventCommentService = EasyMock.createMock(EventCommentService.class);
comments = new ArrayList<EventComment>();
comments.add(EventComment.create(Option.option(35L), mediaPackageId, org.getId(), description, creator, "", false));
comments.add(EventComment.create(Option.option(37L), mediaPackageId, org.getId(), "Different Description", creator, reason, false));
comments.add(EventComment.create(Option.option(39L), mediaPackageId, org.getId(), description, creator, "Different Reason", false));
EasyMock.expect(eventCommentService.getComments(mediaPackageId)).andReturn(comments).anyTimes();
EasyMock.replay(eventCommentService);
commentWorkflowOperationHandler = new CommentWorkflowOperationHandler();
commentWorkflowOperationHandler.setEventCommentService(eventCommentService);
commentWorkflowOperationHandler.setSecurityService(secSrv);
commentWorkflowOperationHandler.start(workflowInstance, null);
}
use of org.opencastproject.event.comment.EventCommentService in project opencast by opencast.
the class CommentSchedulerConflictNotifierTest method testCommentSchedulerConflict.
@Test
public void testCommentSchedulerConflict() throws Exception {
Set<String> userIds = new HashSet<>();
userIds.add("user1");
userIds.add("user2");
Map<String, String> caProperties = new HashMap<String, String>();
caProperties.put("test", "true");
caProperties.put("clear", "all");
Map<String, String> wfProperties = new HashMap<String, String>();
wfProperties.put("test", "false");
wfProperties.put("skip", "true");
final String mpId = "1234";
final TechnicalMetadata technicalMetadata = new TechnicalMetadataImpl(mpId, "demo", new Date(), new Date(new Date().getTime() + 10 * 60 * 1000), false, userIds, wfProperties, caProperties, null);
final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mp.setIdentifier(new IdImpl(mpId));
mp.add(DublinCores.mkOpencastEpisode().getCatalog());
DublinCoreCatalog extendedEvent = DublinCores.mkStandard();
extendedEvent.setFlavor(new MediaPackageElementFlavor("extended", "episode"));
mp.add(extendedEvent);
final SchedulerEvent schedulerEvent = EasyMock.createNiceMock(SchedulerEvent.class);
EasyMock.expect(schedulerEvent.getTechnicalMetadata()).andReturn(technicalMetadata).anyTimes();
EasyMock.expect(schedulerEvent.getMediaPackage()).andReturn(mp).anyTimes();
EasyMock.expect(schedulerEvent.getEventId()).andReturn(mpId).anyTimes();
EasyMock.expect(schedulerEvent.getVersion()).andReturn("2").anyTimes();
EasyMock.replay(schedulerEvent);
ConflictingEvent conflictingEvent = EasyMock.createNiceMock(ConflictingEvent.class);
EasyMock.expect(conflictingEvent.getOldEvent()).andReturn(schedulerEvent).anyTimes();
EasyMock.expect(conflictingEvent.getNewEvent()).andReturn(schedulerEvent).anyTimes();
EasyMock.expect(conflictingEvent.getConflictStrategy()).andReturn(Strategy.NEW).anyTimes();
EasyMock.replay(conflictingEvent);
List<ConflictingEvent> conflicts = new ArrayList<>();
conflicts.add(conflictingEvent);
EventCommentService eventCommentService = EasyMock.createNiceMock(EventCommentService.class);
EasyMock.expect(eventCommentService.updateComment(EasyMock.anyObject(EventComment.class))).andReturn(null).once();
EasyMock.replay(eventCommentService);
conflictNotifier.setEventCommentService(eventCommentService);
conflictNotifier.notifyConflicts(conflicts);
EasyMock.verify(eventCommentService);
}
use of org.opencastproject.event.comment.EventCommentService 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());
}
Aggregations