Search in sources :

Example 36 with Application

use of org.wso2.carbon.identity.oauth.dcr.bean.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 37 with Application

use of org.wso2.carbon.identity.oauth.dcr.bean.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 38 with Application

use of org.wso2.carbon.identity.oauth.dcr.bean.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)

Example 39 with Application

use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.

the class WorkflowExtensionsConfigBuilderTestCase method testWorkflowConfigWithoutConfigFile.

@Test(description = "Test situation where workflow config file loading during a missing config file")
public void testWorkflowConfigWithoutConfigFile() {
    WorkflowConfig config = WorkflowExtensionsConfigBuilder.getWorkflowConfig();
    Assert.assertNotNull(config.getApplicationCreation(), "Default application creation workflow not set");
    Assert.assertNotNull(config.getSubscriptionCreation(), "Default subscription creation workflow not set");
    Assert.assertNotNull(config.getApplicationDeletion(), "Default application deletion workflow not set");
    Assert.assertNotNull(config.getSubscriptionDeletion(), "Default subscription deletion workflow not set");
    WorkflowExtensionsConfigBuilder obj = new WorkflowExtensionsConfigBuilder();
    Assert.assertNotNull(obj);
}
Also used : WorkflowConfig(org.wso2.carbon.apimgt.core.models.WorkflowConfig) Test(org.testng.annotations.Test)

Example 40 with Application

use of org.wso2.carbon.identity.oauth.dcr.bean.Application in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesThrottlingApplicationIdPut.

/**
 * Updates/adds a new Application throttle policy to the system
 *
 * @param id          Uuid of the policy.
 * @param body              DTO object including the Policy meta information
 * @param ifMatch           If-Match header value
 * @param ifUnmodifiedSince If-Unmodified-Since header value
 * @param request           msf4j request object
 * @return Response object  response object with the updated application throttle policy resource
 * @throws NotFoundException if an error occurred when particular resource does not exits in the system.
 */
@Override
public Response policiesThrottlingApplicationIdPut(String id, ApplicationThrottlePolicyDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
    APIMgtAdminService.PolicyLevel tierLevel = APIMgtAdminService.PolicyLevel.application;
    if (log.isDebugEnabled()) {
        log.info("Received Application Policy PUT request " + body + " with tierLevel = " + tierLevel);
    }
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        ApplicationPolicy applicationPolicy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(body);
        applicationPolicy.setUuid(id);
        apiMgtAdminService.updateApplicationPolicy(applicationPolicy);
        return Response.status(Response.Status.OK).entity(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(apiMgtAdminService.getApplicationPolicyByUuid(id))).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while updating Application Policy. policy uuid: " + id;
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Aggregations

Test (org.testng.annotations.Test)266 ArrayList (java.util.ArrayList)173 SQLException (java.sql.SQLException)172 PreparedStatement (java.sql.PreparedStatement)169 Connection (java.sql.Connection)148 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)145 ResultSet (java.sql.ResultSet)135 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)131 Application (org.wso2.carbon.apimgt.api.model.Application)130 HashMap (java.util.HashMap)122 Application (org.wso2.carbon.apimgt.core.models.Application)121 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)110 Test (org.junit.Test)102 IOException (java.io.IOException)74 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)73 Subscriber (org.wso2.carbon.apimgt.api.model.Subscriber)71 JSONObject (org.json.simple.JSONObject)68 Response (javax.ws.rs.core.Response)65 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)63 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)63