Search in sources :

Example 41 with APISubscriptionDAO

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

the class SubscriptionDAOImplIT method testGetSubscriptionForProvider.

@Test
public void testGetSubscriptionForProvider() throws Exception {
    // add test apis, apps and subscriptions
    // app1: api2
    // app2: api1, api2, api3
    // app3: api3
    // app4: api1, api2, api3, api4
    createApisAppsAndSubscriptions();
    APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
    // TODO getAPISubscriptionsForUser() pagination not implemented properly
    List<Subscription> subscriptions = subscriptionDAO.getAPISubscriptionsForUser(0, Integer.MAX_VALUE, "admin");
    // The number of total subscriptions created from createApisAppsAndSubscriptions() is 9
    Assert.assertEquals(subscriptions.size(), 9);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Test(org.testng.annotations.Test)

Example 42 with APISubscriptionDAO

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

the class SubscriptionDAOImplIT method testGetSubscriptionForValidationByApiContextVersionAndApp.

@Test
public void testGetSubscriptionForValidationByApiContextVersionAndApp() throws Exception {
    // add test apis, apps and subscriptions
    // app1: api2
    // app2: api1, api2
    ApisAndApps apisAndApps = createApisAppsAndSubscriptions();
    APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    API api1 = apisAndApps.getApis().get(0);
    API api2 = apisAndApps.getApis().get(1);
    Application app1 = apisAndApps.getApps().get(0);
    Application app2 = apisAndApps.getApps().get(1);
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-1", app1.getId());
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-2", app2.getId());
    List<SubscriptionValidationData> availableSubs = subscriptionDAO.getAPISubscriptionsOfAPIForValidation(api2.getContext(), api2.getVersion(), app2.getId());
    Assert.assertEquals(availableSubs.size(), 1, "There should be 1 subscription only but found " + availableSubs.size());
    validateSubscriptionsOfApi(availableSubs.get(0), api2, app2);
    List<SubscriptionValidationData> notAvailableSubs = subscriptionDAO.getAPISubscriptionsOfAPIForValidation(api1.getContext(), api1.getVersion(), app1.getId());
    Assert.assertEquals(notAvailableSubs.size(), 0, "There can't be any subscriptions but found " + notAvailableSubs.size());
}
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 43 with APISubscriptionDAO

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

the class SubscriptionDAOImplIT method testGetSubscriptionsForValidation.

@Test
public void testGetSubscriptionsForValidation() throws Exception {
    // add test apis, apps and subscriptions
    ApisAndApps apisAndApps = createApisAppsAndSubscriptions();
    APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    API api1 = apisAndApps.getApis().get(0);
    API api2 = apisAndApps.getApis().get(1);
    API api3 = apisAndApps.getApis().get(2);
    API api4 = apisAndApps.getApis().get(3);
    Application app1 = apisAndApps.getApps().get(0);
    Application app2 = apisAndApps.getApps().get(1);
    Application app3 = apisAndApps.getApps().get(2);
    Application app4 = apisAndApps.getApps().get(3);
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-1", app1.getId());
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-2", app2.getId());
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-3", app3.getId());
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-4", app4.getId());
    // get all subscriptions
    List<SubscriptionValidationData> subscriptions = subscriptionDAO.getAPISubscriptionsOfAPIForValidation(-1);
    // validate subscription count
    Assert.assertEquals(subscriptions.size(), 9, "There should be 9 subscriptions (only).");
    // validate subscriptions
    for (SubscriptionValidationData subscription : subscriptions) {
        Assert.assertNotNull(subscription);
        if (subscription.getApplicationId().equals(app1.getId()) && subscription.getApiName().equals(api2.getName())) {
            // app1  & api 2
            validateSubscriptionsOfApi(subscription, api2, app1);
        } else if (subscription.getApplicationId().equals(app2.getId()) && subscription.getApiName().equals(api1.getName())) {
            // app2  & api 1
            validateSubscriptionsOfApi(subscription, api1, app2);
        } else if (subscription.getApplicationId().equals(app2.getId()) && subscription.getApiName().equals(api2.getName())) {
            // app2  & api 2
            validateSubscriptionsOfApi(subscription, api2, app2);
        } else if (subscription.getApplicationId().equals(app2.getId()) && subscription.getApiName().equals(api3.getName())) {
            // app2  & api 3
            validateSubscriptionsOfApi(subscription, api3, app2);
        } else if (subscription.getApplicationId().equals(app2.getId()) && subscription.getApiName().equals(api4.getName())) {
            // app2  & api 4
            validateSubscriptionsOfApi(subscription, api4, app2);
        } else if (subscription.getApplicationId().equals(app3.getId()) && subscription.getApiName().equals(api3.getName())) {
            // app3  & api 3
            validateSubscriptionsOfApi(subscription, api3, app3);
        } else if (subscription.getApplicationId().equals(app4.getId()) && subscription.getApiName().equals(api1.getName())) {
            // app4  & api 1
            validateSubscriptionsOfApi(subscription, api1, app4);
        } else if (subscription.getApplicationId().equals(app4.getId()) && subscription.getApiName().equals(api2.getName())) {
            // app4  & api 2
            validateSubscriptionsOfApi(subscription, api2, app4);
        } else if (subscription.getApplicationId().equals(app4.getId()) && subscription.getApiName().equals(api3.getName())) {
            // app4  & api 3
            validateSubscriptionsOfApi(subscription, api3, app4);
        } else if (subscription.getApplicationId().equals(app4.getId()) && subscription.getApiName().equals(api4.getName())) {
            // app4  & api 4
            validateSubscriptionsOfApi(subscription, api4, app4);
        } else {
            Assert.fail("Invalid subscription found!!! API: " + subscription.getApiName() + " Application: " + subscription.getApplicationId());
        }
    }
}
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 44 with APISubscriptionDAO

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

the class SubscriptionDAOImplIT method testGetSubscriptionForValidationByApiContextAndVersion.

@Test
public void testGetSubscriptionForValidationByApiContextAndVersion() throws Exception {
    // add test apis, apps and subscriptions
    ApisAndApps apisAndApps = createApisAppsAndSubscriptions();
    APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    API api1 = apisAndApps.getApis().get(0);
    API api2 = apisAndApps.getApis().get(1);
    API api3 = apisAndApps.getApis().get(2);
    API api4 = apisAndApps.getApis().get(3);
    Application app1 = apisAndApps.getApps().get(0);
    Application app2 = apisAndApps.getApps().get(1);
    Application app3 = apisAndApps.getApps().get(2);
    Application app4 = apisAndApps.getApps().get(3);
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-1", app1.getId());
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-2", app2.getId());
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-3", app3.getId());
    registerOAuthAppForApplication(applicationDAO, "client-key-for-app-4", app4.getId());
    // get subscriptions of api1 (app2, app4)
    List<SubscriptionValidationData> subscriptions = subscriptionDAO.getAPISubscriptionsOfAPIForValidation(api1.getContext(), api1.getVersion());
    // validate subscription count
    Assert.assertEquals(subscriptions.size(), 2, "There should be 2 subscriptions (only).");
    Assert.assertEquals(subscriptionDAO.getSubscriptionCountByAPI(api1.getId()), 2L, "There should be 2 subscriptions (only).");
    // validate subscriptions
    for (SubscriptionValidationData subscription : subscriptions) {
        Assert.assertNotNull(subscription);
        if (subscription.getApplicationId().equals(app2.getId())) {
            validateSubscriptionsOfApi(subscription, api1, app2);
        } else if (subscription.getApplicationId().equals(app4.getId())) {
            validateSubscriptionsOfApi(subscription, api1, app4);
        } else {
            Assert.fail(INVALID_SUBSCRIPTION_FOUND);
        }
    }
    // get subscriptions of api2 (app1, app2, app4)
    subscriptions = subscriptionDAO.getAPISubscriptionsOfAPIForValidation(api2.getContext(), api2.getVersion());
    // validate subscription count
    Assert.assertEquals(subscriptions.size(), 3, "There should be 3 subscriptions (only).");
    Assert.assertEquals(subscriptionDAO.getSubscriptionCountByAPI(api2.getId()), 3L, "There should be 3 subscriptions (only).");
    // validate subscriptions
    for (SubscriptionValidationData subscription : subscriptions) {
        Assert.assertNotNull(subscription);
        if (subscription.getApplicationId().equals(app1.getId())) {
            validateSubscriptionsOfApi(subscription, api2, app1);
        } else if (subscription.getApplicationId().equals(app2.getId())) {
            validateSubscriptionsOfApi(subscription, api2, app2);
        } else if (subscription.getApplicationId().equals(app4.getId())) {
            validateSubscriptionsOfApi(subscription, api2, app4);
        } else {
            Assert.fail(INVALID_SUBSCRIPTION_FOUND);
        }
    }
    // get subscriptions of api3 (app2, app3, app4)
    subscriptions = subscriptionDAO.getAPISubscriptionsOfAPIForValidation(api3.getContext(), api3.getVersion());
    // validate subscription count
    Assert.assertEquals(subscriptions.size(), 3, "There should be 3 subscription (only).");
    Assert.assertEquals(subscriptionDAO.getSubscriptionCountByAPI(api3.getId()), 3L, "There should be 3 subscription (only).");
    // validate subscriptions
    for (SubscriptionValidationData subscription : subscriptions) {
        Assert.assertNotNull(subscription);
        if (subscription.getApplicationId().equals(app2.getId())) {
            validateSubscriptionsOfApi(subscription, api3, app2);
        } else if (subscription.getApplicationId().equals(app3.getId())) {
            validateSubscriptionsOfApi(subscription, api3, app3);
        } else if (subscription.getApplicationId().equals(app4.getId())) {
            validateSubscriptionsOfApi(subscription, api3, app4);
        } else {
            Assert.fail(INVALID_SUBSCRIPTION_FOUND);
        }
    }
    // get subscriptions of api4 (app4)
    subscriptions = subscriptionDAO.getAPISubscriptionsOfAPIForValidation(api4.getContext(), api4.getVersion());
    // validate subscription count
    Assert.assertEquals(subscriptions.size(), 1, "There should be 1 subscriptions (only).");
    Assert.assertEquals(subscriptionDAO.getSubscriptionCountByAPI(api4.getId()), 1L, "There should be 1 subscriptions (only).");
    // validate subscriptions
    for (SubscriptionValidationData subscription : subscriptions) {
        Assert.assertNotNull(subscription);
        if (subscription.getApplicationId().equals(app4.getId())) {
            validateSubscriptionsOfApi(subscription, api4, app4);
        } else {
            Assert.fail(INVALID_SUBSCRIPTION_FOUND);
        }
    }
}
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 45 with APISubscriptionDAO

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

the class SubscriptionDAOImplIT method testGetPendingAPISubscriptionsByApplication.

@Test
public void testGetPendingAPISubscriptionsByApplication() throws Exception {
    // add new app
    Application app = TestUtil.addTestApplication();
    // add new api
    API api1 = TestUtil.addCustomAPI(API_1, API_VERSION, API1_CONTEXT);
    API api2 = TestUtil.addCustomAPI(API_2, API_VERSION, API2_CONTEXT);
    API api3 = TestUtil.addCustomAPI(API_3, API_VERSION, API3_CONTEXT);
    // Add subscriptions
    APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api1.getId(), app.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ON_HOLD);
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api2.getId(), app.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api3.getId(), app.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ON_HOLD);
    List<Subscription> pendingSubscriptions = subscriptionDAO.getPendingAPISubscriptionsByApplication(app.getId());
    Assert.assertNotNull(pendingSubscriptions);
    Assert.assertTrue(pendingSubscriptions.size() == 2);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) API(org.wso2.carbon.apimgt.core.models.API) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Aggregations

APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)59 Test (org.testng.annotations.Test)54 API (org.wso2.carbon.apimgt.core.models.API)30 Application (org.wso2.carbon.apimgt.core.models.Application)24 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)22 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)18 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)18 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)18 BeforeTest (org.testng.annotations.BeforeTest)14 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)14 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)14 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)12 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)11 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)10 SQLException (java.sql.SQLException)8 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)8 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)8 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)6 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)5 SubscriptionValidationData (org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)5