Search in sources :

Example 76 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testAddApplicationCreationException.

@Test(description = "Exception when adding an application", expectedExceptions = APIManagementException.class)
public void testAddApplicationCreationException() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    Policy policy = Mockito.mock(Policy.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO);
    Application application = new Application(APP_NAME, USER_NAME);
    application.setPolicy(new ApplicationPolicy(TIER));
    Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
    Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(policy);
    Mockito.doThrow(new APIMgtDAOException("Error occurred while creating the application - " + application.getName())).when(applicationDAO).addApplication(application);
    apiStore.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) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) 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)

Example 77 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO 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 78 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO 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)

Example 79 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testGetApplicationByName.

@Test(description = "Retrieve an application by name")
public void testGetApplicationByName() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO);
    Application applicationFromDAO = new Application(APP_NAME, null);
    Mockito.when(applicationDAO.getApplicationByName(APP_NAME, USER_ID)).thenReturn(applicationFromDAO);
    Application application = apiStore.getApplicationByName(APP_NAME, USER_ID);
    Assert.assertNotNull(application);
    Mockito.verify(applicationDAO, Mockito.times(1)).getApplicationByName(APP_NAME, USER_ID);
}
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 80 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testGetAPISubscriptionsByApplicationException.

@Test(description = "Exception when getting API subscriptions by application", expectedExceptions = APIManagementException.class)
public void testGetAPISubscriptionsByApplicationException() 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);
    Mockito.when(apiSubscriptionDAO.getAPISubscriptionsByApplication(application.getId())).thenThrow(new APIMgtDAOException("Error occurred while retrieving subscriptions for application - " + application.getName(), new SQLException()));
    apiStore.getAPISubscriptionsByApplication(application);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) SQLException(java.sql.SQLException) 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)

Aggregations

ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)62 Test (org.testng.annotations.Test)59 Application (org.wso2.carbon.apimgt.core.models.Application)50 BeforeTest (org.testng.annotations.BeforeTest)33 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)32 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)31 PaginatableFilterableApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO)25 FileBasedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)25 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 AbstractApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener)13 ApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)13 API (org.wso2.carbon.apimgt.core.models.API)12 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)11 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)10