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());
}
}
Aggregations