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;
}
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);
}
Aggregations