Search in sources :

Example 31 with Application

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

the class ApiDAOImplIT method testGetDocumentContent.

@Test(description = "Getting document content for an API")
public void testGetDocumentContent() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    testAddGetEndpoint();
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    apiDAO.addAPI(api);
    DocumentInfo documentInfo1 = SampleTestObjectCreator.createDefaultDocumentationInfo();
    apiDAO.addDocumentInfo(api.getId(), documentInfo1);
    List<DocumentInfo> documentInfoList = new ArrayList<>();
    documentInfoList.add(documentInfo1);
    List<DocumentInfo> documentInfoListFromDB = apiDAO.getDocumentsInfoList(api.getId());
    Assert.assertTrue(documentInfoListFromDB.containsAll(documentInfoList));
    DocumentInfo documentInfo = SampleTestObjectCreator.createFileDocumentationInfo();
    apiDAO.addDocumentInfo(api.getId(), documentInfo);
    byte[] contentBytes = SampleTestObjectCreator.createDefaultFileDocumentationContent();
    apiDAO.addDocumentFileContent(documentInfo.getId(), new ByteArrayInputStream(contentBytes), "application/pdf", ADMIN);
    byte[] retrievedContentFromDB = IOUtils.toByteArray(apiDAO.getDocumentFileContent(documentInfo.getId()));
    Assert.assertEquals(contentBytes.length, retrievedContentFromDB.length);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) Test(org.testng.annotations.Test)

Example 32 with Application

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

the class ApplicationDAOImplIT method testFingerprintAfterUpdatingApplication.

@Test
public void testFingerprintAfterUpdatingApplication() throws Exception {
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    // add new app
    Application currentApp = TestUtil.addTestApplication();
    String fingerprintBeforeUpdate = ETagUtils.generateETag(applicationDAO.getLastUpdatedTimeOfApplication(currentApp.getId()));
    Assert.assertNotNull(fingerprintBeforeUpdate);
    Thread.sleep(1);
    Application newApp = SampleTestObjectCreator.createAlternativeApplication();
    newApp.setId(currentApp.getId());
    newApp.setCreatedTime(currentApp.getCreatedTime());
    // update app
    applicationDAO.updateApplication(currentApp.getId(), newApp);
    String fingerprintAfterUpdate = ETagUtils.generateETag(applicationDAO.getLastUpdatedTimeOfApplication(currentApp.getId()));
    Assert.assertNotNull(fingerprintAfterUpdate);
    // compare
    Assert.assertNotEquals(fingerprintBeforeUpdate, fingerprintAfterUpdate);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 33 with Application

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

the class ApplicationDAOImplIT method testAddAndGetApplication.

@Test
public void testAddAndGetApplication() throws Exception {
    // add new app
    Application app = TestUtil.addTestApplication();
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    // get added app
    Application appFromDB = applicationDAO.getApplication(app.getId());
    Assert.assertNotNull(appFromDB);
    // compare
    Assert.assertEquals(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 34 with Application

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

the class ApplicationDAOImplIT method testGetAllApplications.

@Test
public void testGetAllApplications() 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();
    // get added apps
    List<Application> appsFromDB = applicationDAO.getApplications(username);
    Assert.assertNotNull(appsFromDB);
    Assert.assertEquals(appsFromDB.size(), 4);
    for (Application application : appsFromDB) {
        Assert.assertNotNull(application);
        if (application.getName().equals(app1.getName())) {
            Assert.assertEquals(application, app1, TestUtil.printDiff(application, app1));
            validateAppTimestamps(application, app1);
        } else if (application.getName().equals(app2.getName())) {
            Assert.assertEquals(application, app2, TestUtil.printDiff(application, app2));
            validateAppTimestamps(application, app2);
        } else if (application.getName().equals(app3.getName())) {
            Assert.assertEquals(application, app3, TestUtil.printDiff(application, app3));
            validateAppTimestamps(application, app3);
        } else if (application.getName().equals(app4.getName())) {
            Assert.assertEquals(application, app4, TestUtil.printDiff(application, app4));
            validateAppTimestamps(application, app4);
        } else {
            Assert.fail("Invalid Application returned.");
        }
    }
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 35 with Application

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

the class ApplicationDAOImplIT method testAddApplicationWithPermissions.

@Test
public void testAddApplicationWithPermissions() throws Exception {
    // add new app with permissions
    Application app = TestUtil.addTestApplicationWithPermissions();
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    // get added app
    Application appFromDB = applicationDAO.getApplication(app.getId());
    Assert.assertNotNull(appFromDB);
    // compare
    Assert.assertEquals(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)

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