use of org.wso2.carbon.apimgt.rest.api.admin.impl.PoliciesApiServiceImpl in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingCustomPostTest.
@Test
public void policiesThrottlingCustomPostTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
CustomRuleDTO dto = new CustomRuleDTO();
String uuid = UUID.randomUUID().toString();
dto.setId(uuid);
CustomPolicy policy = CustomPolicyMappingUtil.fromCustomPolicyDTOToModel(dto);
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.mockStatic(CustomPolicyMappingUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
Mockito.doReturn(uuid).doThrow(new IllegalArgumentException()).when(adminService).addCustomRule(policy);
Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getCustomRuleByUUID(uuid);
PowerMockito.when(CustomPolicyMappingUtil.fromCustomPolicyToDTO(policy)).thenReturn(dto);
Response response = policiesApiService.policiesThrottlingCustomPost(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 policiesThrottlingAdvancedPolicyIdPutTest.
@Test
public void policiesThrottlingAdvancedPolicyIdPutTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
String uuid = UUID.randomUUID().toString();
AdvancedThrottlePolicyDTO dto = new AdvancedThrottlePolicyDTO();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
APIPolicy policy1 = new APIPolicy(uuid, "samplePolicy1");
Mockito.doReturn(policy1).doThrow(new IllegalArgumentException()).when(adminService).getApiPolicyByUuid(uuid);
Response response = policiesApiService.policiesThrottlingAdvancedIdPut(uuid, dto, null, null, 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 policiesThrottlingAdvancedPostTest.
@Test
public void policiesThrottlingAdvancedPostTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
AdvancedThrottlePolicyDTO dto = new AdvancedThrottlePolicyDTO();
String uuid = UUID.randomUUID().toString();
dto.setId(uuid);
dto.setDisplayName("Sample Policy Display Name");
dto.setDescription("Simple Description");
dto.setPolicyName("Simple Policy Name");
dto.setIsDeployed(true);
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.mockStatic(AdvancedThrottlePolicyMappingUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
APIPolicy policy1 = AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyDTOToPolicy(dto);
Mockito.doReturn(uuid).doThrow(new IllegalArgumentException()).when(adminService).addApiPolicy(policy1);
Mockito.doReturn(policy1).doThrow(new IllegalArgumentException()).when(adminService).getApiPolicyByUuid(uuid);
PowerMockito.when(AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyDTOToPolicy(dto)).thenReturn(policy1);
PowerMockito.when(AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyToDTO(policy1)).thenReturn(dto);
Response response = policiesApiService.policiesThrottlingAdvancedPost(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 PoliciesApiServiceImplTestCase method testPoliciesTierLevelGet.
@Test
public void testPoliciesTierLevelGet() 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();
List<Policy> tierList = new ArrayList<>();
Mockito.when(apiStore.getPolicies(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum(tierLevel))).thenReturn(tierList);
Response response = policiesApiService.policiesTierLevelGet(tierLevel, 10, 0, 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 policiesThrottlingAdvancedGetTest.
@Test
public void policiesThrottlingAdvancedGetTest() throws APIManagementException, NotFoundException {
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
APIPolicy policy1 = new APIPolicy("samplePolicy1");
APIPolicy policy2 = new APIPolicy("samplePolicy2");
List<APIPolicy> policies = new ArrayList<>();
policies.add(policy1);
policies.add(policy2);
Mockito.doReturn(policies).doThrow(new IllegalArgumentException()).when(adminService).getApiPolicies();
Response response = policiesApiService.policiesThrottlingAdvancedGet(null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
Aggregations