use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeletePolicy.
@Test(description = "Test delete policy")
public void testDeletePolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName())).thenReturn(apiPolicy);
adminService.deletePolicy(apiPolicy.getPolicyName(), APIMgtAdminService.PolicyLevel.api);
Mockito.verify(policyDAO, Mockito.times(1)).getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName());
Mockito.verify(policyDAO, Mockito.times(1)).deletePolicy(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName());
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).deletePolicy(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName());
try {
adminService.deletePolicy(apiPolicy.getPolicyName(), APIMgtAdminService.PolicyLevel.api);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't delete policy with name: " + apiPolicy.getPolicyName() + ", level: " + APIMgtAdminService.PolicyLevel.api);
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddSubscriptionPolicy.
@Test(description = "Test add subscription policy")
public void testAddSubscriptionPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
adminService.addSubscriptionPolicy(policy);
Mockito.verify(policyDAO, Mockito.times(1)).addSubscriptionPolicy(policy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addSubscriptionPolicy(policy);
try {
adminService.addSubscriptionPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add Subscription policy for uuid: " + policy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetSubscriptionPolicies.
@Test(description = "Test getting all Subscription Policies")
public void testGetSubscriptionPolicies() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
adminService.getSubscriptionPolicies();
Mockito.verify(policyDAO, Mockito.times(1)).getSubscriptionPolicies();
// Error path
Mockito.when(policyDAO.getSubscriptionPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getSubscriptionPolicies();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Subscription policies");
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApplicationPolicy.
@Test(description = "Test getting Application policy")
public void testGetApplicationPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
Mockito.when(policyDAO.getApplicationPolicy(applicationPolicy.getPolicyName())).thenReturn(applicationPolicy);
adminService.getApplicationPolicy(applicationPolicy.getPolicyName());
Mockito.verify(policyDAO, Mockito.times(1)).getApplicationPolicy(applicationPolicy.getPolicyName());
// Error path
Mockito.when(policyDAO.getApplicationPolicy(applicationPolicy.getPolicyName())).thenThrow(APIMgtDAOException.class);
try {
adminService.getApplicationPolicy(applicationPolicy.getPolicyName());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Application policy with name: " + applicationPolicy.getPolicyName());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApiPolicy.
@Test(description = "Test getting API policy")
public void testGetApiPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
Mockito.when(policyDAO.getApiPolicy(apiPolicy.getPolicyName())).thenReturn(apiPolicy);
adminService.getApiPolicy(apiPolicy.getPolicyName());
Mockito.verify(policyDAO, Mockito.times(1)).getApiPolicy(apiPolicy.getPolicyName());
// Error path
Mockito.when(policyDAO.getApiPolicy(apiPolicy.getPolicyName())).thenThrow(APIMgtDAOException.class);
try {
adminService.getApiPolicy(apiPolicy.getPolicyName());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve API policy with name: " + apiPolicy.getPolicyName());
}
}
Aggregations