Search in sources :

Example 1 with BandwidthLimitDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.BandwidthLimitDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromBandwidthLimitToDTO.

/**
 * Converts a Bandwidth Limit model object into a Bandwidth Limit DTO object
 *
 * @param bandwidthLimit Bandwidth Limit model object
 * @return Bandwidth Limit DTO object derived from model
 */
public static ThrottleLimitDTO fromBandwidthLimitToDTO(BandwidthLimit bandwidthLimit) {
    // done
    ThrottleLimitDTO dto = new ThrottleLimitDTO();
    dto = updateFieldsFromLimitToDTO(bandwidthLimit, dto);
    dto.setType(PolicyConstants.BANDWIDTH_LIMIT_TYPE);
    dto.setBandwidthLimit(new BandwidthLimitDTO());
    dto.getBandwidthLimit().setDataAmount(bandwidthLimit.getDataAmount());
    dto.getBandwidthLimit().setDataUnit(bandwidthLimit.getDataUnit());
    return dto;
}
Also used : ThrottleLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO) BandwidthLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.BandwidthLimitDTO)

Example 2 with BandwidthLimitDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.BandwidthLimitDTO in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtilTestCase method fromBandwidthThrottleLimitDtoToQuotaPolicyTest.

@Test(description = "Convert Bandwidth Throttle Limit DTO to Quota Policy")
public void fromBandwidthThrottleLimitDtoToQuotaPolicyTest() throws Exception {
    ThrottleLimitDTO throttleLimitDTO = new ThrottleLimitDTO();
    throttleLimitDTO.setType(PolicyConstants.BANDWIDTH_LIMIT_TYPE);
    BandwidthLimitDTO bandwidthLimitDTO = new BandwidthLimitDTO();
    bandwidthLimitDTO.setDataAmount(10);
    bandwidthLimitDTO.setDataUnit(KB);
    throttleLimitDTO.setBandwidthLimit(bandwidthLimitDTO);
    throttleLimitDTO.setTimeUnit("min");
    throttleLimitDTO.setUnitTime(1);
    QuotaPolicy policy = CommonThrottleMappingUtil.fromDTOToQuotaPolicy(throttleLimitDTO);
    Assert.assertNotNull(policy);
    assertEquals(policy.getType(), PolicyConstants.BANDWIDTH_TYPE);
    BandwidthLimit bandwidthLimit = (BandwidthLimit) policy.getLimit();
    assertEquals(bandwidthLimit.getDataAmount(), 10);
    assertEquals(bandwidthLimit.getDataUnit(), KB);
    assertEquals(bandwidthLimit.getTimeUnit(), "min");
    assertEquals(bandwidthLimit.getUnitTime(), 1);
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)1 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)1 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)1 BandwidthLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.BandwidthLimitDTO)1 ThrottleLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO)1