use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingApplicationPostTest.
@Test
public void policiesThrottlingApplicationPostTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
ApplicationThrottlePolicyDTO dto = new ApplicationThrottlePolicyDTO();
String uuid = UUID.randomUUID().toString();
dto.setId(uuid);
dto.setPolicyName("SamplePolicy");
dto.setDisplayName("DisplayName");
dto.setDescription("Policy Description");
dto.setIsDeployed(true);
ApplicationPolicy policy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(dto);
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.mockStatic(ApplicationThrottlePolicyMappingUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
Mockito.doReturn(uuid).doThrow(new IllegalArgumentException()).when(adminService).addApplicationPolicy(policy);
Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getApplicationPolicyByUuid(uuid);
PowerMockito.when(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(policy)).thenReturn(dto);
PowerMockito.when(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(dto)).thenReturn(policy);
Response response = policiesApiService.policiesThrottlingApplicationPost(dto, getRequest());
Assert.assertEquals(201, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingSubscriptionGetTest.
@Test
public void policiesThrottlingSubscriptionGetTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
List<SubscriptionPolicy> policies = new ArrayList<>();
policies.add(new SubscriptionPolicy("Policy1"));
policies.add(new SubscriptionPolicy("Policy2"));
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
Mockito.doReturn(policies).doThrow(new IllegalArgumentException()).when(adminService).getSubscriptionPolicies();
Response response = policiesApiService.policiesThrottlingSubscriptionGet(null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTestCase method policiesGetTest.
@Test
public void policiesGetTest() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
PolicyValidationData policyValidationDataOne = new PolicyValidationData(UUID.randomUUID().toString(), "APPLICATION_POLICY", true);
PolicyValidationData policyValidationDataTwo = new PolicyValidationData(UUID.randomUUID().toString(), "APPLICATION_POLICY", true);
PolicyValidationData policyValidationDataThree = new PolicyValidationData(UUID.randomUUID().toString(), "APPLICATION_POLICY", true);
Set<PolicyValidationData> policyValidationDataHashSet = new LinkedHashSet<>();
policyValidationDataHashSet.add(policyValidationDataOne);
policyValidationDataHashSet.add(policyValidationDataTwo);
policyValidationDataHashSet.add(policyValidationDataThree);
Mockito.when(apiMgtAdminService.getAllPolicies()).thenReturn(policyValidationDataHashSet);
Response response = policiesApiService.policiesGet(null, getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertEquals(((PolicyListDTO) response.getEntity()).getList().size(), 3);
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelTierNameGet.
@Test
public void testPoliciesTierLevelTierNameGet() throws APIManagementException, NotFoundException {
TestUtil.printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Request request = TestUtil.getRequest();
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
String tierLevel = APIMgtAdminService.PolicyLevel.api.name();
String tierName = "GOLD";
Policy policy = SampleTestObjectCreator.createSubscriptionPolicyWithRequestLimit("test");
Mockito.when(apiStore.getPolicy(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum(tierLevel), tierName)).thenReturn(policy);
Response response = policiesApiService.policiesTierLevelTierNameGet(tierName, tierLevel, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingSubscriptionPostTest.
@Test
public void policiesThrottlingSubscriptionPostTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
String uuid = UUID.randomUUID().toString();
SubscriptionThrottlePolicyDTO dto = new SubscriptionThrottlePolicyDTO();
dto.setRateLimitTimeUnit("m");
dto.setRateLimitCount(1);
dto.setStopOnQuotaReach(true);
SubscriptionPolicy policy = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionThrottlePolicyDTOToModel(dto);
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.mockStatic(SubscriptionThrottlePolicyMappingUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
Mockito.doReturn(uuid).doThrow(new IllegalArgumentException()).when(adminService).addSubscriptionPolicy(policy);
Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getSubscriptionPolicyByUuid(uuid);
PowerMockito.when(SubscriptionThrottlePolicyMappingUtil.fromSubscriptionThrottlePolicyDTOToModel(dto)).thenReturn(policy);
PowerMockito.when(SubscriptionThrottlePolicyMappingUtil.fromSubscriptionThrottlePolicyToDTO(policy)).thenReturn(dto);
Response response = policiesApiService.policiesThrottlingSubscriptionPost(dto, getRequest());
Assert.assertEquals(201, response.getStatus());
}
Aggregations