use of org.wso2.carbon.apimgt.api.model.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);
}
use of org.wso2.carbon.apimgt.api.model.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;
}
use of org.wso2.carbon.apimgt.api.model.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");
}
use of org.wso2.carbon.apimgt.api.model.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);
}
use of org.wso2.carbon.apimgt.api.model.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();
}
}
Aggregations