use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddCustomRule.
@Test(description = "Test adding a custom rule")
public void testAddCustomRule() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
Mockito.when(policyDAO.addCustomPolicy(customPolicy)).thenReturn(customPolicy.getUuid());
String uuid = adminService.addCustomRule(customPolicy);
Assert.assertEquals(uuid, customPolicy.getUuid());
// Error path
Mockito.when(policyDAO.addCustomPolicy(customPolicy)).thenThrow(APIMgtDAOException.class);
try {
adminService.addCustomRule(customPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add custom policy with policy name: " + customPolicy.getPolicyName());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApplicationPolicyByUuid.
@Test(description = "Test getting Application policy by UUID")
public void testGetApplicationPolicyByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
Mockito.when(policyDAO.getApplicationPolicyByUuid(applicationPolicy.getUuid())).thenReturn(applicationPolicy);
adminService.getApplicationPolicyByUuid(applicationPolicy.getUuid());
Mockito.verify(policyDAO, Mockito.times(1)).getApplicationPolicyByUuid(applicationPolicy.getUuid());
// Error path
Mockito.when(policyDAO.getApplicationPolicyByUuid(applicationPolicy.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getApplicationPolicyByUuid(applicationPolicy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Application policy with id: " + applicationPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetBlockConditions.
@Test(description = "Test getting block conditions")
public void testGetBlockConditions() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
List<BlockConditions> blockConditionsListExpected = new ArrayList<>();
BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
blockConditionsListExpected.add(blockConditions);
Mockito.when(policyDAO.getBlockConditions()).thenReturn(blockConditionsListExpected);
List<BlockConditions> blockConditionsListReturned = adminService.getBlockConditions();
Assert.assertEquals(blockConditionsListReturned, blockConditionsListExpected);
// Error path
Mockito.when(policyDAO.getBlockConditions()).thenThrow(APIMgtDAOException.class);
try {
adminService.getBlockConditions();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't get list of block conditions.");
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddSubscriptionPolicyWhenPolicyIdNull.
@Test(description = "Test add subscription policy when the policy ID is null")
public void testAddSubscriptionPolicyWhenPolicyIdNull() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
policy.setUuid(null);
adminService.addSubscriptionPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addSubscriptionPolicy(policy);
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetAllPoliciesByLevel.
@Test(description = "Get all policies by level")
public void testGetAllPoliciesByLevel() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
Policy policy = Mockito.mock(Policy.class);
List<Policy> policyList = new ArrayList<>();
policyList.add(policy);
Mockito.when(policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application)).thenReturn(policyList);
adminService.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application);
Mockito.verify(policyDAO, Mockito.times(1)).getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application);
// Error path
Mockito.when(policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application)).thenThrow(APIMgtDAOException.class);
try {
adminService.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Throttle Policies with level: " + APIMgtAdminService.PolicyLevel.application.name());
}
}
Aggregations