Search in sources :

Example 36 with RequestCountLimit

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());
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) RequestCountLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO) ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO) Test(org.testng.annotations.Test)

Aggregations

RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)33 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)22 Test (org.testng.annotations.Test)14 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)11 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)9 ArrayList (java.util.ArrayList)8 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)8 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)7 IPCondition (org.wso2.carbon.apimgt.core.models.policy.IPCondition)4 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)4 RequestCountLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO)4 ThrottleLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO)4 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)3 Condition (org.wso2.carbon.apimgt.core.models.policy.Condition)3 HeaderCondition (org.wso2.carbon.apimgt.core.models.policy.HeaderCondition)3 JWTClaimsCondition (org.wso2.carbon.apimgt.core.models.policy.JWTClaimsCondition)3 QueryParameterCondition (org.wso2.carbon.apimgt.core.models.policy.QueryParameterCondition)3 AdvancedThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO)3 Limit (org.wso2.carbon.apimgt.core.models.policy.Limit)2 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)2