Search in sources :

Example 6 with ApplicationCreationWorkflow

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

the class WorkflowExecutorFactory method createWorkflow.

/**
 * Create a DTO object related to a given workflow type.
 *
 * @param workflowType Type of the workflow.
 * @return WorkFlow instance
 */
public Workflow createWorkflow(String workflowType) throws APIMgtDAOException {
    Workflow workflow = null;
    if (WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION.equals(workflowType)) {
        workflow = new ApplicationCreationWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION.equals(workflowType)) {
        workflow = new ApplicationDeletionWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equals(workflowType)) {
        workflow = new SubscriptionCreationWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION.equals(workflowType)) {
        workflow = new SubscriptionDeletionWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_API_STATE.equals(workflowType)) {
        workflow = new APIStateChangeWorkflow(DAOFactory.getApiDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().geApiLifecycleManager(), APIManagerFactory.getInstance().getApiGateway(), DAOFactory.getLabelDAO());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE.equals(workflowType)) {
        workflow = new ApplicationUpdateWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else {
        throw new APIMgtDAOException("Invalid workflow type: " + workflowType + " specified", ExceptionCodes.WORKFLOW_INVALID_WFTYPE);
    }
    return workflow;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 7 with ApplicationCreationWorkflow

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

the class WorkflowsApiServiceImplTestCase method testWorkflowsWorkflowReferenceIdGet.

@Test
public void testWorkflowsWorkflowReferenceIdGet() throws Exception {
    printTestMethodName();
    WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    String workflowRefId = UUID.randomUUID().toString();
    WorkflowRequestDTO workflowRequestDTO = new WorkflowRequestDTO();
    workflowRequestDTO.setDescription("Test Desc");
    workflowRequestDTO.setStatus(WorkflowRequestDTO.StatusEnum.APPROVED);
    Workflow workflow = new ApplicationCreationWorkflow(null, null, null);
    workflow.setStatus(WorkflowStatus.APPROVED);
    LocalDateTime date1 = LocalDateTime.now();
    workflow.setCreatedTime(date1);
    workflow.setWorkflowDescription("Description 1");
    workflow.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
    String ref1 = UUID.randomUUID().toString();
    workflow.setExternalWorkflowReference(ref1);
    Mockito.doReturn(workflow).doThrow(new IllegalArgumentException()).when(adminService).retrieveWorkflow(workflowRefId);
    Response response = workflowsApiService.workflowsWorkflowReferenceIdGet(workflowRefId, getRequest());
    assertEquals(200, response.getStatus());
}
Also used : LocalDateTime(java.time.LocalDateTime) Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) WorkflowRequestDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowRequestDTO) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) APIStateChangeWorkflow(org.wso2.carbon.apimgt.core.workflow.APIStateChangeWorkflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with ApplicationCreationWorkflow

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

the class WorkflowMappingUtilTest method testToWorkflowListDTO.

@Test(description = "Convert List<Workflow> workflowList to WorkflowListDTO")
public void testToWorkflowListDTO() throws Exception {
    List<Workflow> wfList = new ArrayList<>();
    Workflow workflow1 = new ApplicationCreationWorkflow(null, null, null);
    workflow1.setStatus(WorkflowStatus.APPROVED);
    LocalDateTime date1 = LocalDateTime.now();
    workflow1.setCreatedTime(date1);
    workflow1.setWorkflowDescription("Description 1");
    workflow1.setWorkflowType(WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
    String ref1 = UUID.randomUUID().toString();
    workflow1.setExternalWorkflowReference(ref1);
    wfList.add(workflow1);
    Workflow workflow2 = new SubscriptionCreationWorkflow(null, null, null);
    workflow2.setStatus(WorkflowStatus.APPROVED);
    LocalDateTime date2 = LocalDateTime.now();
    workflow2.setCreatedTime(date2);
    workflow2.setWorkflowDescription("Description 2");
    workflow2.setWorkflowType(WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION);
    String ref2 = UUID.randomUUID().toString();
    workflow2.setExternalWorkflowReference(ref2);
    wfList.add(workflow2);
    WorkflowListDTO wfDtoList = WorkflowMappingUtil.toWorkflowListDTO(wfList);
    int count = wfDtoList.getCount();
    Assert.assertEquals(count, 2, "Mismatch in the workflow list item count");
    Assert.assertEquals(wfDtoList.getList().get(0).getDescription(), "Description 1", "Invalid description for workflow item 1");
    Assert.assertEquals(wfDtoList.getList().get(0).getType(), WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION, "Invalid type for workflow item 1");
    Assert.assertEquals(wfDtoList.getList().get(0).getWorkflowStatus(), WorkflowStatus.APPROVED.toString(), "Invalid status for workflow item 1");
    Assert.assertEquals(wfDtoList.getList().get(0).getReferenceId(), ref1, "Invalid reference id for workflow item 1");
    Assert.assertEquals(wfDtoList.getList().get(1).getDescription(), "Description 2", "Invalid description for workflow item 2");
    Assert.assertEquals(wfDtoList.getList().get(1).getType(), WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION, "Invalid type for workflow item 2");
    Assert.assertEquals(wfDtoList.getList().get(1).getWorkflowStatus(), WorkflowStatus.APPROVED.toString(), "Invalid status for workflow item 2");
    Assert.assertEquals(wfDtoList.getList().get(1).getReferenceId(), ref2, "Invalid reference id for workflow item 2");
}
Also used : LocalDateTime(java.time.LocalDateTime) SubscriptionCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow) ArrayList(java.util.ArrayList) SubscriptionCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) ApplicationCreationWorkflow(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow) WorkflowListDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowListDTO) Test(org.testng.annotations.Test)

Aggregations

ApplicationCreationWorkflow (org.wso2.carbon.apimgt.core.workflow.ApplicationCreationWorkflow)7 Workflow (org.wso2.carbon.apimgt.core.workflow.Workflow)6 Test (org.testng.annotations.Test)4 SubscriptionCreationWorkflow (org.wso2.carbon.apimgt.core.workflow.SubscriptionCreationWorkflow)4 LocalDateTime (java.time.LocalDateTime)3 HashMap (java.util.HashMap)2 BeforeTest (org.testng.annotations.BeforeTest)2 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)2 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)2 WorkflowExecutor (org.wso2.carbon.apimgt.core.api.WorkflowExecutor)2 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)2 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)2 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)2 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)2 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)2 ApplicationUpdateWorkflow (org.wso2.carbon.apimgt.core.workflow.ApplicationUpdateWorkflow)2 DefaultWorkflowExecutor (org.wso2.carbon.apimgt.core.workflow.DefaultWorkflowExecutor)2 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 ParseException (org.json.simple.parser.ParseException)1