Search in sources :

Example 16 with WorkflowDefinitionImpl

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);
}
Also used : WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 17 with WorkflowDefinitionImpl

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());
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) HashMap(java.util.HashMap) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 18 with WorkflowDefinitionImpl

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());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) WorkflowDefinitionImpl(org.opencastproject.workflow.api.WorkflowDefinitionImpl) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Test(org.junit.Test)

Aggregations

WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)18 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)12 Test (org.junit.Test)11 MediaPackage (org.opencastproject.mediapackage.MediaPackage)10 WorkflowOperationDefinitionImpl (org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl)9 ArrayList (java.util.ArrayList)7 Before (org.junit.Before)7 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)7 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)7 URI (java.net.URI)5 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)5 HashMap (java.util.HashMap)4 File (java.io.File)3 InputStream (java.io.InputStream)3 Set (java.util.Set)3 AuthorizationService (org.opencastproject.security.api.AuthorizationService)3 WorkflowDefinition (org.opencastproject.workflow.api.WorkflowDefinition)3 WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Date (java.util.Date)2