use of org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtilTest method fromSubscriptionThrottlePolicyDTOToModelTest.
@Test(description = "Convert Subscription Throttle Policy DTO to Model")
public void fromSubscriptionThrottlePolicyDTOToModelTest() throws Exception {
SubscriptionThrottlePolicyDTO dto = new SubscriptionThrottlePolicyDTO();
dto.setRateLimitTimeUnit("m");
dto.setRateLimitCount(1);
dto.setStopOnQuotaReach(true);
ThrottleLimitDTO throttleLimitDTO = new ThrottleLimitDTO();
throttleLimitDTO.setType("RequestCountLimit");
throttleLimitDTO.setTimeUnit("s");
throttleLimitDTO.setUnitTime(1);
RequestCountLimitDTO requestCountLimitDTO = new RequestCountLimitDTO();
requestCountLimitDTO.setRequestCount(2);
throttleLimitDTO.setRequestCountLimit(requestCountLimitDTO);
dto.setDefaultLimit(throttleLimitDTO);
List<CustomAttributeDTO> customAttributeDTOs = new ArrayList<>();
CustomAttributeDTO customAttributeDTO1 = new CustomAttributeDTO();
customAttributeDTO1.setName("ABC");
customAttributeDTO1.setValue("ABCVALUE");
CustomAttributeDTO customAttributeDTO2 = new CustomAttributeDTO();
customAttributeDTO2.setName("CDE");
customAttributeDTO2.setValue("CDEVALUE");
customAttributeDTOs.add(customAttributeDTO1);
customAttributeDTOs.add(customAttributeDTO2);
dto.setCustomAttributes(customAttributeDTOs);
SubscriptionPolicy policy = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionThrottlePolicyDTOToModel(dto);
Assert.assertNotNull(policy);
Assert.assertEquals(policy.getRateLimitCount(), 1);
Assert.assertEquals(policy.getRateLimitTimeUnit(), "m");
Assert.assertEquals(policy.isStopOnQuotaReach(), true);
Assert.assertEquals(policy.getDefaultQuotaPolicy().getType(), "requestCount");
Assert.assertEquals(policy.getDefaultQuotaPolicy().getLimit().getTimeUnit(), dto.getDefaultLimit().getTimeUnit());
Assert.assertEquals((Integer) policy.getDefaultQuotaPolicy().getLimit().getUnitTime(), dto.getDefaultLimit().getUnitTime());
Assert.assertEquals((Integer) ((RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit()).getRequestCount(), dto.getDefaultLimit().getRequestCountLimit().getRequestCount());
Assert.assertTrue(new String(policy.getCustomAttributes()).contains("ABC"));
Assert.assertTrue(new String(policy.getCustomAttributes()).contains("ABCVALUE"));
Assert.assertTrue(new String(policy.getCustomAttributes()).contains("CDE"));
Assert.assertTrue(new String(policy.getCustomAttributes()).contains("CDEVALUE"));
}
use of org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtilTest method fromApplicationThrottlePolicyDTOToModelTest.
@Test(description = "Convert from DTO to Policy")
public void fromApplicationThrottlePolicyDTOToModelTest() throws Exception {
ApplicationThrottlePolicyDTO dto = new ApplicationThrottlePolicyDTO();
dto.setDisplayName(displayName);
dto.setPolicyName(policyName);
dto.setId(uuid);
ThrottleLimitDTO throttleLimitDTO = new ThrottleLimitDTO();
throttleLimitDTO.setType("RequestCountLimit");
throttleLimitDTO.setTimeUnit("s");
throttleLimitDTO.setUnitTime(1);
RequestCountLimitDTO requestCountLimitDTO = new RequestCountLimitDTO();
requestCountLimitDTO.setRequestCount(2);
throttleLimitDTO.setRequestCountLimit(requestCountLimitDTO);
dto.setDefaultLimit(throttleLimitDTO);
ApplicationPolicy policy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(dto);
Assert.assertNotNull(policy);
Assert.assertEquals(policy.getDisplayName(), displayName);
Assert.assertEquals(policy.getPolicyName(), policyName);
Assert.assertEquals(policy.getDefaultQuotaPolicy().getType(), "requestCount");
Assert.assertEquals(policy.getDefaultQuotaPolicy().getLimit().getTimeUnit(), dto.getDefaultLimit().getTimeUnit());
Assert.assertEquals((Integer) policy.getDefaultQuotaPolicy().getLimit().getUnitTime(), dto.getDefaultLimit().getUnitTime());
Assert.assertEquals((Integer) ((RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit()).getRequestCount(), dto.getDefaultLimit().getRequestCountLimit().getRequestCount());
}
use of org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtil method fromDTOToRequestCountLimit.
/**
* Converts a Request Count Limit DTO object into a Request Count model object
*
* @param dto Request Count Limit DTO object
* @return Request Count Limit model object derived from DTO
*/
public static RequestCountLimit fromDTOToRequestCountLimit(RequestCountLimitDTO dto) {
RequestCountLimit requestCountLimit = new RequestCountLimit();
requestCountLimit.setTimeUnit(dto.getTimeUnit());
requestCountLimit.setUnitTime(dto.getUnitTime());
requestCountLimit.setRequestCount(dto.getRequestCount());
return requestCountLimit;
}
Aggregations