Search in sources :

Example 11 with AdvancedThrottlePolicyDTO

use of org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO 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)

Aggregations

APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)9 AdvancedThrottlePolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyDTO)8 Test (org.testng.annotations.Test)3 RequestCountLimit (org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)2 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)2 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)2 QuotaPolicy (org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy)2 PoliciesApiServiceImpl (org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl)2 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)2 ArrayList (java.util.ArrayList)1 Pipeline (org.wso2.carbon.apimgt.core.models.policy.Pipeline)1 AdvancedThrottlePolicyListDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.AdvancedThrottlePolicyListDTO)1 ConditionalGroupDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ConditionalGroupDTO)1 RequestCountLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.RequestCountLimitDTO)1 ThrottleLimitDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThrottleLimitDTO)1