Search in sources :

Example 86 with Application

use of org.wso2.carbon.apimgt.api.model.subscription.Application 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 87 with Application

use of org.wso2.carbon.apimgt.api.model.subscription.Application in project carbon-apimgt by wso2.

the class SubscriptionDAOImplIT method testAddAndGetSubscription.

@Test
public void testAddAndGetSubscription() throws Exception {
    // add new app
    Application app = TestUtil.addTestApplication();
    // add new api
    API api = TestUtil.addTestAPI();
    // add subscription
    String subscriptionTier = GOLD_TIER;
    APISubscriptionDAO apiSubscriptionDAO = DAOFactory.getAPISubscriptionDAO();
    String uuid = UUID.randomUUID().toString();
    apiSubscriptionDAO.addAPISubscription(uuid, api.getId(), app.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    // get subscription
    Subscription subscription = apiSubscriptionDAO.getAPISubscription(uuid);
    // validate
    Assert.assertNotNull(subscription);
    Assert.assertEquals(subscription.getId(), uuid);
    Assert.assertEquals(subscription.getStatus(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    Assert.assertEquals(subscription.getPolicy().getPolicyName(), subscriptionTier);
    Assert.assertEquals(subscription.getApi(), TestUtil.createSummaryAPI(api), TestUtil.printDiff(subscription.getApi(), TestUtil.createSummaryAPI(api)));
    Assert.assertEquals(subscription.getApplication(), TestUtil.createSummaryApplication(app), TestUtil.printDiff(subscription.getApplication(), TestUtil.createSummaryApplication(app)));
}
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)

Example 88 with Application

use of org.wso2.carbon.apimgt.api.model.subscription.Application in project carbon-apimgt by wso2.

the class SystemApplicationDaoImplIT method testAddAndGetApplicationKey.

@Test
public void testAddAndGetApplicationKey() throws Exception {
    SystemApplicationDao systemApplicationDao = DAOFactory.getSystemApplicationDao();
    String consumerKey = UUID.randomUUID().toString();
    String appName = "publisher";
    systemApplicationDao.addApplicationKey(appName, consumerKey);
    String retrievedConsumerKey = systemApplicationDao.getConsumerKeyForApplication(appName);
    Assert.assertNotNull(retrievedConsumerKey);
    Assert.assertEquals(retrievedConsumerKey, consumerKey);
    Assert.assertTrue(systemApplicationDao.isConsumerKeyExistForApplication(appName));
    systemApplicationDao.removeConsumerKeyForApplication(appName);
    Assert.assertFalse(systemApplicationDao.isConsumerKeyExistForApplication(appName));
    try {
        systemApplicationDao.getConsumerKeyForApplication(appName);
        Assert.fail("System application exist");
    } catch (APIMgtDAOException e) {
        Assert.assertTrue(true);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SystemApplicationDao(org.wso2.carbon.apimgt.core.dao.SystemApplicationDao) Test(org.testng.annotations.Test)

Example 89 with Application

use of org.wso2.carbon.apimgt.api.model.subscription.Application in project carbon-apimgt by wso2.

the class SubscriptionDAOImplIT method testUpdateSubscription.

@Test
public void testUpdateSubscription() throws Exception {
    // add new app
    Application app = TestUtil.addTestApplication();
    // add new api
    API api = TestUtil.addTestAPI();
    // add subscription
    String subscriptionPolicy = GOLD_TIER;
    APISubscriptionDAO apiSubscriptionDAO = DAOFactory.getAPISubscriptionDAO();
    String uuid = UUID.randomUUID().toString();
    apiSubscriptionDAO.addAPISubscription(uuid, api.getId(), app.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    // get subscription
    Subscription subscription = apiSubscriptionDAO.getAPISubscription(uuid);
    // validate fingerprint
    String fingerprintBeforeUpdate = ETagUtils.generateETag(apiSubscriptionDAO.getLastUpdatedTimeOfSubscription(uuid));
    Assert.assertNotNull(fingerprintBeforeUpdate);
    // validate tier and status
    Assert.assertNotNull(subscription);
    Assert.assertEquals(subscription.getId(), uuid);
    Assert.assertEquals(subscription.getStatus(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    Assert.assertEquals(subscription.getPolicy().getPolicyName(), subscriptionPolicy);
    // update subscription policy
    String newSubscriptionPolicy = SILVER_TIER;
    apiSubscriptionDAO.updateSubscriptionPolicy(uuid, newSubscriptionPolicy);
    // get subscription
    subscription = apiSubscriptionDAO.getAPISubscription(uuid);
    // validate
    Assert.assertNotNull(subscription);
    Assert.assertEquals(subscription.getId(), uuid);
    Assert.assertEquals(subscription.getStatus(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    Assert.assertEquals(subscription.getPolicy().getPolicyName(), newSubscriptionPolicy);
    Assert.assertEquals(subscription.getApi(), TestUtil.createSummaryAPI(api), TestUtil.printDiff(subscription.getApi(), TestUtil.createSummaryAPI(api)));
    Assert.assertEquals(subscription.getApplication(), TestUtil.createSummaryApplication(app), TestUtil.printDiff(subscription.getApplication(), TestUtil.createSummaryApplication(app)));
    // update subscription status
    APIMgtConstants.SubscriptionStatus newSubscriptionStatus = APIMgtConstants.SubscriptionStatus.PROD_ONLY_BLOCKED;
    apiSubscriptionDAO.updateSubscriptionStatus(uuid, newSubscriptionStatus);
    // get subscription
    subscription = apiSubscriptionDAO.getAPISubscription(uuid);
    String fingerprintAfterUpdate = ETagUtils.generateETag(apiSubscriptionDAO.getLastUpdatedTimeOfSubscription(uuid));
    // validate
    Assert.assertNotNull(subscription);
    Assert.assertNotNull(fingerprintAfterUpdate);
    Assert.assertEquals(subscription.getId(), uuid);
    Assert.assertEquals(subscription.getStatus(), newSubscriptionStatus);
    Assert.assertEquals(subscription.getPolicy().getPolicyName(), newSubscriptionPolicy);
    Assert.assertEquals(subscription.getApi(), TestUtil.createSummaryAPI(api), TestUtil.printDiff(subscription.getApi(), TestUtil.createSummaryAPI(api)));
    Assert.assertEquals(subscription.getApplication(), TestUtil.createSummaryApplication(app), TestUtil.printDiff(subscription.getApplication(), TestUtil.createSummaryApplication(app)));
    Assert.assertNotEquals(fingerprintBeforeUpdate, fingerprintAfterUpdate);
}
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) APIMgtConstants(org.wso2.carbon.apimgt.core.util.APIMgtConstants) Test(org.testng.annotations.Test)

Example 90 with Application

use of org.wso2.carbon.apimgt.api.model.subscription.Application in project carbon-apimgt by wso2.

the class SubscriptionDAOImplIT method createApisAppsAndSubscriptions.

private ApisAndApps createApisAppsAndSubscriptions() throws Exception {
    List<Application> apps = new ArrayList<>();
    // add 4 apps
    String username = ADMIN;
    Application app1 = TestUtil.addCustomApplication(APP_1, username);
    apps.add(app1);
    Application app2 = TestUtil.addCustomApplication(APP_2, username);
    apps.add(app2);
    Application app3 = TestUtil.addCustomApplication(APP_3, username);
    apps.add(app3);
    Application app4 = TestUtil.addCustomApplication(APP_4, username);
    apps.add(app4);
    // add 4 apis
    List<API> apis = new ArrayList<>();
    API api1 = TestUtil.addCustomAPI(API_1, API_VERSION, API1_CONTEXT);
    apis.add(api1);
    API api2 = TestUtil.addCustomAPI(API_2, API_VERSION, API2_CONTEXT);
    apis.add(api2);
    API api3 = TestUtil.addCustomAPI(API_3, API_VERSION, API3_CONTEXT);
    apis.add(api3);
    API api4 = TestUtil.addCustomAPI(API_4, API_VERSION, API4_CONTEXT);
    apis.add(api4);
    // Add subscriptions
    APISubscriptionDAO subscriptionDAO = DAOFactory.getAPISubscriptionDAO();
    // app1: api2
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api2.getId(), app1.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    // app2: api1, api2, api3
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api1.getId(), app2.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api2.getId(), app2.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api3.getId(), app2.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    // app3: api3
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api3.getId(), app3.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    // app4: api1, api2, api3, api4
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api1.getId(), app4.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api2.getId(), app4.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api3.getId(), app4.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    subscriptionDAO.addAPISubscription(UUID.randomUUID().toString(), api4.getId(), app4.getId(), goldSubscriptionPolicy.getUuid(), APIMgtConstants.SubscriptionStatus.ACTIVE);
    return new ApisAndApps(apis, apps);
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) Application(org.wso2.carbon.apimgt.core.models.Application)

Aggregations

Test (org.testng.annotations.Test)156 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)143 Application (org.wso2.carbon.apimgt.api.model.Application)130 Application (org.wso2.carbon.apimgt.core.models.Application)121 Test (org.junit.Test)102 ArrayList (java.util.ArrayList)98 SQLException (java.sql.SQLException)94 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)94 PreparedStatement (java.sql.PreparedStatement)88 Connection (java.sql.Connection)83 ResultSet (java.sql.ResultSet)73 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)71 HashMap (java.util.HashMap)70 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)63 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)63 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)61 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)60 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)59 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)58 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)57