Search in sources :

Example 21 with SubscriptionValidationData

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

Aggregations

SubscriptionValidationData (org.wso2.carbon.apimgt.core.models.SubscriptionValidationData)16 Test (org.testng.annotations.Test)6 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)6 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)5 API (org.wso2.carbon.apimgt.core.models.API)5 Application (org.wso2.carbon.apimgt.core.models.Application)5 ArrayList (java.util.ArrayList)4 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 SQLException (java.sql.SQLException)3 SubscriptionEvent (org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)2 OAuthApplicationInfo (org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)2 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.core.dto.SubscriptionDTO)2 HashMap (java.util.HashMap)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)1