use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAPISubscriptionsByApplicationException.
@Test(description = "Exception when getting API subscriptions by application", expectedExceptions = APIManagementException.class)
public void testGetAPISubscriptionsByApplicationException() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setPolicy(new ApplicationPolicy(TIER));
application.setId(UUID);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsByApplication(application.getId())).thenThrow(new APIMgtDAOException("Error occurred while retrieving subscriptions for application - " + application.getName(), new SQLException()));
apiStore.getAPISubscriptionsByApplication(application);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingApplicationGetTest.
@Test
public void policiesThrottlingApplicationGetTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
ApplicationPolicy policy1 = new ApplicationPolicy("sampleAppPolicy1");
ApplicationPolicy policy2 = new ApplicationPolicy("sampleAppPolicy2");
List<ApplicationPolicy> policies = new ArrayList<>();
policies.add(policy1);
policies.add(policy2);
Mockito.doReturn(policies).doThrow(new IllegalArgumentException()).when(adminService).getApplicationPolicies();
Response response = policiesApiService.policiesThrottlingApplicationGet(null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingApplicationPolicyIdGetTest.
@Test
public void policiesThrottlingApplicationPolicyIdGetTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
String uuid = UUID.randomUUID().toString();
ApplicationPolicy policy = new ApplicationPolicy(uuid, "SampleApplicationPolicy");
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getApplicationPolicyByUuid(uuid);
Response response = policiesApiService.policiesThrottlingApplicationIdGet(uuid, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy 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);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.
the class ApplicationThrottlePolicyMappingUtilTest method fromApplicationThrottlePolicyDTOToModelTest.
@Test(description = "Convert from DTO to Policy")
public void fromApplicationThrottlePolicyDTOToModelTest() throws Exception {
ApplicationThrottlePolicyDTO dto = new ApplicationThrottlePolicyDTO();
dto.setDisplayName(displayName);
dto.setPolicyName(policyName);
dto.setId(uuid);
ThrottleLimitDTO throttleLimitDTO = new ThrottleLimitDTO();
throttleLimitDTO.setType("RequestCountLimit");
throttleLimitDTO.setTimeUnit("s");
throttleLimitDTO.setUnitTime(1);
RequestCountLimitDTO requestCountLimitDTO = new RequestCountLimitDTO();
requestCountLimitDTO.setRequestCount(2);
throttleLimitDTO.setRequestCountLimit(requestCountLimitDTO);
dto.setDefaultLimit(throttleLimitDTO);
ApplicationPolicy policy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(dto);
Assert.assertNotNull(policy);
Assert.assertEquals(policy.getDisplayName(), displayName);
Assert.assertEquals(policy.getPolicyName(), policyName);
Assert.assertEquals(policy.getDefaultQuotaPolicy().getType(), "requestCount");
Assert.assertEquals(policy.getDefaultQuotaPolicy().getLimit().getTimeUnit(), dto.getDefaultLimit().getTimeUnit());
Assert.assertEquals((Integer) policy.getDefaultQuotaPolicy().getLimit().getUnitTime(), dto.getDefaultLimit().getUnitTime());
Assert.assertEquals((Integer) ((RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit()).getRequestCount(), dto.getDefaultLimit().getRequestCountLimit().getRequestCount());
}
Aggregations