Search in sources :

Example 36 with ApplicationDAO

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.");
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 37 with ApplicationDAO

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);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 38 with ApplicationDAO

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");
}
Also used : OAuthApplicationInfo(org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 39 with ApplicationDAO

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.");
        }
    }
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 40 with ApplicationDAO

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);
        }
    }
}
Also used : APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) API(org.wso2.carbon.apimgt.core.models.API) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Aggregations

ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)62 Test (org.testng.annotations.Test)56 Application (org.wso2.carbon.apimgt.core.models.Application)50 BeforeTest (org.testng.annotations.BeforeTest)32 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)32 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)21 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)18 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)18 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)15 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)15 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)13 API (org.wso2.carbon.apimgt.core.models.API)12 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)10 SQLException (java.sql.SQLException)8 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)7 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)6 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)5 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)5 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)4