Search in sources :

Example 16 with ThrottleLimitDTO

use of org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO 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"));
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) RequestCountLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) SubscriptionThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.SubscriptionThrottlePolicyDTO) ArrayList(java.util.ArrayList) ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO) CustomAttributeDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.CustomAttributeDTO) Test(org.testng.annotations.Test)

Example 17 with ThrottleLimitDTO

use of org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO 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

Test (org.testng.annotations.Test)5 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)5 ThrottleLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO)5 EventCountLimit (org.wso2.carbon.apimgt.api.model.policy.EventCountLimit)4 RequestCountLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO)4 BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)3 QuotaPolicy (org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy)3 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)3 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)3 RequestCountLimitDTO (org.wso2.apimgt.gateway.cli.model.rest.policy.RequestCountLimitDTO)2 ThrottleLimitDTO (org.wso2.apimgt.gateway.cli.model.rest.policy.ThrottleLimitDTO)2 UnsupportedThrottleLimitTypeException (org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException)2 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)2 ThrottleLimitDTO (org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO)2 UnsupportedThrottleLimitTypeException (org.wso2.carbon.apimgt.rest.api.admin.exceptions.UnsupportedThrottleLimitTypeException)2 ThrottleLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleLimitDTO)2 ArrayList (java.util.ArrayList)1 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)1 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)1 Limit (org.wso2.carbon.apimgt.core.models.policy.Limit)1