Search in sources :

Example 41 with WorkflowDAO

use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO 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 42 with WorkflowDAO

use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testAddSubscriptionForInvalidAPI.

@Test(description = "Add subscription without a valid api", expectedExceptions = APIManagementException.class)
public void testAddSubscriptionForInvalidAPI() 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);
    APIStore apiStore = getApiStoreImpl(apiDAO, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway, policyDAO);
    Application application = new Application("TestApp", USER_ID);
    application.setId(UUID);
    Mockito.when(apiDAO.getAPI(API_ID)).thenReturn(null);
    Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(application);
    SubscriptionResponse subscriptionResponse = apiStore.addApiSubscription(API_ID, UUID, TIER);
    String subscriptionId = subscriptionResponse.getSubscriptionUUID();
    Assert.assertNotNull(subscriptionId);
    // subscription should not be added
    Mockito.verify(apiSubscriptionDAO, Mockito.times(0)).addAPISubscription(subscriptionId, API_ID, UUID, TIER, APIMgtConstants.SubscriptionStatus.ON_HOLD);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SubscriptionResponse(org.wso2.carbon.apimgt.core.models.SubscriptionResponse) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) 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 43 with WorkflowDAO

use of org.wso2.carbon.apimgt.core.dao.WorkflowDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testDeleteApplication.

@Test(description = "Delete application")
public void testDeleteApplication() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APISubscriptionDAO subscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, subscriptionDAO, workflowDAO, apiGateway);
    Application application = SampleTestObjectCreator.createDefaultApplication();
    application.setId(UUID);
    Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(application);
    String externalRef = java.util.UUID.randomUUID().toString();
    Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(application.getId(), WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE)).thenReturn(Optional.of(externalRef));
    apiStore.deleteApplication(UUID);
    Mockito.verify(applicationDAO, Mockito.times(1)).deleteApplication(UUID);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

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