use of org.wso2.carbon.identity.application.authentication.framework.model.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.");
}
use of org.wso2.carbon.identity.application.authentication.framework.model.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)));
}
use of org.wso2.carbon.identity.application.authentication.framework.model.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);
}
}
use of org.wso2.carbon.identity.application.authentication.framework.model.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);
}
use of org.wso2.carbon.identity.application.authentication.framework.model.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);
}
Aggregations