Search in sources :

Example 1 with RequestCountLimitDTO

use of org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtilTestCase method fromRequestCountThrottleLimitDtoToQuotaPolicyTest.

@Test(description = "Convert Request Count Throttle Limit DTO to Quota Policy")
public void fromRequestCountThrottleLimitDtoToQuotaPolicyTest() throws Exception {
    ThrottleLimitDTO throttleLimitDTO = new ThrottleLimitDTO();
    throttleLimitDTO.setType(PolicyConstants.REQUEST_COUNT_LIMIT_TYPE);
    RequestCountLimitDTO requestCountLimitDTO = new RequestCountLimitDTO();
    requestCountLimitDTO.setRequestCount(100);
    throttleLimitDTO.setRequestCountLimit(requestCountLimitDTO);
    throttleLimitDTO.setTimeUnit("sec");
    throttleLimitDTO.setUnitTime(1);
    QuotaPolicy policy = CommonThrottleMappingUtil.fromDTOToQuotaPolicy(throttleLimitDTO);
    Assert.assertNotNull(policy);
    RequestCountLimit limit = (RequestCountLimit) policy.getLimit();
    Assert.assertNotNull(limit);
    assertEquals(limit.getRequestCount(), 100);
    assertEquals(limit.getTimeUnit(), "sec");
    assertEquals(limit.getUnitTime(), 1);
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) Test(org.testng.annotations.Test)

Example 2 with RequestCountLimitDTO

use of org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO in project carbon-apimgt by wso2.

the class AdvancedThrottlePolicyMappingUtilTestCase method fromAdvancedPolicyDTOToPolicyTest.

@Test(description = "Convert Policy DTO to Policy object")
public void fromAdvancedPolicyDTOToPolicyTest() throws Exception {
    AdvancedThrottlePolicyDTO dto = new AdvancedThrottlePolicyDTO();
    dto.setDisplayName(APIMgtConstants.DEFAULT_API_POLICY);
    String uuid = UUID.randomUUID().toString();
    String description = "Sample Description";
    dto.setDescription(description);
    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);
    APIPolicy policy = AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyDTOToPolicy(dto);
    Assert.assertNotNull(policy);
    Assert.assertEquals(policy.getDisplayName(), APIMgtConstants.DEFAULT_API_POLICY);
    Assert.assertEquals(policy.getDescription(), description);
    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) AdvancedThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO) ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) Test(org.testng.annotations.Test)

Example 3 with RequestCountLimitDTO

use of org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO in project carbon-apimgt by wso2.

the class SubscriptionValidationDataUtil method fromRequestCountLimitToDTO.

/**
 * Converts a Request Count Limit model object into a Request Count Limit DTO object.
 *
 * @param requestCountLimit Request Count Limit model object
 * @return Request Count DTO object derived from model
 */
private static RequestCountLimitDTO fromRequestCountLimitToDTO(RequestCountLimit requestCountLimit) {
    RequestCountLimitDTO dto = new RequestCountLimitDTO();
    dto.setTimeUnit(requestCountLimit.getTimeUnit());
    dto.setUnitTime(requestCountLimit.getUnitTime());
    dto.setRequestCount(requestCountLimit.getRequestCount());
    return dto;
}
Also used : RequestCountLimitDTO(org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO)

Example 4 with RequestCountLimitDTO

use of org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromRequestCountLimitToDTO.

/**
 * Converts a Request Count Limit model object into a Request Count Limit DTO object
 *
 * @param requestCountLimit Request Count Limit model object
 * @return Request Count DTO object derived from model
 */
public static RequestCountLimitDTO fromRequestCountLimitToDTO(RequestCountLimit requestCountLimit) {
    // done
    RequestCountLimitDTO dto = new RequestCountLimitDTO();
    dto.setTimeUnit(requestCountLimit.getTimeUnit());
    dto.setUnitTime(requestCountLimit.getUnitTime());
    dto.setRequestCount(requestCountLimit.getRequestCount());
    return dto;
}
Also used : RequestCountLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RequestCountLimitDTO)

Example 5 with RequestCountLimitDTO

use of org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromRequestCountLimitToDTO.

/**
 * Converts a Request Count Limit model object into a Request Count Limit DTO object
 *
 * @param requestCountLimit Request Count Limit model object
 * @return Request Count DTO object derived from model
 */
public static ThrottleLimitDTO fromRequestCountLimitToDTO(RequestCountLimit requestCountLimit) {
    // done
    ThrottleLimitDTO dto = new ThrottleLimitDTO();
    dto = updateFieldsFromLimitToDTO(requestCountLimit, dto);
    dto.setType("RequestCountLimit");
    dto.setRequestCountLimit(new RequestCountLimitDTO());
    dto.getRequestCountLimit().setRequestCount(requestCountLimit.getRequestCount());
    return dto;
}
Also used : RequestCountLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO) ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO)

Aggregations

Test (org.testng.annotations.Test)4 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)4 RequestCountLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO)4 ThrottleLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO)4 ArrayList (java.util.ArrayList)1 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)1 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)1 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)1 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)1 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)1 RequestCountLimitDTO (org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO)1 AdvancedThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO)1 ApplicationThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO)1 CustomAttributeDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.CustomAttributeDTO)1 SubscriptionThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.SubscriptionThrottlePolicyDTO)1 RequestCountLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RequestCountLimitDTO)1