Search in sources :

Example 41 with MediaPackageBuilder

use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.

the class CleanupWorkflowOperationHandlerTest method testCreanupWOHwithoutPreservedFlavorAndWithoutDeleteExternal.

@Test
public void testCreanupWOHwithoutPreservedFlavorAndWithoutDeleteExternal() throws WorkflowOperationException, MediaPackageException {
    Map<String, String> wfInstConfig = new Hashtable<>();
    MediaPackageBuilder mpBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    MediaPackage mp = mpBuilder.createNew();
    MediaPackageElement track1 = addElementToMediaPackage(mp, MediaPackageElement.Type.Track, "presenter", "source", null);
    track1.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.COLLECTION_PATH_PREFIX, "asset", mp.getIdentifier().compact(), track1.getIdentifier(), "track.mp4"));
    cleanupWOH.start(createWorkflowInstance(wfInstConfig, mp), null);
    Assert.assertEquals("Media package shouldn't contain any elements", 0, mp.getElements().length);
    Assert.assertEquals("Delete on remote repository not allowed", 0, deletedFilesURIs.size());
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) Hashtable(java.util.Hashtable) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Test(org.junit.Test)

Example 42 with MediaPackageBuilder

use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.

the class CleanupWorkflowOperationHandlerTest method testCreanupWOHwithsomeUnknowenUrl.

@Test
public void testCreanupWOHwithsomeUnknowenUrl() throws WorkflowOperationException, MediaPackageException {
    Map<String, String> wfInstConfig = new Hashtable<>();
    MediaPackageBuilder mpBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    MediaPackage mp = mpBuilder.createNew();
    MediaPackageElement track1 = addElementToMediaPackage(mp, MediaPackageElement.Type.Track, "presenter", "source", null);
    track1.setURI(UrlSupport.uri(HOSTNAME_NODE1, "asset", "asset", mp.getIdentifier().compact(), track1.getIdentifier(), 0, "track.mp4"));
    cleanupWOH.start(createWorkflowInstance(wfInstConfig, mp), null);
    Assert.assertEquals("Media package shouldn't contain any elements", 0, mp.getElements().length);
    Assert.assertEquals("Delete on remote repository not allowed", 0, deletedFilesURIs.size());
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) Hashtable(java.util.Hashtable) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Test(org.junit.Test)

Example 43 with MediaPackageBuilder

use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.

the class CleanupWorkflowOperationHandlerTest method testCreanupWOHwithPreservedFlavorAndMediaPackagePathPrefix.

@Test
public void testCreanupWOHwithPreservedFlavorAndMediaPackagePathPrefix() throws WorkflowOperationException, MediaPackageException {
    Map<String, String> wfInstConfig = new Hashtable<>();
    wfInstConfig.put(CleanupWorkflowOperationHandler.PRESERVE_FLAVOR_PROPERTY, "*/source,smil/trimmed,security/*");
    wfInstConfig.put(CleanupWorkflowOperationHandler.DELETE_EXTERNAL, "true");
    MediaPackageBuilder mpBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    MediaPackage mp = mpBuilder.createNew();
    MediaPackageElement track1 = addElementToMediaPackage(mp, MediaPackageElement.Type.Track, "presenter", "source", null);
    track1.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX, mp.getIdentifier().compact(), track1.getIdentifier(), "track.mp4"));
    MediaPackageElement track2 = addElementToMediaPackage(mp, MediaPackageElement.Type.Track, "presentation", "work", null);
    track2.setURI(UrlSupport.uri(HOSTNAME_NODE2, WFR_URL_PREFIX, WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX, mp.getIdentifier().compact(), track2.getIdentifier(), "track.mp4"));
    MediaPackageElement att1 = addElementToMediaPackage(mp, MediaPackageElement.Type.Attachment, "presentation", "preview", null);
    att1.setURI(UrlSupport.uri(HOSTNAME_NODE2, WFR_URL_PREFIX, WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX, mp.getIdentifier().compact(), att1.getIdentifier(), "preview.png"));
    MediaPackageElement att2 = addElementToMediaPackage(mp, MediaPackageElement.Type.Attachment, "smil", "trimmed", null);
    att2.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX, mp.getIdentifier().compact(), att2.getIdentifier(), "trimmed.smil"));
    MediaPackageElement cat1 = addElementToMediaPackage(mp, MediaPackageElement.Type.Catalog, "dublincore", "episode", null);
    cat1.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX, mp.getIdentifier().compact(), cat1.getIdentifier(), "dublincore.xml"));
    MediaPackageElement cat2 = addElementToMediaPackage(mp, MediaPackageElement.Type.Catalog, "security", "xaml", null);
    cat2.setURI(UrlSupport.uri(HOSTNAME_NODE1, WFR_URL_PREFIX, WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX, mp.getIdentifier().compact(), cat2.getIdentifier(), "security.xml"));
    cleanupWOH.start(createWorkflowInstance(wfInstConfig, mp), null);
    Assert.assertEquals("Media package should contain at least tree elements", 3, mp.getElements().length);
    SimpleElementSelector elementSelector = new SimpleElementSelector();
    elementSelector.addFlavor("*/source");
    Assert.assertFalse("Media package doesn't contain an element with a preserved flavor '*/source'", elementSelector.select(mp, false).isEmpty());
    elementSelector = new SimpleElementSelector();
    elementSelector.addFlavor("smil/trimmed");
    Assert.assertFalse("Media package doesn't contain an element with a preserved flavor 'smil/trimmed'", elementSelector.select(mp, false).isEmpty());
    elementSelector = new SimpleElementSelector();
    elementSelector.addFlavor("security/*");
    Assert.assertFalse("Media package doesn't contain an element with a preserved flavor 'security/*'", elementSelector.select(mp, false).isEmpty());
    Assert.assertEquals("At least one file wasn't deleted on remote repository", 3, deletedFilesURIs.size());
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) Hashtable(java.util.Hashtable) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SimpleElementSelector(org.opencastproject.mediapackage.selector.SimpleElementSelector) Test(org.junit.Test)

Example 44 with MediaPackageBuilder

use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.

the class SilenceDetectionWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws URISyntaxException, MediaPackageException, MalformedURLException, IOException, SmilException, JAXBException, SAXException {
    MediaPackageBuilder mpBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    mpURI = SilenceDetectionWorkflowOperationHandlerTest.class.getResource("/silencedetection_mediapackage.xml").toURI();
    mp = mpBuilder.loadFromXml(mpURI.toURL().openStream());
    smilURI = SilenceDetectionWorkflowOperationHandlerTest.class.getResource("/silencedetection_smil_filled.smil").toURI();
    // create service mocks
    smilService = SmilServiceMock.createSmilServiceMock(smilURI);
    silenceDetectionServiceMock = EasyMock.createNiceMock(SilenceDetectionService.class);
    workspaceMock = EasyMock.createNiceMock(Workspace.class);
    // setup SilenceDetectionWorkflowOperationHandler
    silenceDetectionOperationHandler = new SilenceDetectionWorkflowOperationHandler();
    silenceDetectionOperationHandler.setJobBarrierPollingInterval(0);
    silenceDetectionOperationHandler.setDetectionService(silenceDetectionServiceMock);
    silenceDetectionOperationHandler.setSmilService(smilService);
    silenceDetectionOperationHandler.setWorkspace(workspaceMock);
}
Also used : SilenceDetectionService(org.opencastproject.silencedetection.api.SilenceDetectionService) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 45 with MediaPackageBuilder

use of org.opencastproject.mediapackage.MediaPackageBuilder in project opencast by opencast.

the class CountWorkflowsTest method setUp.

@Before
public void setUp() throws Exception {
    // always start with a fresh solr root directory
    sRoot = new File(getStorageRoot());
    try {
        FileUtils.deleteDirectory(sRoot);
        FileUtils.forceMkdir(sRoot);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
    InputStream is = HoldStateTest.class.getResourceAsStream("/mediapackage-1.xml");
    mp = mediaPackageBuilder.loadFromXml(is);
    IOUtils.closeQuietly(is);
    // create operation handlers for our workflows
    final Set<HandlerRegistration> handlerRegistrations = new HashSet<HandlerRegistration>();
    holdingOperationHandler = new ResumableTestWorkflowOperationHandler();
    handlerRegistrations.add(new HandlerRegistration("op1", holdingOperationHandler));
    handlerRegistrations.add(new HandlerRegistration("op2", new ContinuingWorkflowOperationHandler()));
    // instantiate a service implementation and its DAO, overriding the methods that depend on the osgi runtime
    service = new WorkflowServiceImpl() {

        @Override
        public Set<HandlerRegistration> getRegisteredHandlers() {
            return handlerRegistrations;
        }
    };
    scanner = new WorkflowDefinitionScanner();
    service.addWorkflowDefinitionScanner(scanner);
    // security service
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    EasyMock.replay(authzService);
    service.setAuthorizationService(authzService);
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    Organization organization = new DefaultOrganization();
    List<Organization> organizationList = new ArrayList<Organization>();
    organizationList.add(organization);
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    dao = new WorkflowServiceSolrIndex();
    dao.setServiceRegistry(serviceRegistry);
    dao.solrRoot = sRoot + File.separator + "solr";
    dao.setAuthorizationService(authzService);
    dao.setSecurityService(securityService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.activate("System Admin");
    service.setDao(dao);
    service.setMessageSender(messageSender);
    service.activate(null);
    service.setServiceRegistry(serviceRegistry);
    is = CountWorkflowsTest.class.getResourceAsStream("/workflow-definition-holdstate.xml");
    def = WorkflowParser.parseWorkflowDefinition(is);
    IOUtils.closeQuietly(is);
    service.registerWorkflowDefinition(def);
    serviceRegistry.registerService(service);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) MessageSender(org.opencastproject.message.broker.api.MessageSender) ArrayList(java.util.ArrayList) MediaPackageMetadataService(org.opencastproject.metadata.api.MediaPackageMetadataService) DefaultMediaPackageSerializerImpl(org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) SecurityService(org.opencastproject.security.api.SecurityService) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) HashSet(java.util.HashSet) HandlerRegistration(org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration) InputStream(java.io.InputStream) IOException(java.io.IOException) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Aggregations

MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)46 Before (org.junit.Before)35 Workspace (org.opencastproject.workspace.api.Workspace)27 URI (java.net.URI)20 File (java.io.File)18 MediaPackage (org.opencastproject.mediapackage.MediaPackage)18 ArrayList (java.util.ArrayList)15 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)13 Job (org.opencastproject.job.api.Job)11 SecurityService (org.opencastproject.security.api.SecurityService)11 InputStream (java.io.InputStream)10 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)10 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)10 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)10 IncidentService (org.opencastproject.serviceregistry.api.IncidentService)10 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)10 Date (java.util.Date)9 DefaultMediaPackageSerializerImpl (org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl)9 Organization (org.opencastproject.security.api.Organization)9 WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)9