use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetPolicy.
@Test(description = "Get policy by level and name")
public void testGetPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
Policy policy = Mockito.mock(Policy.class);
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME)).thenReturn(policy);
adminService.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
Mockito.verify(policyDAO, Mockito.times(1)).getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
// Error path
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME)).thenThrow(APIMgtDAOException.class);
try {
adminService.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Throttle Policy with level: " + APIMgtAdminService.PolicyLevel.application.name() + ", name: " + POLICY_NAME);
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testUpdateSubscriptionPolicy.
@Test(description = "Test update subscription policy")
public void testUpdateSubscriptionPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
adminService.updateSubscriptionPolicy(subscriptionPolicy);
Mockito.verify(policyDAO, Mockito.times(1)).updateSubscriptionPolicy(subscriptionPolicy);
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateSubscriptionPolicy(subscriptionPolicy);
try {
adminService.updateSubscriptionPolicy(subscriptionPolicy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't update Subscription policy for uuid: " + subscriptionPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddBlockCondition.
@Test(description = "Test adding block condition")
public void testAddBlockCondition() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
String uuid = adminService.addBlockCondition(blockConditions);
Assert.assertNotNull(uuid);
// Error path
Mockito.when(policyDAO.addBlockConditions(blockConditions)).thenThrow(APIMgtDAOException.class);
try {
adminService.addBlockCondition(blockConditions);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't add block condition with condition type: " + blockConditions.getConditionType() + ", condition value: " + blockConditions.getConditionValue());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApiPolicyByUuid.
@Test(description = "Test getting API policy by UUID")
public void testGetApiPolicyByUuid() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
Mockito.when(policyDAO.getApiPolicyByUuid(apiPolicy.getUuid())).thenReturn(apiPolicy);
adminService.getApiPolicyByUuid(apiPolicy.getUuid());
Mockito.verify(policyDAO, Mockito.times(1)).getApiPolicyByUuid(apiPolicy.getUuid());
// Error path
Mockito.when(policyDAO.getApiPolicyByUuid(apiPolicy.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getApiPolicyByUuid(apiPolicy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve API policy with id: " + apiPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApplicationPolicies.
@Test(description = "Test getting all Application Policies")
public void testGetApplicationPolicies() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
adminService.getApplicationPolicies();
Mockito.verify(policyDAO, Mockito.times(1)).getApplicationPolicies();
// Error path
Mockito.when(policyDAO.getApplicationPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getApplicationPolicies();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Application policies");
}
}
Aggregations