Search in sources :

Example 6 with ApplicationDAO

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

the class TestUtil method addCustomApplication.

public static Application addCustomApplication(String applicationName, String owner) throws APIMgtDAOException {
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    Application application = SampleTestObjectCreator.createCustomApplication(applicationName, owner);
    applicationDAO.addApplication(application);
    return application;
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application)

Example 7 with ApplicationDAO

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

the class SubscriptionDAOImplIT method testGetSubscriptionForApplicationAndKeyType.

@Test
public void testGetSubscriptionForApplicationAndKeyType() throws Exception {
    // add test apis, apps and subscriptions
    // app1: api2
    // app2: api1, api2, api3
    // app3: api3
    // app4: api1, api2, api3, api4
    ApisAndApps apisAndApps = createApisAppsAndSubscriptions();
    APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    API api2 = apisAndApps.getApis().get(1);
    Application app1 = apisAndApps.getApps().get(0);
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-1", app1.getId());
    // get subscriptions of app1-PRODUCTION
    List<SubscriptionValidationData> subscriptionValidationDataProd = subscriptionDAO.getAPISubscriptionsOfAppForValidation(app1.getId(), "PRODUCTION");
    // validate subscriptions
    Assert.assertEquals(subscriptionValidationDataProd.size(), 1, "There should be 1 subscriptions (only).");
    SubscriptionValidationData validationData = subscriptionValidationDataProd.get(0);
    Assert.assertNotNull(validationData);
    Assert.assertEquals(validationData.getApiName(), api2.getName());
    Assert.assertEquals(validationData.getApiVersion(), api2.getVersion());
    Assert.assertEquals(validationData.getApplicationId(), app1.getId());
    Assert.assertEquals(validationData.getKeyEnvType(), "PRODUCTION");
    // list subscriptions for app1-SANDBOX
    List<SubscriptionValidationData> subscriptionValidationDataSandbox = subscriptionDAO.getAPISubscriptionsOfAppForValidation(app1.getId(), "SANDBOX");
    Assert.assertEquals(subscriptionValidationDataSandbox.size(), 0, "There shouldn't be any subscriptions.");
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) API(org.wso2.carbon.apimgt.core.models.API) SubscriptionValidationData(org.wso2.carbon.apimgt.core.models.SubscriptionValidationData) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 8 with ApplicationDAO

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

the class APIStoreImplTestCase method testUpdateApplication.

@Test(description = "Update an application")
public void testUpdateApplication() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO, apiGateway);
    Application existingApplication = SampleTestObjectCreator.createDefaultApplication();
    String appUUID = existingApplication.getUuid();
    existingApplication.setStatus(ApplicationStatus.APPLICATION_APPROVED);
    Mockito.when(applicationDAO.getApplication(appUUID)).thenReturn(existingApplication);
    // Updating the existing application
    Application updatedApplication = SampleTestObjectCreator.createDefaultApplication();
    updatedApplication.setDescription("updated description");
    ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
    applicationPolicy.setPolicyName(TIER);
    updatedApplication.setPolicy(applicationPolicy);
    updatedApplication.setStatus(ApplicationStatus.APPLICATION_APPROVED);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName())).thenReturn(applicationPolicy);
    apiStore.updateApplication(appUUID, updatedApplication);
    Mockito.verify(applicationDAO, Mockito.times(1)).updateApplication(appUUID, updatedApplication);
    // Error
    // APIMgtDAOException
    Mockito.doThrow(APIMgtDAOException.class).when(applicationDAO).updateApplication(appUUID, updatedApplication);
    try {
        apiStore.updateApplication(appUUID, updatedApplication);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while updating the application - " + appUUID);
    }
    // Error path
    // When specified tier in the updated application is invalid
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName())).thenReturn(null);
    try {
        apiStore.updateApplication(appUUID, updatedApplication);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Specified tier " + applicationPolicy + " is invalid");
    }
}
Also used : WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) 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 9 with ApplicationDAO

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

the class APIStoreImplTestCase method testAddApplicationNullPolicy.

@Test(description = "Add an application with null policy", expectedExceptions = APIManagementException.class)
public void testAddApplicationNullPolicy() 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(TIER));
    Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
    Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(null);
    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)

Example 10 with ApplicationDAO

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

the class APIStoreImplTestCase method testGetApplicationByUUIDException.

@Test(description = "Exception when retrieving an application by uuid", expectedExceptions = APIManagementException.class)
public void testGetApplicationByUUIDException() throws APIManagementException {
    ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
    APIStore apiStore = getApiStoreImpl(applicationDAO);
    Mockito.when(applicationDAO.getApplication(UUID)).thenThrow(new APIMgtDAOException("Error occurred while retrieving application - " + UUID, new SQLException()));
    apiStore.getApplicationByUuid(UUID);
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) 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)

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