use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createApplicationPolicyWithBndwidthLimit.
public static ApplicationPolicy createApplicationPolicyWithBndwidthLimit(String name) {
ApplicationPolicy applicationPolicy = new ApplicationPolicy(name);
applicationPolicy.setDescription("testDescription");
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("bandwidth");
BandwidthLimit bandwidthLimit = new BandwidthLimit("s", 60, 10, "mb");
quotaPolicy.setLimit(bandwidthLimit);
applicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
applicationPolicy.setDisplayName("displayName");
return applicationPolicy;
}
use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy 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();
}
}
use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtil method fromApplicationPolicyArrayToListDTO.
/**
* Converts an array of Application Policy objects into a List DTO
*
* @param appPolicies Array of Application Policies
* @return A List DTO of converted Application Policies
* @throws UnsupportedThrottleLimitTypeException - If error occurs
*/
public static ApplicationThrottlePolicyListDTO fromApplicationPolicyArrayToListDTO(List<ApplicationPolicy> appPolicies) throws UnsupportedThrottleLimitTypeException, UnsupportedThrottleConditionTypeException {
ApplicationThrottlePolicyListDTO listDTO = new ApplicationThrottlePolicyListDTO();
List<ApplicationThrottlePolicyDTO> appPolicyDTOList = new ArrayList<>();
if (appPolicies != null) {
for (Policy policy : appPolicies) {
ApplicationThrottlePolicyDTO dto = fromApplicationThrottlePolicyToDTO(policy);
appPolicyDTOList.add(dto);
}
}
listDTO.setCount(appPolicyDTOList.size());
listDTO.setList(appPolicyDTOList);
return listDTO;
}
use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy in project carbon-apimgt by wso2.
the class PolicyExportManagerTest method testCreateArchiveFromExecutionPlans.
@Test(description = "testing creating archive from execution plans")
public void testCreateArchiveFromExecutionPlans() throws APIManagementException {
APIMgtAdminService apiMgtAdminService = Mockito.mock(APIMgtAdminService.class);
List<APIPolicy> apiPolicies = new ArrayList<>();
List<ApplicationPolicy> applicationPolicies = new ArrayList<>();
List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
List<CustomPolicy> customPolicies = new ArrayList<>();
apiPolicies.add(SampleTestObjectCreator.createDefaultAPIPolicy());
applicationPolicies.add(SampleTestObjectCreator.createDefaultApplicationPolicy());
subscriptionPolicies.add(SampleTestObjectCreator.createDefaultSubscriptionPolicy());
customPolicies.add(SampleTestObjectCreator.createDefaultCustomPolicy());
Mockito.when(apiMgtAdminService.getApiPolicies()).thenReturn(apiPolicies);
Mockito.when(apiMgtAdminService.getApplicationPolicies()).thenReturn(applicationPolicies);
Mockito.when(apiMgtAdminService.getCustomRules()).thenReturn(customPolicies);
Mockito.when(apiMgtAdminService.getSubscriptionPolicies()).thenReturn(subscriptionPolicies);
PolicyExportManager policyExportManager = new PolicyExportManager(apiMgtAdminService);
String path = policyExportManager.createArchiveFromExecutionPlans("exportDir", exportRootDirectory, "policies");
String unzippedPath = exportRootDirectory + File.separator + "export-policies";
APIFileUtils.extractArchive(path, unzippedPath);
Assert.assertEquals(new File(APIFileUtils.getDirectoryList(unzippedPath).iterator().next()).listFiles().length == 6, true, "Exported policy count is not equal to ");
}
use of org.wso2.micro.gateway.tests.common.model.ApplicationPolicy in project carbon-apimgt by wso2.
the class ApplicationMappingUtil method fromDTOtoApplication.
public static Application fromDTOtoApplication(ApplicationDTO applicationDTO, String createdUser) {
// subscriber field of the body is not honored
Application application = new Application(applicationDTO.getName(), createdUser);
application.setPolicy(new ApplicationPolicy(applicationDTO.getThrottlingTier()));
application.setDescription(applicationDTO.getDescription());
application.setId(applicationDTO.getApplicationId());
application.setPermissionString(applicationDTO.getPermission());
application.setStatus(applicationDTO.getLifeCycleStatus());
// application.setGroupId(applicationDTO.getGroupId());
return application;
}
Aggregations