use of org.wso2.carbon.apimgt.core.dao.PolicyDAO 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());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddPolicy.
@Test(description = "Add policy")
public void testAddPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicy();
adminService.addApiPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addApiPolicy(policy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addApiPolicy(policy);
try {
adminService.addApiPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add API policy for uuid: " + policy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetSubscriptionPolicyByUuid.
@Test(description = "Test getting Subscription policy by UUID")
public void testGetSubscriptionPolicyByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
Mockito.when(policyDAO.getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid())).thenReturn(subscriptionPolicy);
adminService.getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid());
Mockito.verify(policyDAO, Mockito.times(1)).getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid());
// Error path
Mockito.when(policyDAO.getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getSubscriptionPolicyByUuid(subscriptionPolicy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Subscription policy with id: " + subscriptionPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddPolicyWhenPolicyIdNull.
@Test(description = "Add policy when policy id is null")
public void testAddPolicyWhenPolicyIdNull() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicy();
policy.setUuid(null);
adminService.addApiPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addApiPolicy(policy);
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddApplicationPolicyWhenPolicyIdNull.
@Test(description = "Test add application policy when the policy ID is null")
public void testAddApplicationPolicyWhenPolicyIdNull() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
policy.setUuid(null);
adminService.addApplicationPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addApplicationPolicy(policy);
}
Aggregations