use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testDeleteApplication.
@Test
public void testDeleteApplication() throws Exception {
// add app
Application app = TestUtil.addTestApplication();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
// delete app
applicationDAO.deleteApplication(app.getId());
try {
applicationDAO.getApplication(app.getId());
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Application is not available in the system.");
}
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testUpdateApplicationState.
@Test
public void testUpdateApplicationState() throws Exception {
// add new app
Application app = TestUtil.addTestApplication();
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
// update app
applicationDAO.updateApplicationState(app.getId(), APIMgtConstants.ApplicationStatus.APPLICATION_APPROVED);
// get app
Application appFromDB = applicationDAO.getApplication(app.getId());
Assert.assertNotNull(appFromDB);
// check whether the status has updated
Assert.assertEquals(appFromDB.getStatus(), APIMgtConstants.ApplicationStatus.APPLICATION_APPROVED);
// compare
Assert.assertNotEquals(appFromDB, app, TestUtil.printDiff(appFromDB, app));
validateAppTimestamps(appFromDB, app);
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testAddAndGetApplicationKeys.
@Test
public void testAddAndGetApplicationKeys() throws Exception {
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
// add test app
Application app = TestUtil.addTestApplicationWithPermissions();
String appId = app.getId();
String prodConsumerKey = "prod-xxx";
String sandConsumerKey = "sand-yyy";
// add prod key
applicationDAO.addApplicationKeys(appId, KeyManagerConstants.OAUTH_CLIENT_PRODUCTION, prodConsumerKey);
// get by key type
OAuthApplicationInfo keysFromDB = applicationDAO.getApplicationKeys(appId, KeyManagerConstants.OAUTH_CLIENT_PRODUCTION);
Assert.assertEquals(keysFromDB.getClientId(), prodConsumerKey);
// add sand key
applicationDAO.addApplicationKeys(appId, KeyManagerConstants.OAUTH_CLIENT_SANDBOX, sandConsumerKey);
// get all keys
List<OAuthApplicationInfo> allKeysFromDB = applicationDAO.getApplicationKeys(appId);
Assert.assertEquals(allKeysFromDB.size(), 2, "Wrong number of keys are returned.");
// this should stay 0 at the end
int i = 0;
for (OAuthApplicationInfo oAuthApplicationInfo : allKeysFromDB) {
switch(oAuthApplicationInfo.getKeyType()) {
case KeyManagerConstants.OAUTH_CLIENT_PRODUCTION:
Assert.assertEquals(oAuthApplicationInfo.getClientId(), prodConsumerKey);
i++;
break;
case KeyManagerConstants.OAUTH_CLIENT_SANDBOX:
Assert.assertEquals(oAuthApplicationInfo.getClientId(), sandConsumerKey);
i--;
break;
default:
Assert.fail("Invalid key type.");
break;
}
}
Assert.assertEquals(i, 0, "Received key counts of each type is not 1");
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class ApplicationDAOImplIT method testGetAllApplicationsForValidation.
@Test
public void testGetAllApplicationsForValidation() throws Exception {
// add 4 apps
String username = "admin";
Application app1 = TestUtil.addCustomApplication("App1", username);
Application app2 = TestUtil.addCustomApplication("App2", username);
Application app3 = TestUtil.addCustomApplication("App3", username);
Application app4 = TestUtil.addCustomApplication("App4", username);
ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
// get added apps
List<Application> appsFromDB = applicationDAO.getAllApplications();
Assert.assertNotNull(appsFromDB);
Assert.assertEquals(appsFromDB.size(), 4);
for (Application application : appsFromDB) {
Assert.assertNotNull(application);
if (application.getName().equals(app1.getName())) {
validateApp(application, app1, policyDAO);
} else if (application.getName().equals(app2.getName())) {
validateApp(application, app2, policyDAO);
} else if (application.getName().equals(app3.getName())) {
validateApp(application, app3, policyDAO);
} else if (application.getName().equals(app4.getName())) {
validateApp(application, app4, policyDAO);
} else {
Assert.fail("Invalid Application returned.");
}
}
}
use of org.wso2.carbon.apimgt.core.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class SubscriptionDAOImplIT method testGetSubscriptionForApplicationAndApiType.
@Test
public void testGetSubscriptionForApplicationAndApiType() 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 (api2)
List<Subscription> subscriptions = subscriptionDAO.getAPISubscriptionsByApplication(app1.getId(), ApiType.STANDARD);
// validate subscriptions
Assert.assertEquals(subscriptions.size(), 1, "There should be 1 subscriptions (only).");
for (Subscription subscription : subscriptions) {
Assert.assertNotNull(subscription);
if (subscription.getApi().getId().equals(api2.getId())) {
Assert.assertEquals(subscription.getApi(), TestUtil.createSummaryAPI(api2), TestUtil.printDiff(subscription.getApi(), TestUtil.createSummaryAPI(api2)));
} else {
Assert.fail(INVALID_SUBSCRIPTION_FOUND);
}
}
}
Aggregations