Search in sources :

Example 36 with Application

use of org.wso2.carbon.apimgt.core.models.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 37 with Application

use of org.wso2.carbon.apimgt.core.models.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)

Example 38 with Application

use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.

the class ApplicationDAOImplIT method testUpdateApplication.

@Test
public void testUpdateApplication() throws Exception {
    // add new app
    Application currentApp = TestUtil.addTestApplication();
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    Application newApp = SampleTestObjectCreator.createAlternativeApplication();
    newApp.setId(currentApp.getId());
    newApp.setCreatedTime(currentApp.getCreatedTime());
    // update app
    applicationDAO.updateApplication(currentApp.getId(), newApp);
    // get app
    Application appFromDB = applicationDAO.getApplication(newApp.getId());
    Assert.assertNotNull(appFromDB);
    // compare
    Assert.assertEquals(appFromDB, newApp, TestUtil.printDiff(appFromDB, newApp));
    validateAppTimestamps(appFromDB, newApp);
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) Test(org.testng.annotations.Test)

Example 39 with Application

use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultApplication.

public static Application createDefaultApplication() {
    // created by admin
    Application application = new Application(TEST_APP_1, ADMIN);
    application.setId(UUID.randomUUID().toString());
    application.setDescription("This is a test application");
    application.setStatus(APIMgtConstants.ApplicationStatus.APPLICATION_CREATED);
    application.setPolicy(fiftyPerMinApplicationPolicy);
    application.setCreatedTime(LocalDateTime.now());
    application.setUpdatedUser(ADMIN);
    application.setUpdatedTime(LocalDateTime.now());
    return application;
}
Also used : Application(org.wso2.carbon.apimgt.core.models.Application)

Example 40 with Application

use of org.wso2.carbon.apimgt.core.models.Application in project carbon-apimgt by wso2.

the class APIFileUtilsTestCase method testAPIFileUtils.

@Test
public void testAPIFileUtils() throws Exception {
    APIFileUtils.createDirectory(dirPath);
    Assert.assertTrue(Files.exists(Paths.get(dirPath)), "Directory doesn't exists");
    String filePath = dirPath + File.separatorChar + fileName;
    APIFileUtils.createFile(filePath);
    Assert.assertTrue(Files.exists(Paths.get(filePath)), "File doesn't exists");
    // write content to file
    APIFileUtils.writeToFile(dirPath + File.separatorChar + fileName, "This is some test content");
    // read content as text
    String contentRead = APIFileUtils.readFileContentAsText(dirPath + File.separatorChar + fileName);
    Assert.assertEquals(contentRead, "This is some test content");
    // read content as stream
    InputStream contentReadInputStream = APIFileUtils.readFileContentAsStream(dirPath + File.separatorChar + fileName);
    Assert.assertEquals(IOUtils.toString(contentReadInputStream), "This is some test content");
    // write stream to filesystem
    APIFileUtils.writeStreamToFile(dirPath + File.separatorChar + "write-stream-to-file", contentReadInputStream);
    Assert.assertTrue(Files.exists(Paths.get(dirPath + File.separatorChar + "write-stream-to-file")), "File doesn't exists");
    // create archive
    APIFileUtils.archiveDirectory(new File(dirPath).getAbsolutePath(), new File(parentDir + File.separatorChar).getAbsolutePath(), "my-test-archive");
    Assert.assertTrue(Files.exists(Paths.get(parentDir + File.separatorChar + "my-test-archive.zip")), "File doesn't exists");
    // find in file system
    Assert.assertNotNull(APIFileUtils.findInFileSystem(new File(dirPath), fileName));
    // write object as json
    GatewayConfigDTO configDTO = new GatewayConfigDTO();
    configDTO.setApiName("api1");
    configDTO.setConfig("config");
    configDTO.setContext("context");
    APIFileUtils.writeObjectAsJsonToFile(configDTO, dirPath + File.separatorChar + "object.json");
    Assert.assertTrue(Files.exists(Paths.get(dirPath + File.separatorChar + "object.json")), "File doesn't exists");
    // write string as json
    APIFileUtils.writeStringAsJsonToFile("{\"config\":\"config\"}", dirPath + File.separatorChar + "object-2.json");
    Assert.assertTrue(Files.exists(Paths.get(dirPath + File.separatorChar + "object-2.json")), "File doesn't exists");
    // list directories
    Assert.assertTrue(APIFileUtils.getDirectoryList(parentDir).size() > 0);
    // export API Definition
    FileApi fileApi = new FileApi();
    fileApi.setApiDefinition("api-definition");
    fileApi.setName("test-api");
    fileApi.setVersion("1.0.0");
    fileApi.setProvider("p1");
    fileApi.setId("1x1x");
    APIFileUtils.exportApiDefinitionToFileSystem(fileApi, parentDir);
    Assert.assertTrue(Files.exists(Paths.get(parentDir + File.separatorChar + "api-1x1x.json")), "File doesn't exists");
    // export swagger definition
    String swaggerDefinition = "{\"swaggerVersion\": \"1.2\",\"apis\": [{\"path\": " + "\"http://localhost:8000/listings/greetings\"," + "\"description\": \"Generating greetings in our application.\"}]}";
    APIFileUtils.exportSwaggerDefinitionToFileSystem(swaggerDefinition, new API.APIBuilder("p", "name", "1.0").id("1x1x").build(), parentDir);
    Assert.assertTrue(Files.exists(Paths.get(parentDir + File.separatorChar + "swagger-1x1x.json")), "File doesn't exists");
    // export endpoint
    APIFileUtils.exportEndpointToFileSystem(SampleTestObjectCreator.createMockEndpoint(), parentDir);
    Assert.assertTrue(Files.exists(Paths.get(parentDir + File.separatorChar + "Endpoint1.json")), "Endpoint doesn't exists");
    // export gatewayconfig
    APIFileUtils.exportGatewayConfigToFileSystem("gateway-config-content-goes-here", new API.APIBuilder("p", "name-5", "1.0").id("5x5x").build(), parentDir);
    Assert.assertTrue(Files.exists(Paths.get(parentDir + File.separatorChar + "gateway-configuration")), "Gateway config doesn't exists");
    // delete file
    APIFileUtils.deleteFile(filePath);
    Assert.assertFalse(Files.exists(Paths.get(filePath)), "File has not deleted");
    // delete directory
    APIFileUtils.deleteDirectory(dirPath);
    Assert.assertFalse(Files.exists(Paths.get(dirPath)), "Directory has not deleted");
}
Also used : GatewayConfigDTO(org.wso2.carbon.apimgt.core.template.dto.GatewayConfigDTO) InputStream(java.io.InputStream) API(org.wso2.carbon.apimgt.core.models.API) File(java.io.File) FileApi(org.wso2.carbon.apimgt.core.models.FileApi) Test(org.testng.annotations.Test)

Aggregations

Application (org.wso2.carbon.apimgt.core.models.Application)121 Test (org.testng.annotations.Test)91 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)61 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 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)40 ArrayList (java.util.ArrayList)35 SQLException (java.sql.SQLException)33 API (org.wso2.carbon.apimgt.core.models.API)33 Test (org.junit.Test)29 BeforeTest (org.testng.annotations.BeforeTest)29 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)29 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)27 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)27 Connection (java.sql.Connection)26 PreparedStatement (java.sql.PreparedStatement)26 HashMap (java.util.HashMap)26 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)25