use of org.wso2.carbon.apimgt.core.models.policy.CustomPolicy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingCustomRuleIdPutTest.
@Test
public void policiesThrottlingCustomRuleIdPutTest() 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.doNothing().doThrow(new IllegalArgumentException()).when(adminService).updateCustomRule(policy);
Mockito.doReturn(policy).doThrow(new IllegalArgumentException()).when(adminService).getCustomRuleByUUID(uuid);
CustomRuleDTO dto = CustomPolicyMappingUtil.fromCustomPolicyToDTO(policy);
Response response = policiesApiService.policiesThrottlingCustomRuleIdPut(uuid, dto, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.core.models.policy.CustomPolicy in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTest method policiesThrottlingCustomGetTest.
@Test
public void policiesThrottlingCustomGetTest() throws APIManagementException, NotFoundException {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
CustomPolicy policy1 = new CustomPolicy(UUID.randomUUID().toString(), "SamplePolicy1");
CustomPolicy policy2 = new CustomPolicy(UUID.randomUUID().toString(), "SamplePolicy2");
List<CustomPolicy> policies = new ArrayList<>();
policies.add(policy1);
policies.add(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).getCustomRules();
Response response = policiesApiService.policiesThrottlingCustomGet(null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.core.models.policy.CustomPolicy 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.core.models.policy.CustomPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetCustomRules.
@Test(description = "Test getting custom rules")
public void testGetCustomRules() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
List<CustomPolicy> customPolicyListExpected = new ArrayList<>();
CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
customPolicyListExpected.add(customPolicy);
Mockito.when(policyDAO.getCustomPolicies()).thenReturn(customPolicyListExpected);
List<CustomPolicy> customPolicyListReturned = adminService.getCustomRules();
Assert.assertEquals(customPolicyListReturned, customPolicyListExpected);
// Error path
Mockito.when(policyDAO.getCustomPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getCustomRules();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't get list of custom policy.");
}
}
use of org.wso2.carbon.apimgt.core.models.policy.CustomPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateCustomRule.
@Test(description = "Test updating a custom rule")
public void testUpdateCustomRule() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
adminService.updateCustomRule(customPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateCustomPolicy(customPolicy);
try {
adminService.updateCustomRule(customPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update custom policy with UUID: " + customPolicy.getUuid());
}
}
Aggregations