Search in sources :

Example 36 with WorkflowDAO

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

the class APIStoreImplTestCase method testAddApplicationWithDuplicateName.

@Test(description = "Add application with duplicate name", expectedExceptions = APIMgtResourceAlreadyExistsException.class)
public void testAddApplicationWithDuplicateName() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, workflowDAO);
    Application application = new Application(APP_NAME, USER_NAME);
    Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(true);
    apiStore.addApplication(application);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) 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)

Example 37 with WorkflowDAO

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

the class APIStoreImplTestCase method testAddSubscriptionForInvalidApplication.

@Test(description = "Add subscription without a valid app", expectedExceptions = APIManagementException.class)
public void testAddSubscriptionForInvalidApplication() 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);
    APIStore apiStore = getApiStoreImpl(apiDAO, applicationDAO, apiSubscriptionDAO, workflowDAO, apiGateway);
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    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(null);
    SubscriptionResponse subscriptionResponse = apiStore.addApiSubscription(apiId, UUID, TIER);
    String subscriptionId = subscriptionResponse.getSubscriptionUUID();
    Assert.assertNotNull(subscriptionId);
    // subscription should not be added
    Mockito.verify(apiSubscriptionDAO, Mockito.times(0)).addAPISubscription(subscriptionId, apiId, UUID, TIER, APIMgtConstants.SubscriptionStatus.ON_HOLD);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) 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) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 38 with WorkflowDAO

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

the class APIStoreImplTestCase method testDeleteApplicationWithOnHoldState.

@Test(description = "Delete application which is in on_hold state")
public void testDeleteApplicationWithOnHoldState() 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.setStatus(APIMgtConstants.ApplicationStatus.APPLICATION_ONHOLD);
    application.setId(UUID);
    String externalRef = java.util.UUID.randomUUID().toString();
    Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(application);
    Mockito.when(workflowDAO.getExternalWorkflowReferenceForPendingTask(application.getId(), WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION)).thenReturn(Optional.of(externalRef));
    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);
    Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(application.getId(), WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION);
    Mockito.verify(workflowDAO, Mockito.times(1)).getExternalWorkflowReferenceForPendingTask(application.getId(), WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE);
}
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)

Example 39 with WorkflowDAO

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

the class APIStoreImplTestCase method testAddApplicationPermissionStringInvalid.

@Test(description = "Add an application with invalid permission String")
public void testAddApplicationPermissionStringInvalid() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    Policy policy = Mockito.mock(Policy.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO, apiGateway);
    Application application = new Application(APP_NAME, USER_NAME);
    application.setPolicy(new ApplicationPolicy(TIER));
    application.setPermissionString("[{\"groupId\": \"testGroup\",\"permission\":[\"TESTREAD\",\"TESTUPDATE\"]}]");
    Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
    ApplicationCreationResponse applicationResponse = apiStore.addApplication(application);
    String applicationUuid = applicationResponse.getApplicationUUID();
    Assert.assertNotNull(applicationUuid);
    Mockito.verify(applicationDAO, Mockito.times(1)).addApplication(application);
}
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) WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) ApplicationCreationResponse(org.wso2.carbon.apimgt.core.workflow.ApplicationCreationResponse) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) 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 40 with WorkflowDAO

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

the class APIStoreImplTestCase method testAddApplicationNullTier.

@Test(description = "Add an application with null tier", expectedExceptions = APIManagementException.class)
public void testAddApplicationNullTier() throws Exception {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO);
    Application application = new Application(APP_NAME, USER_NAME);
    application.setPolicy(new ApplicationPolicy(null));
    Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
    apiStore.addApplication(application);
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) 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)

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