use of org.opencastproject.workflow.api.WorkflowDefinitionImpl in project opencast by opencast.
the class WorkflowServiceImplTest method testRetryStrategyHoldFailureByUser.
@Test
public void testRetryStrategyHoldFailureByUser() throws Exception {
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("workflow-definition-1");
def.setTitle("workflow-definition-1");
def.setDescription("workflow-definition-1");
def.setPublished(true);
service.registerWorkflowDefinition(def);
WorkflowOperationDefinitionImpl opDef = new WorkflowOperationDefinitionImpl("failTwice", "fails twice", null, true);
opDef.setRetryStrategy(RetryStrategy.HOLD);
opDef.setMaxAttempts(3);
opDef.setFailWorkflowOnException(true);
def.add(opDef);
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
WorkflowInstance workflow = startAndWait(def, mp, WorkflowState.PAUSED);
WorkflowOperationInstance errorResolutionOperation = service.getWorkflowById(workflow.getId()).getOperations().get(0);
WorkflowOperationInstance failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(1);
Assert.assertTrue(errorResolutionOperation.getTemplate().equals(WorkflowServiceImpl.ERROR_RESOLUTION_HANDLER_ID));
Assert.assertTrue(errorResolutionOperation.getState() == OperationState.PAUSED);
Assert.assertTrue(errorResolutionOperation.getFailedAttempts() == 0);
Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
Assert.assertTrue(failTwiceOperation.getState() == OperationState.RETRY);
Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 1);
// Try operation a second time, simulate user selecting RETRY
retryAndWait(service.getWorkflowById(workflow.getId()), "RETRY", WorkflowState.PAUSED);
errorResolutionOperation = service.getWorkflowById(workflow.getId()).getOperations().get(1);
failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(2);
Assert.assertTrue(errorResolutionOperation.getTemplate().equals(WorkflowServiceImpl.ERROR_RESOLUTION_HANDLER_ID));
Assert.assertTrue(errorResolutionOperation.getState() == OperationState.PAUSED);
Assert.assertTrue(errorResolutionOperation.getFailedAttempts() == 0);
Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
Assert.assertTrue(failTwiceOperation.getState() == OperationState.RETRY);
Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 2);
// Simulate user selecting 'fail'
retryAndWait(service.getWorkflowById(workflow.getId()), "NONE", WorkflowState.FAILED);
failTwiceOperation = service.getWorkflowById(workflow.getId()).getOperations().get(2);
Assert.assertTrue("failTwice".equals(failTwiceOperation.getTemplate()));
Assert.assertTrue(failTwiceOperation.getState() == OperationState.FAILED);
Assert.assertTrue(failTwiceOperation.getMaxAttempts() == 3);
Assert.assertTrue(failTwiceOperation.getFailedAttempts() == 2);
}
use of org.opencastproject.workflow.api.WorkflowDefinitionImpl in project opencast by opencast.
the class WorkflowInstanceTest method testWorkflowFields.
@Test
public void testWorkflowFields() throws Exception {
// Workflows should obtain information from the definition used in the constructor
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.setId("123");
def.setPublished(true);
Map<String, String> props = new HashMap<String, String>();
props.put("key1", "value1");
WorkflowInstance instance = new WorkflowInstanceImpl(def, null, null, null, null, props);
Assert.assertEquals(def.getId(), instance.getTemplate());
Assert.assertEquals("value1", instance.getConfiguration("key1"));
def.setTitle("a title");
instance = new WorkflowInstanceImpl(def, null, null, null, null, null);
Assert.assertEquals(def.getTitle(), instance.getTitle());
}
use of org.opencastproject.workflow.api.WorkflowDefinitionImpl in project opencast by opencast.
the class WorkflowServiceImplAuthzTest method testWorkflowWithSecurityPolicy.
@Test
public void testWorkflowWithSecurityPolicy() throws Exception {
// Create an ACL for the authorization service to return
AccessControlList acl = new AccessControlList();
acl.getEntries().add(new AccessControlEntry("ROLE_INSTRUCTOR", Permissions.Action.READ.toString(), true));
acl.getEntries().add(new AccessControlEntry("ROLE_INSTRUCTOR", Permissions.Action.WRITE.toString(), true));
// Mock up an authorization service that always returns "true" for hasPermission()
AuthorizationService authzService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authzService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.expect(authzService.hasPermission((MediaPackage) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(true).anyTimes();
EasyMock.replay(authzService);
service.setAuthorizationService(authzService);
dao.setAuthorizationService(authzService);
// Create the workflow and its dependent object graph
WorkflowDefinitionImpl def = new WorkflowDefinitionImpl();
def.add(new WorkflowOperationDefinitionImpl("op1", "op1", null, true));
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
// As an instructor, create a workflow. We don't care if it passes or fails. We just care about access to it.
userResponder.setResponse(instructor1);
WorkflowInstance workflow = service.start(def, mp);
service.suspend(workflow.getId());
// Ensure that this instructor can access the workflow
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// Ensure the organization admin can access that workflow
userResponder.setResponse(DEFAULT_ORG_ADMIN);
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// Ensure the global admin can access that workflow
userResponder.setResponse(globalAdmin);
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// Ensure the other instructor from this organization can also see the workflow, since this is specified in the
// security policy
userResponder.setResponse(instructor2);
try {
service.getWorkflowById(workflow.getId());
assertEquals(1, service.countWorkflowInstances());
} catch (Exception e) {
fail(e.getMessage());
}
// TODO change to answer show in episode or series how to do it. Cool stuff
// Ensure the instructor from a different org can not see the workflow, even though they share the same role
organizationResponder.setResponse(otherOrganization);
userResponder.setResponse(instructorFromDifferentOrg);
try {
service.getWorkflowById(workflow.getId());
fail();
} catch (Exception e) {
// expected
}
assertEquals(0, service.countWorkflowInstances());
}
Aggregations