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);
}
}
}
Aggregations