Search in sources :

Example 61 with Workflow

use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImpl method retrieveUncompletedWorkflowsByType.

@Override
public List<Workflow> retrieveUncompletedWorkflowsByType(String type) throws APIManagementException {
    if (log.isDebugEnabled()) {
        log.debug("Requesting for uncompleted workflow information for type: " + type);
    }
    if (type == null) {
        String message = "Error while retrieving workflow information. Missing workflow type";
        log.error(message);
        throw new APIManagementException(message, ExceptionCodes.WORKFLOW_RETRIEVE_EXCEPTION);
    }
    try {
        return workflowDAO.retrieveUncompleteWorkflows(type);
    } catch (APIMgtDAOException e) {
        String message = "Error while retrieving workflow information";
        log.error(message, e);
        throw new APIManagementException(message, ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Example 62 with Workflow

use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.

the class WorkflowDAOIT method testGetExternalWorkflowReferenceForAPIStateChange.

@Test
public void testGetExternalWorkflowReferenceForAPIStateChange() throws Exception {
    WorkflowDAO workflowDAO = DAOFactory.getWorkflowDAO();
    String workflowExtRefId = UUID.randomUUID().toString();
    String apiId = UUID.randomUUID().toString();
    Workflow workflow = SampleTestObjectCreator.createWorkflow(workflowExtRefId);
    workflow.setWorkflowReference(apiId);
    workflow.setStatus(WorkflowStatus.CREATED);
    workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_API_STATE);
    workflowDAO.addWorkflowEntry(workflow);
    Optional<String> externalRefFromDb = workflowDAO.getExternalWorkflowReferenceForPendingTask(apiId, WorkflowConstants.WF_TYPE_AM_API_STATE);
    if (externalRefFromDb.isPresent()) {
        Assert.assertEquals(externalRefFromDb.get(), workflowExtRefId);
    } else {
        Assert.fail("External workflow reference does not exist");
    }
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) Test(org.testng.annotations.Test)

Example 63 with Workflow

use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.

the class WorkflowDAOIT method testGetPendinExternalWorkflowReferenceForApprovedasks.

@Test
public void testGetPendinExternalWorkflowReferenceForApprovedasks() throws Exception {
    WorkflowDAO workflowDAO = DAOFactory.getWorkflowDAO();
    String workflowExtRefId = UUID.randomUUID().toString();
    String applicationId = UUID.randomUUID().toString();
    Workflow workflow = SampleTestObjectCreator.createWorkflow(workflowExtRefId);
    workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
    workflow.setWorkflowReference(applicationId);
    workflow.setStatus(WorkflowStatus.APPROVED);
    workflowDAO.addWorkflowEntry(workflow);
    Optional<String> externalRefFromDb = workflowDAO.getExternalWorkflowReferenceForPendingTask(applicationId, WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
    Assert.assertFalse(externalRefFromDb.isPresent(), "Should return only if the wf task is in CREATED state");
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) Test(org.testng.annotations.Test)

Example 64 with Workflow

use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.

the class WorkflowDAOIT method testGetExternalWorkflowReferenceForSubscription.

@Test
public void testGetExternalWorkflowReferenceForSubscription() throws Exception {
    WorkflowDAO workflowDAO = DAOFactory.getWorkflowDAO();
    String workflowExtRefId = UUID.randomUUID().toString();
    String subscriptionId = UUID.randomUUID().toString();
    Workflow workflow = SampleTestObjectCreator.createWorkflow(workflowExtRefId);
    workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
    workflow.setWorkflowReference(subscriptionId);
    workflow.setStatus(WorkflowStatus.CREATED);
    workflowDAO.addWorkflowEntry(workflow);
    Optional<String> externalRefFromDb = workflowDAO.getExternalWorkflowReferenceForPendingTask(subscriptionId, WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
    if (externalRefFromDb.isPresent()) {
        Assert.assertEquals(externalRefFromDb.get(), workflowExtRefId);
    } else {
        Assert.fail("External workflow reference does not exist");
    }
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) Test(org.testng.annotations.Test)

Example 65 with Workflow

use of org.wso2.carbon.apimgt.core.workflow.Workflow in project carbon-apimgt by wso2.

the class WorkflowDAOIT method testUpdateWorkflowStatusWithoutAddingEntry.

@Test
public void testUpdateWorkflowStatusWithoutAddingEntry() throws Exception {
    WorkflowDAO workflowDAO = DAOFactory.getWorkflowDAO();
    String workflowRefId = UUID.randomUUID().toString();
    Workflow workflow = SampleTestObjectCreator.createWorkflow(workflowRefId);
    workflow.setStatus(WorkflowStatus.APPROVED);
    workflow.setUpdatedTime(LocalDateTime.now());
    workflowDAO.updateWorkflowStatus(workflow);
    // Workflow entry should not be in the db. so exception should be thrown
    try {
        workflowDAO.retrieveWorkflow(workflow.getExternalWorkflowReference());
        // should throw exception.
        Assert.fail("Expected exception is not thrown when entry is not in the DB");
    } catch (APIMgtDAOException e) {
        Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.WORKFLOW_NOT_FOUND);
    }
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) Test(org.testng.annotations.Test)

Aggregations

Workflow (org.wso2.carbon.apimgt.core.workflow.Workflow)28 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)26 Test (org.testng.annotations.Test)24 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)22 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)19 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)16 ApplicationCreationWorkflow (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow)12 Application (org.wso2.carbon.apimgt.core.models.Application)11 HashMap (java.util.HashMap)10 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)10 WorkflowExecutor (org.wso2.carbon.apimgt.core.api.WorkflowExecutor)10 API (org.wso2.carbon.apimgt.core.models.API)9 Response (javax.ws.rs.core.Response)8 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)8 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)8 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)8 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6