use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl 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.impl.APIMgtAdminServiceImpl 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.impl.APIMgtAdminServiceImpl 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);
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetAPISubscriptionsOfApi.
@Test(description = "Get api subscriptions of API")
public void testGetAPISubscriptionsOfApi() throws APIManagementException {
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(apiSubscriptionDAO);
Mockito.when(apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(API_CONTEXT, API_VERSION)).thenReturn(new ArrayList<SubscriptionValidationData>());
adminService.getAPISubscriptionsOfApi(API_CONTEXT, API_VERSION);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).getAPISubscriptionsOfAPIForValidation(API_CONTEXT, API_VERSION);
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl 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());
}
}
Aggregations