use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy 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);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy 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);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtilTestCase method fromAdvancedPolicyToDTOTest.
@Test(description = "Convert Policy to DTO")
public void fromAdvancedPolicyToDTOTest() throws Exception {
APIPolicy apiPolicy = new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY);
String uuid = UUID.randomUUID().toString();
String displayName = "SampleAPIPolicy";
String description = "Sample Description";
apiPolicy.setUuid(uuid);
apiPolicy.setDisplayName(displayName);
apiPolicy.setDescription(description);
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("requestCount");
RequestCountLimit requestCountLimit = new RequestCountLimit("s", 60, 10);
quotaPolicy.setLimit(requestCountLimit);
apiPolicy.setDefaultQuotaPolicy(quotaPolicy);
AdvancedThrottlePolicyDTO dto = AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyToDTO(apiPolicy);
Assert.assertNotNull(dto);
Assert.assertEquals(dto.getPolicyName(), APIMgtConstants.DEFAULT_API_POLICY);
Assert.assertEquals(dto.getDisplayName(), displayName);
Assert.assertEquals(dto.getDescription(), description);
Assert.assertEquals(apiPolicy.getDefaultQuotaPolicy().getLimit().getTimeUnit(), dto.getDefaultLimit().getTimeUnit());
Assert.assertEquals((Integer) apiPolicy.getDefaultQuotaPolicy().getLimit().getUnitTime(), dto.getDefaultLimit().getUnitTime());
Assert.assertEquals((Integer) ((RequestCountLimit) apiPolicy.getDefaultQuotaPolicy().getLimit()).getRequestCount(), dto.getDefaultLimit().getRequestCountLimit().getRequestCount());
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy in project carbon-apimgt by wso2.
the class SubscriptionValidationDAO method setCommonProperties.
private void setCommonProperties(APIPolicyConditionGroup apiPolicyConditionGroup, ResultSet resultSet) throws SQLException {
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType(resultSet.getString(ThrottlePolicyConstants.COLUMN_QUOTA_POLICY_TYPE));
if (quotaPolicy.getType() != null) {
if (PolicyConstants.REQUEST_COUNT_TYPE.equalsIgnoreCase(quotaPolicy.getType())) {
RequestCountLimit reqLimit = new RequestCountLimit();
reqLimit.setUnitTime(resultSet.getInt(ThrottlePolicyConstants.COLUMN_UNIT_TIME));
reqLimit.setTimeUnit(resultSet.getString(ThrottlePolicyConstants.COLUMN_TIME_UNIT));
reqLimit.setRequestCount(resultSet.getInt(ThrottlePolicyConstants.COLUMN_QUOTA));
quotaPolicy.setLimit(reqLimit);
} else if (PolicyConstants.BANDWIDTH_TYPE.equalsIgnoreCase(quotaPolicy.getType())) {
BandwidthLimit bandLimit = new BandwidthLimit();
bandLimit.setUnitTime(resultSet.getInt(ThrottlePolicyConstants.COLUMN_UNIT_TIME));
bandLimit.setTimeUnit(resultSet.getString(ThrottlePolicyConstants.COLUMN_TIME_UNIT));
bandLimit.setDataAmount(resultSet.getInt(ThrottlePolicyConstants.COLUMN_QUOTA));
bandLimit.setDataUnit(resultSet.getString(ThrottlePolicyConstants.COLUMN_QUOTA_UNIT));
quotaPolicy.setLimit(bandLimit);
}
apiPolicyConditionGroup.setQuotaPolicy(quotaPolicy);
}
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy in project carbon-apimgt by wso2.
the class APIProviderImplTest method getPolicyAPILevelPerUser.
private APIPolicy getPolicyAPILevelPerUser() {
APIPolicy policy = new APIPolicy("custom1");
policy.setUserLevel(PolicyConstants.PER_USER);
policy.setDescription("Description");
// policy.setPolicyLevel("api");
policy.setTenantDomain("carbon.super");
RequestCountLimit defaultLimit = new RequestCountLimit();
defaultLimit.setTimeUnit("min");
defaultLimit.setUnitTime(5);
defaultLimit.setRequestCount(400);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setLimit(defaultLimit);
defaultQuotaPolicy.setType("RequestCount");
policy.setDefaultQuotaPolicy(defaultQuotaPolicy);
List<Pipeline> pipelines;
Pipeline p;
QuotaPolicy quotaPolicy;
List<Condition> condition;
RequestCountLimit countlimit;
Condition cond;
pipelines = new ArrayList<Pipeline>();
// /////////pipeline item start//////
p = new Pipeline();
quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("RequestCount");
countlimit = new RequestCountLimit();
countlimit.setTimeUnit("min");
countlimit.setUnitTime(5);
countlimit.setRequestCount(100);
quotaPolicy.setLimit(countlimit);
condition = new ArrayList<Condition>();
HTTPVerbCondition verbCond = new HTTPVerbCondition();
verbCond.setHttpVerb("POST");
condition.add(verbCond);
p.setQuotaPolicy(quotaPolicy);
p.setConditions(condition);
pipelines.add(p);
// /////////pipeline item end//////
policy.setPipelines(pipelines);
return policy;
}
Aggregations