Search in sources :

Example 46 with ApplicationDAO

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

the class APIStoreImplTestCase method testGetApplicationByUUID.

@Test(description = "Retrieve an application by uuid")
public void testGetApplicationByUUID() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO);
    Application applicationFromDAO = new Application(APP_NAME, USER_NAME);
    Mockito.when(applicationDAO.getApplication(UUID)).thenReturn(applicationFromDAO);
    Application application = apiStore.getApplicationByUuid(UUID);
    Assert.assertNotNull(application);
    Mockito.verify(applicationDAO, Mockito.times(1)).getApplication(UUID);
}
Also used : 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 47 with ApplicationDAO

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

the class APIStoreImplTestCase method testGetAPISubscriptionsByApplication.

@Test(description = "Get API subscriptions by application")
public void testGetAPISubscriptionsByApplication() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO);
    Application application = new Application(APP_NAME, USER_NAME);
    application.setPolicy(new ApplicationPolicy(TIER));
    application.setId(UUID);
    apiStore.getAPISubscriptionsByApplication(application);
    Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).getAPISubscriptionsByApplication(UUID);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) 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) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 48 with ApplicationDAO

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

the class APIStoreImplTestCase method testGetApplications.

@Test(description = "Retrieve applications")
public void testGetApplications() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO);
    apiStore.getApplications(USER_ID);
    Mockito.verify(applicationDAO, Mockito.times(1)).getApplications(USER_ID);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 49 with ApplicationDAO

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

use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO 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)

Aggregations

ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)62 Test (org.testng.annotations.Test)56 Application (org.wso2.carbon.apimgt.core.models.Application)50 BeforeTest (org.testng.annotations.BeforeTest)32 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)32 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)21 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)18 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)18 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)15 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)15 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)13 API (org.wso2.carbon.apimgt.core.models.API)12 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)10 SQLException (java.sql.SQLException)8 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)7 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)6 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)5 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)5 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)4