use of org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit 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;
}
use of org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createAPIPolicyWithRequestLimit.
public static APIPolicy createAPIPolicyWithRequestLimit(String name) {
APIPolicy apiPolicy = new APIPolicy(name);
apiPolicy.setDescription("testDescription");
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("requestCount");
RequestCountLimit requestCountLimit = new RequestCountLimit("s", 60, 10);
quotaPolicy.setLimit(requestCountLimit);
apiPolicy.setDefaultQuotaPolicy(quotaPolicy);
apiPolicy.setDisplayName("displayName");
return apiPolicy;
}
use of org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createSubscriptionPolicyWithRequestLimit.
public static SubscriptionPolicy createSubscriptionPolicyWithRequestLimit(String name) {
SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy(name);
subscriptionPolicy.setDescription("testDescription");
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType("requestCount");
RequestCountLimit requestCountLimit = new RequestCountLimit("s", 60, 10);
quotaPolicy.setLimit(requestCountLimit);
subscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
return subscriptionPolicy;
}
use of org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultApplicationPolicy.
/**
* Create default application policy.
*
* @return
*/
protected static ApplicationPolicy createDefaultApplicationPolicy() {
ApplicationPolicy applicationPolicy = new ApplicationPolicy(SAMPLE_APP_POLICY);
applicationPolicy.setUuid(UUID.randomUUID().toString());
applicationPolicy.setDisplayName(SAMPLE_APP_POLICY);
applicationPolicy.setDescription(SAMPLE_APP_POLICY_DESCRIPTION);
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setType(REQUEST_COUNT_TYPE);
RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 10000, 1000);
defaultQuotaPolicy.setLimit(requestCountLimit);
applicationPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
return applicationPolicy;
}
use of org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtilTest method fromSubscriptionThrottlePolicyToDTOTest.
@Test(description = "Convert Subscription Throttle Policy to DTO")
public void fromSubscriptionThrottlePolicyToDTOTest() throws Exception {
SubscriptionPolicy policy = new SubscriptionPolicy(uuid, name);
QuotaPolicy quotaPolicy = new QuotaPolicy();
RequestCountLimit requestCountLimit = new RequestCountLimit("s", 1000, 10000);
quotaPolicy.setLimit(requestCountLimit);
quotaPolicy.setType(REQUEST_COUNT_TYPE);
policy.setDefaultQuotaPolicy(quotaPolicy);
policy.setCustomAttributes("[{\"name\":\"dwd\",\"value\":\"wdw\"},{\"name\":\"dwdw\",\"value\":\"dwdw\"}]".getBytes());
SubscriptionThrottlePolicyDTO dto = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionThrottlePolicyToDTO(policy);
Assert.assertNotNull(dto);
Assert.assertEquals(dto.getPolicyName(), name);
Assert.assertEquals(dto.getId(), uuid);
Assert.assertEquals(dto.getDefaultLimit().getRequestCountLimit().getRequestCount().intValue(), requestCountLimit.getRequestCount());
Assert.assertEquals(dto.getCustomAttributes().get(0).getName(), "dwd");
Assert.assertEquals(dto.getCustomAttributes().get(1).getName(), "dwdw");
}
Aggregations