use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class DefaultsWorkflowOperationHandlerTest method setupInstance.
/**
* Setup a workflow instance to test the preset values.
*
* @param organization
* The {@link Organization} to use to get presets.
* @param seriesID
* The series id to get the presets.
* @param workflowConfiguration
* A workflow configuration to get the workflow keys and values.
* @param provideEventValue
* Whether to provide an event level value for the key
* @return A {@link WorkflowInstance} ready to run a test of {@link DefaultsWorkflowOperationHandler}
*/
private WorkflowInstance setupInstance(Organization organization, String seriesID, Map<String, String> workflowConfiguration, boolean provideEventValue) {
WorkflowOperationInstance operation = EasyMock.createMock(WorkflowOperationInstance.class);
EasyMock.expect(operation.getConfigurationKeys()).andReturn(workflowConfiguration.keySet());
EasyMock.expect(operation.getConfiguration(OPT_KEY)).andReturn(WORKFLOW_PRESET_VALUE);
EasyMock.replay(operation);
MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
EasyMock.expect(mediaPackage.getSeries()).andReturn(seriesID);
EasyMock.replay(mediaPackage);
WorkflowInstance workflowInstance = EasyMock.createMock(WorkflowInstance.class);
EasyMock.expect(workflowInstance.getId()).andReturn(1L).anyTimes();
EasyMock.expect(workflowInstance.getCurrentOperation()).andReturn(operation).anyTimes();
EasyMock.expect(workflowInstance.getOrganization()).andReturn(organization).anyTimes();
EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
if (provideEventValue) {
EasyMock.expect(workflowInstance.getConfiguration(OPT_KEY)).andReturn(EVENT_PRESET_VALUE);
} else {
EasyMock.expect(workflowInstance.getConfiguration(OPT_KEY)).andReturn(null);
}
EasyMock.replay(workflowInstance);
return workflowInstance;
}
use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class ZipWorkflowOperationHandlerTest method testInvalidMediaPackage.
/*
* MH-9759
*/
@Test
public void testInvalidMediaPackage() throws Exception {
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(null);
operation.setConfiguration(ZipWorkflowOperationHandler.ZIP_COLLECTION_PROPERTY, "failed-zips");
operation.setConfiguration(ZipWorkflowOperationHandler.INCLUDE_FLAVORS_PROPERTY, "*/source,dublincore/*");
operation.setConfiguration(ZipWorkflowOperationHandler.TARGET_FLAVOR_PROPERTY, "archive/zip");
operation.setConfiguration(ZipWorkflowOperationHandler.COMPRESS_PROPERTY, "false");
try {
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.fail("A null mediapackage is passed so an exception should be thrown");
} catch (WorkflowOperationException e) {
// expecting exception
}
}
use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class ZipWorkflowOperationHandlerTest method testConfigKeyTargetFlavorDefaultValue.
/*
* MH-10043
*/
@Test
public void testConfigKeyTargetFlavorDefaultValue() {
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
instance.setMediaPackage(mp);
operation.setConfiguration(ZipWorkflowOperationHandler.ZIP_COLLECTION_PROPERTY, "failed-zips");
operation.setConfiguration(ZipWorkflowOperationHandler.INCLUDE_FLAVORS_PROPERTY, "*/source,dublincore/*");
// targe-flavor is not mandatory
// operation.setConfiguration(ZipWorkflowOperationHandler.TARGET_FLAVOR_PROPERTY, "archive/zip");
operation.setConfiguration(ZipWorkflowOperationHandler.COMPRESS_PROPERTY, "false");
try {
WorkflowOperationResult result = operationHandler.start(instance, null);
Assert.assertEquals("workflow result action not CONTINUE: " + result.getAction(), WorkflowOperationResult.Action.CONTINUE, result.getAction());
} catch (WorkflowOperationException e) {
Assert.fail("missing target-flavor and no default value kicked in: " + e);
}
}
use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class ZipWorkflowOperationHandlerTest method testInvalidWorkflow.
/*
* MH-9757
*/
@Test
public void testInvalidWorkflow() throws Exception {
WorkflowInstanceImpl instance = new WorkflowInstanceImpl();
List<WorkflowOperationInstance> ops = new ArrayList<WorkflowOperationInstance>();
WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("test", OperationState.INSTANTIATED);
ops.add(operation);
instance.setOperations(ops);
operation.setConfiguration(ZipWorkflowOperationHandler.ZIP_COLLECTION_PROPERTY, "failed-zips");
operation.setConfiguration(ZipWorkflowOperationHandler.INCLUDE_FLAVORS_PROPERTY, "*/source,dublincore/*");
operation.setConfiguration(ZipWorkflowOperationHandler.TARGET_FLAVOR_PROPERTY, "archive/zip");
operation.setConfiguration(ZipWorkflowOperationHandler.COMPRESS_PROPERTY, "false");
try {
WorkflowOperationResult result = operationHandler.start(null, null);
Assert.fail("A null workflow is passed so an exception should be thrown");
} catch (WorkflowOperationException e) {
// expecting exception
}
}
use of org.opencastproject.workflow.api.WorkflowOperationInstance in project opencast by opencast.
the class IncidentCreatorWorkflowOperationHandler method start.
@Override
public WorkflowOperationResult start(WorkflowInstance wi, JobContext ctx) throws WorkflowOperationException {
final WorkflowOperationInstance woi = wi.getCurrentOperation();
final int code = option(woi.getConfiguration(OPT_CODE)).bind(Strings.toInt).getOrElse(1);
final Severity severity = option(woi.getConfiguration(OPT_SEVERITY)).bind(parseEnum(Severity.FAILURE)).getOrElse(Severity.INFO);
final List<Tuple<String, String>> details = option(woi.getConfiguration(OPT_DETAILS)).mlist().bind(splitBy(";")).map(splitBy("=")).filter(Tuples.<String>listHasSize(2)).map(Tuples.<String>fromList()).value();
final Map<String, String> params = Immutables.map(option(woi.getConfiguration(OPT_PARAMS)).mlist().bind(splitBy(";")).map(splitBy("=")).filter(Tuples.<String>listHasSize(2)).map(Tuples.<String>fromList()).value());
log.info("Create nop job");
final Job job = nopService.nop();
log.info("Log a dummy incident with code %d", code);
serviceRegistry.incident().record(job, severity, code, params, details);
if (!waitForStatus(job).isSuccess()) {
throw new WorkflowOperationException("Job did not complete successfully");
} else {
return createResult(WorkflowOperationResult.Action.CONTINUE);
}
}
Aggregations