Search in sources :

Example 66 with Workflow

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

the class WorkflowDAOIT method testremoveWorkflowEntry.

@Test
public void testremoveWorkflowEntry() throws Exception {
    String workflowRefId = UUID.randomUUID().toString();
    WorkflowDAO workflowDAO = DAOFactory.getWorkflowDAO();
    Workflow workflow = SampleTestObjectCreator.createWorkflow(workflowRefId);
    workflowDAO.addWorkflowEntry(workflow);
    workflowDAO.deleteWorkflowEntryforExternalReference(workflow.getExternalWorkflowReference());
    // 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)

Example 67 with Workflow

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

the class WorkflowDAOIT method testAddWorkflowEntry.

@Test
public void testAddWorkflowEntry() throws Exception {
    String workflowRefId = UUID.randomUUID().toString();
    WorkflowDAO workflowDAO = DAOFactory.getWorkflowDAO();
    Workflow workflow = SampleTestObjectCreator.createWorkflow(workflowRefId);
    workflowDAO.addWorkflowEntry(workflow);
    Workflow retrieveWorflow = workflowDAO.retrieveWorkflow(workflow.getExternalWorkflowReference());
    Assert.assertEquals(retrieveWorflow.getExternalWorkflowReference(), workflowRefId);
    Assert.assertEquals(retrieveWorflow.getStatus(), workflow.getStatus());
    Assert.assertEquals(retrieveWorflow.getWorkflowReference(), workflow.getWorkflowReference());
    Assert.assertEquals(retrieveWorflow.getAttributes(), workflow.getAttributes());
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) Workflow(org.wso2.carbon.apimgt.core.workflow.Workflow) Test(org.testng.annotations.Test)

Example 68 with Workflow

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

the class APIStoreImplTestCase method testAddSubscription.

@Test(description = "Add subscription to an application")
public void testAddSubscription() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    Policy policy = new SubscriptionPolicy(UUID, TIER);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
    APIStore apiStore = getApiStoreImpl(apiDAO, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway, policyDAO);
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    apiBuilder.lifeCycleStatus(APIStatus.PUBLISHED.getStatus());
    API api = apiBuilder.build();
    String apiId = api.getId();
    Application application = new Application("TestApp", USER_ID);
    application.setId(UUID);
    Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
    Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(application);
    SubscriptionResponse subscriptionResponse = apiStore.addApiSubscription(apiId, UUID, TIER);
    String subscriptionId = subscriptionResponse.getSubscriptionUUID();
    Assert.assertNotNull(subscriptionId);
    // before workflow add subscription with blocked state
    Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).addAPISubscription(subscriptionId, apiId, UUID, policy.getUuid(), APIMgtConstants.SubscriptionStatus.ON_HOLD);
    // after workflow change the state
    Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).updateSubscriptionStatus(subscriptionId, APIMgtConstants.SubscriptionStatus.ACTIVE);
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) SubscriptionResponse(org.wso2.carbon.apimgt.core.models.SubscriptionResponse) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) Application(org.wso2.carbon.apimgt.core.models.Application) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 69 with Workflow

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

the class TestMappingUtilTestCase method testWorkflowResponseToWorkflowResponseDTOMapping.

@Test(description = "Workflow response to Workflow response DTO mapping ")
void testWorkflowResponseToWorkflowResponseDTOMapping() {
    WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
    workflowResponse.setWorkflowStatus(WorkflowStatus.APPROVED);
    WorkflowResponseDTO workflowResponseDTO = MappingUtil.toWorkflowResponseDTO(workflowResponse);
    assertEquals(workflowResponse.getWorkflowStatus().name(), workflowResponseDTO.getWorkflowStatus().name());
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.WorkflowResponseDTO) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) GeneralWorkflowResponse(org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse) 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