use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class CommonThrottleMappingUtilTestCase method fromBandwidthThrottleLimitDtoToQuotaPolicyTest.
@Test(description = "Convert Bandwidth Throttle Limit DTO to Quota Policy")
public void fromBandwidthThrottleLimitDtoToQuotaPolicyTest() throws Exception {
ThrottleLimitDTO throttleLimitDTO = new ThrottleLimitDTO();
throttleLimitDTO.setType(PolicyConstants.BANDWIDTH_LIMIT_TYPE);
BandwidthLimitDTO bandwidthLimitDTO = new BandwidthLimitDTO();
bandwidthLimitDTO.setDataAmount(10);
bandwidthLimitDTO.setDataUnit(KB);
throttleLimitDTO.setBandwidthLimit(bandwidthLimitDTO);
throttleLimitDTO.setTimeUnit("min");
throttleLimitDTO.setUnitTime(1);
QuotaPolicy policy = CommonThrottleMappingUtil.fromDTOToQuotaPolicy(throttleLimitDTO);
Assert.assertNotNull(policy);
assertEquals(policy.getType(), PolicyConstants.BANDWIDTH_TYPE);
BandwidthLimit bandwidthLimit = (BandwidthLimit) policy.getLimit();
assertEquals(bandwidthLimit.getDataAmount(), 10);
assertEquals(bandwidthLimit.getDataUnit(), KB);
assertEquals(bandwidthLimit.getTimeUnit(), "min");
assertEquals(bandwidthLimit.getUnitTime(), 1);
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class CustomPolicyMappingUtilTest method fromCustomPolicyArrayToListDTOTest.
@Test(description = "Convert List<CustomPolicy> to CustomRuleListDTO")
public void fromCustomPolicyArrayToListDTOTest() throws Exception {
CustomPolicy customPolicy1 = new CustomPolicy("namw1");
customPolicy1.setDescription("custom policy desc1");
customPolicy1.setKeyTemplate("keytemplate1");
customPolicy1.setSiddhiQuery("sample query1");
CustomPolicy customPolicy2 = new CustomPolicy("namw2");
customPolicy2.setDescription("custom policy desc2");
customPolicy2.setKeyTemplate("keytemplate2");
customPolicy2.setSiddhiQuery("sample query2");
List<CustomPolicy> customPolicyList = new ArrayList<>();
customPolicyList.add(customPolicy1);
customPolicyList.add(customPolicy2);
CustomRuleListDTO listDTO = CustomPolicyMappingUtil.fromCustomPolicyArrayToListDTO(customPolicyList);
Assert.assertEquals((Integer) customPolicyList.size(), listDTO.getCount());
Assert.assertEquals(customPolicy1.getPolicyName(), listDTO.getList().get(0).getPolicyName());
Assert.assertEquals(customPolicy1.getDisplayName(), listDTO.getList().get(0).getDisplayName());
Assert.assertEquals(customPolicy1.getKeyTemplate(), listDTO.getList().get(0).getKeyTemplate());
Assert.assertEquals(customPolicy1.getSiddhiQuery(), listDTO.getList().get(0).getSiddhiQuery());
Assert.assertEquals(customPolicy1.getDescription(), listDTO.getList().get(0).getDescription());
Assert.assertEquals(customPolicy2.getPolicyName(), listDTO.getList().get(1).getPolicyName());
Assert.assertEquals(customPolicy2.getDisplayName(), listDTO.getList().get(1).getDisplayName());
Assert.assertEquals(customPolicy2.getKeyTemplate(), listDTO.getList().get(1).getKeyTemplate());
Assert.assertEquals(customPolicy2.getSiddhiQuery(), listDTO.getList().get(1).getSiddhiQuery());
Assert.assertEquals(customPolicy2.getDescription(), listDTO.getList().get(1).getDescription());
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class CustomPolicyMappingUtilTest method fromCustomPolicyToDTOTest.
@Test(description = "Convert custom Policy to DTO object")
public void fromCustomPolicyToDTOTest() throws Exception {
CustomPolicy policy = new CustomPolicy(name);
policy.setUuid(uuid);
CustomRuleDTO dto = CustomPolicyMappingUtil.fromCustomPolicyToDTO(policy);
Assert.assertNotNull(dto);
Assert.assertEquals(dto.getPolicyName(), name);
Assert.assertEquals(dto.getId(), uuid);
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class SubscriptionThrottlePolicyMappingUtilTest method fromSubscriptionPolicyArrayToListDTOTest.
@Test(description = "Convert Subscription Throttle Policy List to List DTO")
public void fromSubscriptionPolicyArrayToListDTOTest() throws Exception {
List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
SubscriptionPolicy policy1 = SampleTestObjectCreator.createSubscriptionPolicyWithRequestLimit("Gold1");
SubscriptionPolicy policy2 = SampleTestObjectCreator.createSubscriptionPolicyWithRequestLimit("Gold2");
subscriptionPolicies.add(policy1);
subscriptionPolicies.add(policy2);
SubscriptionThrottlePolicyListDTO listDTO = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionPolicyArrayToListDTO(subscriptionPolicies);
assertEquals(listDTO.getCount(), (Integer) subscriptionPolicies.size());
assertEquals(listDTO.getList().get(0).getPolicyName(), policy1.getPolicyName());
assertEquals(listDTO.getList().get(0).getDescription(), policy1.getDescription());
assertEquals(listDTO.getList().get(0).getDefaultLimit().getUnitTime(), (Integer) policy1.getDefaultQuotaPolicy().getLimit().getUnitTime());
assertEquals(listDTO.getList().get(0).getDefaultLimit().getRequestCountLimit().getRequestCount(), (Integer) ((RequestCountLimit) policy1.getDefaultQuotaPolicy().getLimit()).getRequestCount());
assertEquals(listDTO.getList().get(1).getPolicyName(), policy2.getPolicyName());
assertEquals(listDTO.getList().get(1).getDescription(), policy2.getDescription());
assertEquals(listDTO.getList().get(1).getDefaultLimit().getUnitTime(), (Integer) policy2.getDefaultQuotaPolicy().getLimit().getUnitTime());
assertEquals(listDTO.getList().get(1).getDefaultLimit().getRequestCountLimit().getRequestCount(), (Integer) ((RequestCountLimit) policy2.getDefaultQuotaPolicy().getLimit()).getRequestCount());
}
use of org.wso2.carbon.apimgt.api.model.policy.Policy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingCustomRuleIdGetTest.
@Test
public void policiesThrottlingCustomRuleIdGetTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
String uuid = UUID.randomUUID().toString();
CustomPolicy policy = new CustomPolicy(uuid, "Policy");
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getCustomRuleByUUID(uuid);
Response response = policiesApiService.policiesThrottlingCustomRuleIdGet(uuid, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
Aggregations