Search in sources :

Example 1 with ErrorResolutionWorkflowOperationHandler

use of org.opencastproject.workflow.handler.workflow.ErrorResolutionWorkflowOperationHandler 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

File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Before (org.junit.Before)1 DefaultMediaPackageSerializerImpl (org.opencastproject.mediapackage.DefaultMediaPackageSerializerImpl)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 MessageSender (org.opencastproject.message.broker.api.MessageSender)1 MediaPackageMetadataService (org.opencastproject.metadata.api.MediaPackageMetadataService)1 AuthorizationService (org.opencastproject.security.api.AuthorizationService)1 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)1 Organization (org.opencastproject.security.api.Organization)1 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)1 SecurityService (org.opencastproject.security.api.SecurityService)1 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)1 IncidentService (org.opencastproject.serviceregistry.api.IncidentService)1