use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy 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.throttle.policy.deployer.dto.QuotaPolicy 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.throttle.policy.deployer.dto.QuotaPolicy 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");
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy in project carbon-apimgt by wso2.
the class AdvancedThrottlePolicyMappingUtilTestCase method fromAdvancedPolicyToInfoDTOTest.
@Test(description = "Convert Policy DTO to Policy object")
public void fromAdvancedPolicyToInfoDTOTest() 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 policyDTO = AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyToInfoDTO(apiPolicy);
Assert.assertNotNull(policyDTO);
Assert.assertEquals(policyDTO.getDisplayName(), displayName);
Assert.assertEquals(policyDTO.getDescription(), description);
Assert.assertEquals(policyDTO.getDefaultLimit().getType(), "RequestCountLimit");
Assert.assertEquals(policyDTO.getDefaultLimit().getTimeUnit(), apiPolicy.getDefaultQuotaPolicy().getLimit().getTimeUnit());
Assert.assertEquals(policyDTO.getDefaultLimit().getUnitTime(), (Integer) apiPolicy.getDefaultQuotaPolicy().getLimit().getUnitTime());
Assert.assertEquals(policyDTO.getDefaultLimit().getRequestCountLimit().getRequestCount(), (Integer) ((RequestCountLimit) apiPolicy.getDefaultQuotaPolicy().getLimit()).getRequestCount());
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtilTest method fromApplicationThrottlePolicyToDTOTest.
@Test(description = "Convert from Policy to DTO")
public void fromApplicationThrottlePolicyToDTOTest() throws Exception {
Policy policy = new ApplicationPolicy(uuid, policyName);
QuotaPolicy quotaPolicy = new QuotaPolicy();
RequestCountLimit requestCountLimit = new RequestCountLimit("s", 1000, 10000);
quotaPolicy.setLimit(requestCountLimit);
quotaPolicy.setType(REQUEST_COUNT_TYPE);
policy.setDefaultQuotaPolicy(quotaPolicy);
policy.setDisplayName(displayName);
ApplicationThrottlePolicyDTO dto = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(policy);
Assert.assertNotNull(dto);
Assert.assertEquals(dto.getDisplayName(), displayName);
Assert.assertNotNull(dto.getPolicyName(), policyName);
Assert.assertEquals(dto.getId(), uuid);
Assert.assertEquals(dto.getDefaultLimit().getRequestCountLimit().getRequestCount().intValue(), requestCountLimit.getRequestCount());
Assert.assertEquals(dto.getDisplayName(), displayName);
}
Aggregations