Search in sources :

Example 1 with WorkflowDAO

use of org.wso2.carbon.identity.workflow.mgt.dao.WorkflowDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testRemovePendingLifecycleWorkflowTaskForAPI.

@Test(description = "Remove api pending lc status change request")
public void testRemovePendingLifecycleWorkflowTaskForAPI() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiLifecycleManager, apiDAO, workflowDAO, gateway);
    APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    builder.workflowStatus(APILCWorkflowStatus.PENDING.toString());
    API api = builder.build();
    String uuid = api.getId();
    String externalRef = UUID.randomUUID().toString();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(Optional.of(externalRef));
    apiPublisher.removePendingLifecycleWorkflowTaskForAPI(uuid);
    Mockito.verify(apiDAO, Mockito.times(1)).updateAPIWorkflowStatus(uuid, APILCWorkflowStatus.APPROVED);
    Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 2 with WorkflowDAO

use of org.wso2.carbon.identity.workflow.mgt.dao.WorkflowDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testDeleteApiWithZeroSubscriptionsAndPendingStateChange.

@Test(description = "Delete API with zero Subscriptions and pending wf state change")
public void testDeleteApiWithZeroSubscriptionsAndPendingStateChange() throws APIManagementException, LifecycleException, SQLException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    builder.workflowStatus(APILCWorkflowStatus.PENDING.toString());
    API api = builder.build();
    String uuid = api.getId();
    String lifecycleId = api.getLifecycleInstanceId();
    Mockito.when(apiSubscriptionDAO.getSubscriptionCountByAPI(uuid)).thenReturn(0L);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    KeyManager keyManager = Mockito.mock(KeyManager.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(USER, identityProvider, keyManager, apiDAO, null, apiSubscriptionDAO, null, apiLifecycleManager, null, workflowDAO, null, null, null, gateway);
    String externalRef = UUID.randomUUID().toString();
    Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE)).thenReturn(Optional.ofNullable(externalRef));
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    apiPublisher.deleteAPI(uuid);
    Mockito.verify(apiDAO, Mockito.times(1)).getAPI(uuid);
    Mockito.verify(apiLifecycleManager, Mockito.times(1)).removeLifecycle(lifecycleId);
    Mockito.verify(apiDAO, Mockito.times(1)).deleteAPI(uuid);
    Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(uuid, WorkflowConstants.WF_TYPE_AM_API_STATE);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) API(org.wso2.carbon.apimgt.core.models.API) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) KeyManager(org.wso2.carbon.apimgt.core.api.KeyManager) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 3 with WorkflowDAO

use of org.wso2.carbon.identity.workflow.mgt.dao.WorkflowDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testRemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState.

@Test(description = "Remove api pending lc status change request for an api without a pending task", expectedExceptions = APIManagementException.class)
public void testRemovePendingLifecycleWorkflowTaskForAPIForAPIWithoutPendingLCState() throws APIManagementException, LifecycleException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiLifecycleManager, apiDAO, workflowDAO, gateway);
    APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    builder.workflowStatus(APILCWorkflowStatus.APPROVED.toString());
    API api = builder.build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    apiPublisher.removePendingLifecycleWorkflowTaskForAPI(uuid);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) Test(org.testng.annotations.Test)

Example 4 with WorkflowDAO

use of org.wso2.carbon.identity.workflow.mgt.dao.WorkflowDAO in project carbon-apimgt by wso2.

the class ApprovalWorkflowExecutorTestCase method testWorkflowResponses.

@Test(description = "Test workflow responses")
public void testWorkflowResponses() throws WorkflowException {
    WorkflowExecutor executor = new ApprovalWorkflowExecutor();
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    Workflow workflow = new SubscriptionCreationWorkflow(apiSubscriptionDAO, workflowDAO, apiGateway);
    WorkflowResponse respone = executor.execute(workflow);
    Assert.assertEquals(respone.getJSONPayload(), "");
    Assert.assertEquals(respone.getWorkflowStatus(), WorkflowStatus.CREATED);
    workflow.setStatus(WorkflowStatus.APPROVED);
    respone = executor.complete(workflow);
    Assert.assertEquals(respone.getWorkflowStatus(), WorkflowStatus.APPROVED);
    executor.cleanUpPendingTask(workflow.getExternalWorkflowReference());
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) WorkflowResponse(org.wso2.carbon.apimgt.core.api.WorkflowResponse) WorkflowExecutor(org.wso2.carbon.apimgt.core.api.WorkflowExecutor) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) Test(org.testng.annotations.Test)

Example 5 with WorkflowDAO

use of org.wso2.carbon.identity.workflow.mgt.dao.WorkflowDAO in project carbon-apimgt by wso2.

the class WorkflowDAOIT method testUpdateWorkflowStatus.

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

Aggregations

WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)43 Test (org.testng.annotations.Test)42 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)29 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)21 BeforeTest (org.testng.annotations.BeforeTest)19 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)19 Application (org.wso2.carbon.apimgt.core.models.Application)18 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)15 API (org.wso2.carbon.apimgt.core.models.API)15 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)14 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)14 Workflow (org.wso2.carbon.apimgt.core.workflow.Workflow)14 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)12 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)11 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)11 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)11 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)8 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)5 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)5 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)5