use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl 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.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetThreatProtectionPolicyList.
@Test(description = "Test getting list of all threat protection policies")
public void testGetThreatProtectionPolicyList() throws APIManagementException {
ThreatProtectionDAO threatProtectionDAO = Mockito.mock(ThreatProtectionDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(threatProtectionDAO);
List<ThreatProtectionPolicy> policyList = new ArrayList<>();
policyList.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
policyList.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
Mockito.when(threatProtectionDAO.getPolicies()).thenReturn(policyList);
List<ThreatProtectionPolicy> policyListReturned = adminService.getThreatProtectionPolicyList();
Assert.assertEquals(policyListReturned.size(), policyList.size());
// Error path
Mockito.when(threatProtectionDAO.getPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getThreatProtectionPolicyList();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error while retrieving threat protection policy list");
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl 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.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeleteThreatProtectionPolicy.
@Test(description = "Test delete threat protection policy")
public void testDeleteThreatProtectionPolicy() throws APIManagementException {
ThreatProtectionDAO threatProtectionDAO = Mockito.mock(ThreatProtectionDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(threatProtectionDAO);
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(threatProtectionDAO).deletePolicy(policy.getUuid());
try {
adminService.deleteThreatProtectionPolicy(policy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error deleting threat protection policy");
}
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeletePolicyByUuid.
@Test(description = "Test delete policy by UUID")
public void testDeletePolicyByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
adminService.deletePolicyByUuid(apiPolicy.getUuid(), APIMgtAdminService.PolicyLevel.api);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).deletePolicyByUuid(APIMgtAdminService.PolicyLevel.api, apiPolicy.getUuid());
try {
adminService.deletePolicyByUuid(apiPolicy.getUuid(), APIMgtAdminService.PolicyLevel.api);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't delete policy with id: " + apiPolicy.getUuid() + ", level: " + APIMgtAdminService.PolicyLevel.api);
}
}
Aggregations