use of org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit 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());
}
Aggregations