Search in sources :

Example 21 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowServiceImplTest method testGetWorkflowByEpisodeId.

@Test
public void testGetWorkflowByEpisodeId() throws Exception {
    String mediaPackageId = mediapackage1.getIdentifier().toString();
    // Ensure that the database doesn't have a workflow instance with this episode
    Assert.assertEquals(0, service.countWorkflowInstances());
    Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withMediaPackage(mediaPackageId)).size());
    startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    WorkflowSet workflowsInDb = service.getWorkflowInstances(new WorkflowQuery().withMediaPackage(mediaPackageId));
    Assert.assertEquals(1, workflowsInDb.getItems().length);
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) Test(org.junit.Test)

Example 22 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowServiceImplTest method testGetWorkflowByCreator.

@Test
public void testGetWorkflowByCreator() throws Exception {
    // Set different creators in the mediapackages
    String manfred = "Dr. Manfred Frisch";
    mediapackage1.addCreator(manfred);
    mediapackage2.addCreator("Somebody else");
    // Ensure that the database doesn't have any workflow instances with media packages with this creator
    Assert.assertEquals(0, service.countWorkflowInstances());
    WorkflowInstance instance1 = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    WorkflowInstance instance2 = startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
    Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance1.getId()).getState());
    Assert.assertEquals(WorkflowState.SUCCEEDED, service.getWorkflowById(instance2.getId()).getState());
    // Build the workflow query
    WorkflowQuery queryForManfred = new WorkflowQuery().withCreator(manfred);
    Assert.assertEquals(1, service.getWorkflowInstances(queryForManfred).getTotalCount());
    Assert.assertEquals(instance1.getMediaPackage().getIdentifier().toString(), service.getWorkflowInstances(queryForManfred).getItems()[0].getMediaPackage().getIdentifier().toString());
}
Also used : WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Example 23 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowServiceImplTest method testGetWorkflowByText.

@Test
public void testGetWorkflowByText() throws Exception {
    // Ensure that the database doesn't have any workflow instances
    Assert.assertEquals(0, service.countWorkflowInstances());
    Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withText("Climate").withCount(100).withStartPage(0)).size());
    startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    WorkflowSet workflowsInDb = service.getWorkflowInstances(new WorkflowQuery().withText("Climate").withCount(100).withStartPage(0));
    Assert.assertEquals(1, workflowsInDb.getItems().length);
    Assert.assertEquals(1, service.getWorkflowInstances(new WorkflowQuery().withText("limate")).size());
    Assert.assertEquals(1, service.getWorkflowInstances(new WorkflowQuery().withText("mate")).size());
    Assert.assertEquals(1, service.getWorkflowInstances(new WorkflowQuery().withText("lima")).size());
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) Test(org.junit.Test)

Example 24 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowServiceImplTest method testGetWorkflowByCurrentOperation.

@Test
public void testGetWorkflowByCurrentOperation() throws Exception {
    // Ensure that the database doesn't have a workflow instance in the "opPause" operation
    Assert.assertEquals(0, service.countWorkflowInstances());
    Assert.assertEquals(0, service.getWorkflowInstances(new WorkflowQuery().withCurrentOperation("opPause")).size());
    startAndWait(pausingWorkflowDefinition, mediapackage1, WorkflowState.PAUSED);
    WorkflowSet workflowsInDb = service.getWorkflowInstances(new WorkflowQuery().withCurrentOperation("opPause"));
    Assert.assertEquals(1, workflowsInDb.getItems().length);
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) Test(org.junit.Test)

Example 25 with WorkflowQuery

use of org.opencastproject.workflow.api.WorkflowQuery in project opencast by opencast.

the class WorkflowServiceImplTest method testCleanupWorkflowInstances.

/**
 * Test for {@link WorkflowServiceImpl#cleanupWorkflowInstances(int, WorkflowState)}
 *
 * @throws Exception
 *           if anything fails
 */
@Test
public void testCleanupWorkflowInstances() throws Exception {
    WorkflowInstance wi1 = startAndWait(workingDefinition, mediapackage1, WorkflowState.SUCCEEDED);
    startAndWait(workingDefinition, mediapackage2, WorkflowState.SUCCEEDED);
    // reload instances, because operations have no id before
    wi1 = service.getWorkflowById(wi1.getId());
    service.cleanupWorkflowInstances(0, WorkflowState.FAILED);
    assertEquals(2, service.getWorkflowInstances(new WorkflowQuery()).size());
    service.cleanupWorkflowInstances(0, WorkflowState.SUCCEEDED);
    assertEquals(0, service.getWorkflowInstances(new WorkflowQuery()).size());
    for (WorkflowOperationInstance op : wi1.getOperations()) {
        assertEquals(0, serviceRegistry.getChildJobs(op.getId()).size());
    }
}
Also used : WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Test(org.junit.Test)

Aggregations

WorkflowQuery (org.opencastproject.workflow.api.WorkflowQuery)30 WorkflowSet (org.opencastproject.workflow.api.WorkflowSet)18 Test (org.junit.Test)17 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)16 NotFoundException (org.opencastproject.util.NotFoundException)9 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)8 ArrayList (java.util.ArrayList)5 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)5 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)4 WorkflowParsingException (org.opencastproject.workflow.api.WorkflowParsingException)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Organization (org.opencastproject.security.api.Organization)3 User (org.opencastproject.security.api.User)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 WorkflowException (org.opencastproject.workflow.api.WorkflowException)3 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)3 IOException (java.io.IOException)2