Search in sources :

Example 41 with QuotaPolicy

use of org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method updateAPIPolicy.

/**
 * Updated the given API policy
 *
 * @param apiPolicy {@link APIPolicy} instance to be updated
 * @return updated {@link APIPolicy} instance
 */
public static APIPolicy updateAPIPolicy(APIPolicy apiPolicy) {
    apiPolicy.setDisplayName(UPDATED_SAMPLE_API_POLICY);
    apiPolicy.setDescription(UPDATED_SAMPLE_API_POLICY_DESCRIPTION);
    QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
    defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
    BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 1, 1000, "KB");
    defaultQuotaPolicy.setLimit(bandwidthLimit);
    apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
    apiPolicy.setPipelines(createDefaultPipelines());
    apiPolicy.getPipelines().add(createNewIPRangePipeline());
    return apiPolicy;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 42 with QuotaPolicy

use of org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createDefaultPolicy.

public static void createDefaultPolicy(PolicyDAO policyDAO) throws APIMgtDAOException {
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType(REQUEST_COUNT_TYPE);
    quotaPolicy.setLimit(new RequestCountLimit(SECONDS_TIMUNIT, 60, 1));
    unlimitedApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(unlimitedApiPolicy);
    goldApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(goldApiPolicy);
    silverApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(silverApiPolicy);
    bronzeApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApiPolicy(bronzeApiPolicy);
    unlimitedSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(unlimitedSubscriptionPolicy);
    goldSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(goldSubscriptionPolicy);
    silverSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(silverSubscriptionPolicy);
    bronzeSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addSubscriptionPolicy(bronzeSubscriptionPolicy);
    fiftyPerMinApplicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApplicationPolicy(fiftyPerMinApplicationPolicy);
    twentyPerMinApplicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
    policyDAO.addApplicationPolicy(twentyPerMinApplicationPolicy);
}
Also used : RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)

Example 43 with QuotaPolicy

use of org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy in project carbon-apimgt by wso2.

the class CommonThrottleMappingUtil method fromDTOToQuotaPolicy.

/**
 * Converts a Throttle Limit DTO object into a Quota Policy object
 *
 * @param dto Throttle limit DTO object
 * @return Derived Quota policy object from DTO
 * @throws UnsupportedThrottleLimitTypeException - If error occurs
 */
public static QuotaPolicy fromDTOToQuotaPolicy(ThrottleLimitDTO dto) throws UnsupportedThrottleLimitTypeException {
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setLimit(fromDTOToLimit(dto));
    quotaPolicy.setType(mapQuotaPolicyTypeFromDTOToModel(dto.getType()));
    return quotaPolicy;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)

Example 44 with QuotaPolicy

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

Example 45 with QuotaPolicy

use of org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createAPIPolicyWithBndwidthLimit.

public static APIPolicy createAPIPolicyWithBndwidthLimit(String name) {
    APIPolicy apiPolicy = new APIPolicy(name);
    apiPolicy.setDescription("testDescription");
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType("bandwidth");
    BandwidthLimit bandwidthLimit = new BandwidthLimit("s", 60, 10, "mb");
    quotaPolicy.setLimit(bandwidthLimit);
    apiPolicy.setDefaultQuotaPolicy(quotaPolicy);
    apiPolicy.setDisplayName("displayName");
    return apiPolicy;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

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