Search in sources :

Example 46 with QuotaPolicy

use of org.wso2.carbon.apimgt.api.model.policy.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;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)

Example 47 with QuotaPolicy

use of org.wso2.carbon.apimgt.api.model.policy.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;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)

Example 48 with QuotaPolicy

use of org.wso2.carbon.apimgt.api.model.policy.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");
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) SubscriptionThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.SubscriptionThrottlePolicyDTO) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) Test(org.testng.annotations.Test)

Example 49 with QuotaPolicy

use of org.wso2.carbon.apimgt.api.model.policy.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());
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) AdvancedThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) Test(org.testng.annotations.Test)

Example 50 with QuotaPolicy

use of org.wso2.carbon.apimgt.api.model.policy.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);
}
Also used : Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) ApplicationThrottlePolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ApplicationThrottlePolicyDTO) Test(org.testng.annotations.Test)

Aggregations

QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)34 QuotaPolicy (org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy)27 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)24 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)23 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)16 ArrayList (java.util.ArrayList)13 BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)12 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)12 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)10 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)9 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)9 EventCountLimit (org.wso2.carbon.apimgt.api.model.policy.EventCountLimit)7 Test (org.testng.annotations.Test)6 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)6 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)6 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)6 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Pipeline (org.wso2.carbon.apimgt.api.model.policy.Pipeline)5