Search in sources :

Example 26 with IdImpl

use of org.opencastproject.mediapackage.identifier.IdImpl in project opencast by opencast.

the class ConfigurablePublishWorkflowOperationHandlerTest method testTemplateReplacement.

@Test
public void testTemplateReplacement() throws WorkflowOperationException, URISyntaxException {
    URI elementUri = new URI("http://element.com/path/to/element/element.mp4");
    String mpId = "mp-id";
    String pubUUID = "test-uuid";
    String seriesId = "series-id";
    MediaPackage mp = EasyMock.createNiceMock(MediaPackage.class);
    Id id = new IdImpl(mpId);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    MediaPackageElement element = EasyMock.createNiceMock(MediaPackageElement.class);
    EasyMock.expect(element.getURI()).andStubReturn(elementUri);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andStubReturn(org);
    EasyMock.replay(element, mp, securityService);
    // Test player path and mediapackage id
    ConfigurablePublishWorkflowOperationHandler configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    URI result = configurePublish.populateUrlWithVariables("${player_path}${event_id}", mp, pubUUID);
    assertEquals(examplePlayer + "mp-id", result.toString());
    // Test without series
    configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    result = configurePublish.populateUrlWithVariables("${series_id}/${event_id}", mp, pubUUID);
    assertEquals("/mp-id", result.toString());
    // Test with series
    mp = EasyMock.createNiceMock(MediaPackage.class);
    EasyMock.expect(mp.getIdentifier()).andStubReturn(id);
    EasyMock.expect(mp.getSeries()).andStubReturn(seriesId);
    EasyMock.replay(mp);
    configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    result = configurePublish.populateUrlWithVariables("${series_id}/${event_id}", mp, pubUUID);
    assertEquals("series-id/mp-id", result.toString());
    // Test publication uuid
    configurePublish = new ConfigurablePublishWorkflowOperationHandler();
    configurePublish.setSecurityService(securityService);
    result = configurePublish.populateUrlWithVariables("${publication_id}", mp, pubUUID);
    assertEquals(pubUUID, result.toString());
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Test(org.junit.Test)

Example 27 with IdImpl

use of org.opencastproject.mediapackage.identifier.IdImpl 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());
}
Also used : Organization(org.opencastproject.security.api.Organization) User(org.opencastproject.security.api.User) ArrayList(java.util.ArrayList) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) EventComment(org.opencastproject.event.comment.EventComment) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) EventCommentService(org.opencastproject.event.comment.EventCommentService) Test(org.junit.Test)

Example 28 with IdImpl

use of org.opencastproject.mediapackage.identifier.IdImpl in project opencast by opencast.

the class EmailSchedulerConflictNotifierTest method testEmailSchedulerConflict.

@Test
public void testEmailSchedulerConflict() 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);
    final Integer[] counter = new Integer[1];
    counter[0] = 0;
    SmtpService smtpService = new SmtpService() {

        @Override
        public void send(MimeMessage message) throws MessagingException {
            counter[0]++;
        }
    };
    conflictNotifier.setSmtpService(smtpService);
    conflictNotifier.notifyConflicts(conflicts);
    Assert.assertEquals(1, counter[0].intValue());
}
Also used : ConflictingEvent(org.opencastproject.scheduler.api.ConflictingEvent) HashMap(java.util.HashMap) TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) ArrayList(java.util.ArrayList) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Date(java.util.Date) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SchedulerEvent(org.opencastproject.scheduler.api.SchedulerEvent) SmtpService(org.opencastproject.kernel.mail.SmtpService) MimeMessage(javax.mail.internet.MimeMessage) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

IdImpl (org.opencastproject.mediapackage.identifier.IdImpl)28 MediaPackage (org.opencastproject.mediapackage.MediaPackage)26 Test (org.junit.Test)21 URI (java.net.URI)13 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)12 SecurityService (org.opencastproject.security.api.SecurityService)11 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)9 Id (org.opencastproject.mediapackage.identifier.Id)9 InputStream (java.io.InputStream)8 Date (java.util.Date)7 Workspace (org.opencastproject.workspace.api.Workspace)7 Catalog (org.opencastproject.mediapackage.Catalog)6 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)6 AccessControlList (org.opencastproject.security.api.AccessControlList)6 ArrayList (java.util.ArrayList)5 Attachment (org.opencastproject.mediapackage.Attachment)5 HashMap (java.util.HashMap)4 NotFoundException (org.opencastproject.util.NotFoundException)4 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)4 HashSet (java.util.HashSet)3