Search in sources :

Example 31 with RequestCountLimit

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.RequestCountLimit in project carbon-apimgt by wso2.

the class APIUtilTierTest method generateAppPolicies.

private ApplicationPolicy[] generateAppPolicies(String[] policyNames) {
    List<ApplicationPolicy> policyList = new ArrayList<ApplicationPolicy>();
    for (String policyName : policyNames) {
        ApplicationPolicy policy = new ApplicationPolicy(policyName);
        QuotaPolicy quotaPolicy = new QuotaPolicy();
        RequestCountLimit countLimit = new RequestCountLimit();
        countLimit.setRequestCount(123);
        quotaPolicy.setLimit(countLimit);
        policy.setDefaultQuotaPolicy(quotaPolicy);
        policy.setDescription(policyName);
        policyList.add(policy);
    }
    ApplicationPolicy[] array = {};
    return policyList.toArray(array);
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) ArrayList(java.util.ArrayList) QuotaPolicy(org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy) Matchers.anyString(org.mockito.Matchers.anyString)

Example 32 with RequestCountLimit

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.RequestCountLimit in project carbon-apimgt by wso2.

the class SubscriptionValidationDataUtil method getThrottleLimitDTO.

/**
 * Converts a quota policy object of a policy into a Throttle Limit DTO object.
 *
 * @param policy policy model object
 * @return Throttle Limit DTO
 */
private static ThrottleLimitDTO getThrottleLimitDTO(Policy policy) {
    QuotaPolicy quotaPolicy = policy.getQuotaPolicy();
    ThrottleLimitDTO defaultLimit = new ThrottleLimitDTO();
    defaultLimit.setQuotaType(quotaPolicy.getType());
    if (PolicyConstants.REQUEST_COUNT_TYPE.equals(quotaPolicy.getType())) {
        RequestCountLimit requestCountLimit = (RequestCountLimit) quotaPolicy.getLimit();
        defaultLimit.setRequestCount(fromRequestCountLimitToDTO(requestCountLimit));
    } else if (PolicyConstants.BANDWIDTH_TYPE.equals(quotaPolicy.getType())) {
        BandwidthLimit bandwidthLimit = (BandwidthLimit) quotaPolicy.getLimit();
        defaultLimit.setBandwidth(fromBandwidthLimitToDTO(bandwidthLimit));
    } else if (PolicyConstants.EVENT_COUNT_TYPE.equals(quotaPolicy.getType())) {
        EventCountLimit eventCountLimit = (EventCountLimit) quotaPolicy.getLimit();
        defaultLimit.setEventCount(fromEventCountLimitToDTO(eventCountLimit));
    }
    return defaultLimit;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit) EventCountLimit(org.wso2.carbon.apimgt.api.model.policy.EventCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy) ThrottleLimitDTO(org.wso2.carbon.apimgt.internal.service.dto.ThrottleLimitDTO) BandwidthLimit(org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)

Example 33 with RequestCountLimit

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.RequestCountLimit in project carbon-apimgt by wso2.

the class SubscriptionValidationDataUtil 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
 */
private static RequestCountLimitDTO fromRequestCountLimitToDTO(RequestCountLimit requestCountLimit) {
    RequestCountLimitDTO dto = new RequestCountLimitDTO();
    dto.setTimeUnit(requestCountLimit.getTimeUnit());
    dto.setUnitTime(requestCountLimit.getUnitTime());
    dto.setRequestCount(requestCountLimit.getRequestCount());
    return dto;
}
Also used : RequestCountLimitDTO(org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO)

Example 34 with RequestCountLimit

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.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 RequestCountLimitDTO fromRequestCountLimitToDTO(RequestCountLimit requestCountLimit) {
    // done
    RequestCountLimitDTO dto = new RequestCountLimitDTO();
    dto.setTimeUnit(requestCountLimit.getTimeUnit());
    dto.setUnitTime(requestCountLimit.getUnitTime());
    dto.setRequestCount(requestCountLimit.getRequestCount());
    return dto;
}
Also used : RequestCountLimitDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RequestCountLimitDTO)

Example 35 with RequestCountLimit

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.RequestCountLimit in project carbon-apimgt by wso2.

the class TestUtil method getPolicySubLevel.

/**
 * Generate a dummy Subscription Policy object
 *
 * @return an Subscription Policy
 */
public static SubscriptionPolicy getPolicySubLevel() {
    SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy();
    subscriptionPolicy.setId(1);
    subscriptionPolicy.setTenantId(-1234);
    subscriptionPolicy.setTenantDomain("carbon.super");
    subscriptionPolicy.setName("policy1");
    subscriptionPolicy.setQuotaType("requestCount");
    QuotaPolicy defaultLimit = new QuotaPolicy();
    defaultLimit.setQuotaType("requestCount");
    RequestCountLimit requestCountLimit = new RequestCountLimit();
    requestCountLimit.setRequestCount(1);
    requestCountLimit.setTimeUnit("min");
    requestCountLimit.setUnitTime(1);
    defaultLimit.setRequestCount(requestCountLimit);
    subscriptionPolicy.setDefaultLimit(defaultLimit);
    subscriptionPolicy.setGraphQLMaxComplexity(0);
    subscriptionPolicy.setGraphQLMaxDepth(0);
    subscriptionPolicy.setRateLimitCount(0);
    subscriptionPolicy.setRateLimitTimeUnit(null);
    subscriptionPolicy.setStopOnQuotaReach(true);
    subscriptionPolicy.setSubscriberCount(0);
    return subscriptionPolicy;
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.RequestCountLimit) SubscriptionPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicy) QuotaPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.QuotaPolicy)

Aggregations

RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)33 RequestCountLimit (org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit)30 QuotaPolicy (org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy)25 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)22 ArrayList (java.util.ArrayList)16 BandwidthLimit (org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)16 Test (org.testng.annotations.Test)14 EventCountLimit (org.wso2.carbon.apimgt.api.model.policy.EventCountLimit)12 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)12 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)11 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)9 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)9 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)8 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)8 BandwidthLimit (org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)7 PreparedStatement (java.sql.PreparedStatement)6 Pipeline (org.wso2.carbon.apimgt.api.model.policy.Pipeline)6 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)5