Search in sources :

Example 1 with HandlerRegistration

use of org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration in project opencast by opencast.

the class HoldStateTest 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 = CountWorkflowsTest.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.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).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);
    ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    dao = new WorkflowServiceSolrIndex();
    dao.solrRoot = sRoot + File.separator + "solr";
    dao.setServiceRegistry(serviceRegistry);
    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);
    serviceRegistry.registerService(service);
    is = HoldStateTest.class.getResourceAsStream("/workflow-definition-holdstate.xml");
    def = WorkflowParser.parseWorkflowDefinition(is);
    IOUtils.closeQuietly(is);
    service.registerWorkflowDefinition(def);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) 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)

Example 2 with HandlerRegistration

use of org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration in project opencast by opencast.

the class PauseFinalOperationTest 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 = PauseFinalOperationTest.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>();
    handler = new ResumableTestWorkflowOperationHandler();
    handlerRegistrations.add(new HandlerRegistration("op1", handler));
    // 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 defaultOrganization = new DefaultOrganization();
    securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(defaultOrganization).anyTimes();
    EasyMock.replay(securityService);
    service.setSecurityService(securityService);
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    EasyMock.expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
    EasyMock.replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    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);
    List<Organization> organizationList = new ArrayList<Organization>();
    organizationList.add(defaultOrganization);
    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);
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
    EasyMock.replay(workspace);
    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.setMessageSender(messageSender);
    service.activate(null);
    service.setServiceRegistry(serviceRegistry);
    is = PauseFinalOperationTest.class.getResourceAsStream("/workflow-definition-pause-last.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) 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) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 3 with HandlerRegistration

use of org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration in project opencast by opencast.

the class WorkflowStatisticsTest method setUp.

@Before
public void setUp() throws Exception {
    // always start with a fresh solr root directory
    sRoot = new File(getStorageRoot());
    try {
        FileUtils.forceMkdir(sRoot);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    workflowDefinitions = new ArrayList<WorkflowDefinition>();
    workflowHandlers = new HashSet<HandlerRegistration>();
    String opId = "op";
    WorkflowOperationDefinition op = new WorkflowOperationDefinitionImpl(opId, "Pausing operation", null, true);
    WorkflowOperationHandler opHandler = new ResumableTestWorkflowOperationHandler(opId, Action.PAUSE, Action.CONTINUE);
    HandlerRegistration handler = new HandlerRegistration(opId, opHandler);
    workflowHandlers.add(handler);
    // create operation handlers for our workflows
    for (int i = 1; i <= WORKFLOW_DEFINITION_COUNT; i++) {
        WorkflowDefinition workflowDef = new WorkflowDefinitionImpl();
        workflowDef.setId("def-" + i);
        for (int opCount = 1; opCount <= OPERATION_COUNT; opCount++) {
            workflowDef.add(op);
        }
        workflowDefinitions.add(workflowDef);
    }
    // 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 workflowHandlers;
        }
    };
    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.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    service.setMessageSender(messageSender);
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    // Register the workflow definitions
    for (WorkflowDefinition workflowDefinition : workflowDefinitions) {
        service.registerWorkflowDefinition(workflowDefinition);
    }
    // Mock the workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
    EasyMock.replay(workspace);
    // Mock the service registry
    ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    // Create the workflow database (solr)
    dao = new WorkflowServiceSolrIndex();
    dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
    dao.setSecurityService(securityService);
    dao.setServiceRegistry(serviceRegistry);
    dao.setAuthorizationService(authzService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.activate("System Admin");
    service.setDao(dao);
    service.setServiceRegistry(serviceRegistry);
    service.setSecurityService(securityService);
    service.activate(null);
    // Crate a media package
    InputStream is = null;
    try {
        MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
        mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
        is = WorkflowStatisticsTest.class.getResourceAsStream("/mediapackage-1.xml");
        mediaPackage = mediaPackageBuilder.loadFromXml(is);
        IOUtils.closeQuietly(is);
        Assert.assertNotNull(mediaPackage.getIdentifier());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    // Register the workflow service with the service registry
    serviceRegistry.registerService(service);
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) 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) WorkflowOperationHandler(org.opencastproject.workflow.api.WorkflowOperationHandler) ServiceRegistryInMemoryImpl(org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl) HandlerRegistration(org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) InputStream(java.io.InputStream) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowOperationDefinition(org.opencastproject.workflow.api.WorkflowOperationDefinition) IOException(java.io.IOException) IOException(java.io.IOException) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) 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)

Example 4 with HandlerRegistration

use of org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration in project opencast by opencast.

the class WorkflowOperationSkippingTest method setUp.

@Before
public void setUp() throws Exception {
    sRoot = new File(getStorageRoot());
    try {
        FileUtils.forceMkdir(sRoot);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    // create operation handlers for our workflows
    succeedingOperationHandler = new SucceedingWorkflowOperationHandler(mediapackage1);
    handlerRegistrations = new HashSet<HandlerRegistration>();
    handlerRegistrations.add(new HandlerRegistration("op1", succeedingOperationHandler));
    handlerRegistrations.add(new HandlerRegistration("op2", succeedingOperationHandler));
    // 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);
    MediaPackageMetadataService mds = EasyMock.createNiceMock(MediaPackageMetadataService.class);
    EasyMock.replay(mds);
    service.addMetadataService(mds);
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
    EasyMock.replay(workspace);
    // security service
    SecurityService 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);
    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.getOrganizations()).andReturn(organizationList).anyTimes();
    EasyMock.expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(organization).anyTimes();
    EasyMock.replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    ServiceRegistryInMemoryImpl serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, EasyMock.createNiceMock(IncidentService.class));
    dao = new WorkflowServiceSolrIndex();
    dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
    MessageSender messageSender = EasyMock.createNiceMock(MessageSender.class);
    EasyMock.replay(messageSender);
    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);
    dao.setServiceRegistry(serviceRegistry);
    dao.setSecurityService(securityService);
    dao.setAuthorizationService(authzService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.activate("System Admin");
    service.setDao(dao);
    service.setServiceRegistry(serviceRegistry);
    service.setMessageSender(messageSender);
    service.setUserDirectoryService(userDirectoryService);
    service.activate(null);
    InputStream is = null;
    try {
        is = WorkflowOperationSkippingTest.class.getResourceAsStream("/workflow-definition-skipping.xml");
        workingDefinition = WorkflowParser.parseWorkflowDefinition(is);
        service.registerWorkflowDefinition(workingDefinition);
        IOUtils.closeQuietly(is);
        MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
        mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
        is = WorkflowOperationSkippingTest.class.getResourceAsStream("/mediapackage-1.xml");
        mediapackage1 = mediaPackageBuilder.loadFromXml(is);
        IOUtils.closeQuietly(is);
        Assert.assertNotNull(mediapackage1.getIdentifier());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) 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) 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) HandlerRegistration(org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration) InputStream(java.io.InputStream) IOException(java.io.IOException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) 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) Workspace(org.opencastproject.workspace.api.Workspace) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) OrganizationDirectoryService(org.opencastproject.security.api.OrganizationDirectoryService) Before(org.junit.Before)

Example 5 with HandlerRegistration

use of org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration in project opencast by opencast.

the class WorkflowServiceImplTest method setUp.

@Before
public void setUp() throws Exception {
    // always start with a fresh solr root directory
    sRoot = new File(getStorageRoot());
    try {
        FileUtils.forceMkdir(sRoot);
    } catch (IOException e) {
        Assert.fail(e.getMessage());
    }
    // create operation handlers for our workflows
    succeedingOperationHandler = new SucceedingWorkflowOperationHandler();
    failingOperationHandler = new FailingWorkflowOperationHandler();
    handlerRegistrations = new HashSet<HandlerRegistration>();
    handlerRegistrations.add(new HandlerRegistration("op1", succeedingOperationHandler));
    handlerRegistrations.add(new HandlerRegistration("op2", succeedingOperationHandler));
    handlerRegistrations.add(new HandlerRegistration("op3", failingOperationHandler));
    handlerRegistrations.add(new HandlerRegistration(WorkflowServiceImpl.ERROR_RESOLUTION_HANDLER_ID, new ErrorResolutionWorkflowOperationHandler()));
    handlerRegistrations.add(new HandlerRegistration("opPause", new ResumableTestWorkflowOperationHandler()));
    handlerRegistrations.add(new HandlerRegistration("failOnHost", new FailOnHostWorkflowOperationHandler()));
    handlerRegistrations.add(new HandlerRegistration("failOneTime", new FailOnceWorkflowOperationHandler()));
    handlerRegistrations.add(new HandlerRegistration("failTwice", new FailTwiceWorkflowOperationHandler()));
    scanner = new WorkflowDefinitionScanner();
    // 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;
        }
    };
    // Add scanner to activate workflow service and store definitions
    service.addWorkflowDefinitionScanner(scanner);
    // security service
    DefaultOrganization organization = new DefaultOrganization();
    securityService = createNiceMock(SecurityService.class);
    expect(securityService.getUser()).andReturn(SecurityServiceStub.DEFAULT_ORG_ADMIN).anyTimes();
    expect(securityService.getOrganization()).andReturn(organization).anyTimes();
    replay(securityService);
    service.setSecurityService(securityService);
    UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class);
    expect(userDirectoryService.loadUser((String) EasyMock.anyObject())).andReturn(DEFAULT_ORG_ADMIN).anyTimes();
    replay(userDirectoryService);
    service.setUserDirectoryService(userDirectoryService);
    AuthorizationService authzService = createNiceMock(AuthorizationService.class);
    expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    replay(authzService);
    service.setAuthorizationService(authzService);
    List<Organization> organizationList = new ArrayList<Organization>();
    organizationList.add(organization);
    OrganizationDirectoryService organizationDirectoryService = EasyMock.createMock(OrganizationDirectoryService.class);
    expect(organizationDirectoryService.getOrganization((String) EasyMock.anyObject())).andReturn(securityService.getOrganization()).anyTimes();
    expect(organizationDirectoryService.getOrganizations()).andReturn(organizationList).anyTimes();
    replay(organizationDirectoryService);
    service.setOrganizationDirectoryService(organizationDirectoryService);
    MediaPackageMetadataService mds = createNiceMock(MediaPackageMetadataService.class);
    replay(mds);
    service.addMetadataService(mds);
    workspace = createNiceMock(Workspace.class);
    expect(workspace.getCollectionContents((String) EasyMock.anyObject())).andReturn(new URI[0]);
    replay(workspace);
    IncidentService incidentService = createNiceMock(IncidentService.class);
    replay(incidentService);
    serviceRegistry = new ServiceRegistryInMemoryImpl(service, securityService, userDirectoryService, organizationDirectoryService, incidentService);
    serviceRegistry.registerHost(REMOTE_HOST, REMOTE_HOST, Runtime.getRuntime().totalMemory(), Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors());
    serviceRegistry.registerService(REMOTE_SERVICE, REMOTE_HOST, "/path", true);
    service.setWorkspace(workspace);
    MessageSender messageSender = createNiceMock(MessageSender.class);
    replay(messageSender);
    dao = new WorkflowServiceSolrIndex();
    dao.setServiceRegistry(serviceRegistry);
    dao.setSecurityService(securityService);
    dao.setOrgDirectory(organizationDirectoryService);
    dao.setAuthorizationService(authzService);
    dao.solrRoot = sRoot + File.separator + "solr." + System.currentTimeMillis();
    dao.activate("System Admin");
    service.setDao(dao);
    service.setServiceRegistry(serviceRegistry);
    service.setMessageSender(messageSender);
    service.activate(null);
    InputStream is = null;
    try {
        is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-1.xml");
        workingDefinition = WorkflowParser.parseWorkflowDefinition(is);
        IOUtils.closeQuietly(is);
        is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-2.xml");
        failingDefinitionWithoutErrorHandler = WorkflowParser.parseWorkflowDefinition(is);
        IOUtils.closeQuietly(is);
        is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-3.xml");
        failingDefinitionWithErrorHandler = WorkflowParser.parseWorkflowDefinition(is);
        IOUtils.closeQuietly(is);
        is = WorkflowServiceImplTest.class.getResourceAsStream("/workflow-definition-4.xml");
        pausingWorkflowDefinition = WorkflowParser.parseWorkflowDefinition(is);
        IOUtils.closeQuietly(is);
        service.registerWorkflowDefinition(workingDefinition);
        service.registerWorkflowDefinition(failingDefinitionWithoutErrorHandler);
        service.registerWorkflowDefinition(failingDefinitionWithErrorHandler);
        service.registerWorkflowDefinition(pausingWorkflowDefinition);
        MediaPackageBuilder mediaPackageBuilder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
        mediaPackageBuilder.setSerializer(new DefaultMediaPackageSerializerImpl(new File("target/test-classes")));
        is = WorkflowServiceImplTest.class.getResourceAsStream("/mediapackage-1.xml");
        mediapackage1 = mediaPackageBuilder.loadFromXml(is);
        IOUtils.closeQuietly(is);
        is = WorkflowServiceImplTest.class.getResourceAsStream("/mediapackage-2.xml");
        mediapackage2 = mediaPackageBuilder.loadFromXml(is);
        Assert.assertNotNull(mediapackage1.getIdentifier());
        Assert.assertNotNull(mediapackage2.getIdentifier());
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
}
Also used : IncidentService(org.opencastproject.serviceregistry.api.IncidentService) Set(java.util.Set) HashSet(java.util.HashSet) WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) 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) HandlerRegistration(org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration) InputStream(java.io.InputStream) IOException(java.io.IOException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) NotFoundException(org.opencastproject.util.NotFoundException) ConfigurationException(org.opencastproject.util.ConfigurationException) IOException(java.io.IOException) UserDirectoryService(org.opencastproject.security.api.UserDirectoryService) AuthorizationService(org.opencastproject.security.api.AuthorizationService) ErrorResolutionWorkflowOperationHandler(org.opencastproject.workflow.handler.workflow.ErrorResolutionWorkflowOperationHandler) 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

HandlerRegistration (org.opencastproject.workflow.impl.WorkflowServiceImpl.HandlerRegistration)8 File (java.io.File)7 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 Set (java.util.Set)7 Before (org.junit.Before)7 DefaultMediaPackageSerializerImpl (org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl)7 MediaPackage (org.opencastproject.mediapackage.MediaPackage)7 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)7 MessageSender (org.opencastproject.message.broker.api.MessageSender)7 MediaPackageMetadataService (org.opencastproject.metadata.api.MediaPackageMetadataService)7 AuthorizationService (org.opencastproject.security.api.AuthorizationService)7 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)7 Organization (org.opencastproject.security.api.Organization)7 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)7 SecurityService (org.opencastproject.security.api.SecurityService)7 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)7 ServiceRegistryInMemoryImpl (org.opencastproject.serviceregistry.api.ServiceRegistryInMemoryImpl)7