Search in sources :

Example 66 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class TagByDublinCoreTermWOHTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    mp = builder.loadFromXml(this.getClass().getResourceAsStream("/archive_mediapackage.xml"));
    mp.getCatalog("catalog-1").setURI(this.getClass().getResource("/dublincore.xml").toURI());
    // set up the handler
    operationHandler = new TagByDublinCoreTermWOH();
    // Initialize the workflow
    instance = new WorkflowInstanceImpl();
    operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
    List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
    ops.add(operation);
    instance.setOperations(ops);
    instance.setMediaPackage(mp);
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml"));
    EasyMock.replay(workspace);
    operationHandler.setWorkspace(workspace);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 67 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class ZipWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    mp = builder.loadFromXml(this.getClass().getResourceAsStream("/archive_mediapackage.xml"));
    // set up the handler
    operationHandler = new ZipWorkflowOperationHandler();
    // set up mock workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    URI newURI = new URI("http://www.url.org");
    EasyMock.expect(workspace.put((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andReturn(newURI).anyTimes();
    EasyMock.expect(workspace.getURI((String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(newURI).anyTimes();
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(getClass().getResource("/dublincore.xml").toURI())).anyTimes();
    EasyMock.replay(workspace);
    operationHandler.setWorkspace(workspace);
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) InputStream(java.io.InputStream) URI(java.net.URI) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 68 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class CloneWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    // test resources
    URI uriMP = getClass().getResource("/clone_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    // set up mock workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    // set up service
    operationHandler = new CloneWorkflowOperationHandler();
    // Prepare file to returne from workflow
    File videoFile = new File(getClass().getResource("/av.mov").toURI());
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(videoFile).anyTimes();
    EasyMock.replay(workspace);
    operationHandler.setWorkspace(workspace);
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) URI(java.net.URI) File(java.io.File) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 69 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class VideoSegmenterTest method setUp.

/**
 * Setup for the video segmenter service, including creation of a mock workspace.
 *
 * @throws Exception
 *           if setup fails
 */
@Before
public void setUp() throws Exception {
    mpeg7Service = new Mpeg7CatalogService();
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(track.getURI()));
    tempFile = testFolder.newFile(getClass().getName() + ".xml");
    EasyMock.expect(workspace.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andAnswer(new IAnswer<URI>() {

        @Override
        public URI answer() throws Throwable {
            InputStream in = (InputStream) EasyMock.getCurrentArguments()[2];
            IOUtils.copy(in, new FileOutputStream(tempFile));
            return tempFile.toURI();
        }
    });
    EasyMock.replay(workspace);
    mpeg7Service1 = new Mpeg7CatalogService();
    Workspace workspace1 = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace1.get((URI) EasyMock.anyObject())).andReturn(new File(track1.getURI()));
    tempFile1 = testFolder.newFile(getClass().getName() + "-1.xml");
    EasyMock.expect(workspace1.putInCollection((String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (InputStream) EasyMock.anyObject())).andAnswer(new IAnswer<URI>() {

        @Override
        public URI answer() throws Throwable {
            InputStream in = (InputStream) EasyMock.getCurrentArguments()[2];
            IOUtils.copy(in, new FileOutputStream(tempFile1));
            return tempFile1.toURI();
        }
    });
    EasyMock.replay(workspace1);
    User anonymous = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole(DefaultOrganization.DEFAULT_ORGANIZATION_ANONYMOUS, new DefaultOrganization()));
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(anonymous).anyTimes();
    EasyMock.replay(userDirectoryService);
    Organization organization = new DefaultOrganization();
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(anonymous).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    EasyMock.replay(securityService);
    vsegmenter = new VideoSegmenterServiceImpl();
    serviceRegistry = new ServiceRegistryInMemoryImpl(vsegmenter, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    vsegmenter.setServiceRegistry(serviceRegistry);
    vsegmenter.setMpeg7CatalogService(mpeg7Service);
    vsegmenter.setWorkspace(workspace);
    vsegmenter.setSecurityService(securityService);
    vsegmenter.setUserDirectoryService(userDirectoryService);
    vsegmenter.setOrganizationDirectoryService(organizationDirectoryService);
    vsegmenter1 = new VideoSegmenterServiceImpl();
    serviceRegistry1 = new ServiceRegistryInMemoryImpl(vsegmenter1, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    vsegmenter1.setServiceRegistry(serviceRegistry1);
    vsegmenter1.setMpeg7CatalogService(mpeg7Service1);
    vsegmenter1.setWorkspace(workspace1);
    vsegmenter1.setSecurityService(securityService);
    vsegmenter1.setUserDirectoryService(userDirectoryService);
    vsegmenter1.setOrganizationDirectoryService(organizationDirectoryService);
    // set parameters for segmentation because the default parameters are not suitable for too short videos
    vsegmenter.prefNumber = 2;
    vsegmenter.stabilityThreshold = 2;
    vsegmenter.absoluteMin = 1;
    vsegmenter1.stabilityThreshold = 2;
    vsegmenter1.changesThreshold = 0.025f;
    vsegmenter1.prefNumber = 5;
    vsegmenter1.maxCycles = 5;
    vsegmenter1.maxError = 0.2f;
    vsegmenter1.absoluteMin = 1;
}
Also used : User(org.opencastproject.security.api.User) JaxbUser(org.opencastproject.security.api.JaxbUser) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) InputStream(java.io.InputStream) JaxbUser(org.opencastproject.security.api.JaxbUser) URI(java.net.URI) Mpeg7CatalogService(org.opencastproject.metadata.mpeg7.Mpeg7CatalogService) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 70 with Workspace

use of org.opencastproject.workspace.api.Workspace in project opencast by opencast.

the class PauseWorkflowTest 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 = PauseWorkflowTest.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>();
    firstHandler = new ResumableTestWorkflowOperationHandler();
    secondHandler = new ResumableTestWorkflowOperationHandler();
    handlerRegistrations.add(new HandlerRegistration("op1", firstHandler));
    handlerRegistrations.add(new HandlerRegistration("op2", secondHandler));
    // 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
    DefaultOrganization organization = new DefaultOrganization();
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(organization).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);
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    List<Organization> organizationList = new ArrayList<Organization>();
    organizationList.add(organization);
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    EasyMock.expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(securityService.getOrganization()).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
    EasyMock.replay(workspace);
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    dao = new WorkflowServiceSolrIndex();
    dao.setServiceRegistry(serviceRegistry);
    dao.setAuthorizationService(authzService);
    dao.solrRoot = sRoot + File.separator + "solr";
    dao.setSecurityService(securityService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.activate("System Admin");
    service.setDao(dao);
    service.setServiceRegistry(serviceRegistry);
    service.setMessageSender(messageSender);
    service.activate(null);
    is = PauseWorkflowTest.class.getResourceAsStream("/workflow-definition-pause.xml");
    def = WorkflowParser.parseWorkflowDefinition(is);
    IOUtils.closeQuietly(is);
    service.registerWorkflowDefinition(def);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) HashSet(java.util.HashSet) Set(java.util.Set) Organization(org.opencastproject.security.api.Organization) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) MessageSender(org.opencastproject.message.broker.api.MessageSender) MediaPackageMetadataService(org.opencastproject.metadata.api.MediaPackageMetadataService) ArrayList(java.util.ArrayList) 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) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Aggregations

Workspace (org.opencastproject.workspace.api.Workspace)71 Before (org.junit.Before)47 File (java.io.File)41 URI (java.net.URI)38 SecurityService (org.opencastproject.security.api.SecurityService)30 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)25 Job (org.opencastproject.job.api.Job)23 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)23 InputStream (java.io.InputStream)20 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)19 ServiceRegistry (org.opencastproject.serviceregistry.api.ServiceRegistry)18 Test (org.junit.Test)17 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)17 ArrayList (java.util.ArrayList)15 JaxbUser (org.opencastproject.security.api.JaxbUser)15 Organization (org.opencastproject.security.api.Organization)14 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)14 AuthorizationService (org.opencastproject.security.api.AuthorizationService)13 JaxbRole (org.opencastproject.security.api.JaxbRole)13