use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetCustomRuleByUUID.
@Test(description = "Test getting custom rule by uuid")
public void testGetCustomRuleByUUID() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
Mockito.when(policyDAO.getCustomPolicyByUuid(customPolicy.getUuid())).thenReturn(customPolicy);
CustomPolicy customPolicyReturned = adminService.getCustomRuleByUUID(customPolicy.getUuid());
Assert.assertEquals(customPolicyReturned, customPolicy);
// Error path
Mockito.when(policyDAO.getCustomPolicyByUuid(customPolicy.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getCustomRuleByUUID(customPolicy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't get custom policy by UUID: " + customPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetApiPolicies.
@Test(description = "Test getting all API Policies")
public void testGetApiPolicies() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
adminService.getApiPolicies();
Mockito.verify(policyDAO, Mockito.times(1)).getApiPolicies();
// Error path
Mockito.when(policyDAO.getApiPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getApiPolicies();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve API policies");
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetSubscriptionPolicy.
@Test(description = "Test getting Subscription policy")
public void testGetSubscriptionPolicy() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
Mockito.when(policyDAO.getSubscriptionPolicy(subscriptionPolicy.getPolicyName())).thenReturn(subscriptionPolicy);
adminService.getSubscriptionPolicy(subscriptionPolicy.getPolicyName());
Mockito.verify(policyDAO, Mockito.times(1)).getSubscriptionPolicy(subscriptionPolicy.getPolicyName());
// Error path
Mockito.when(policyDAO.getSubscriptionPolicy(subscriptionPolicy.getPolicyName())).thenThrow(APIMgtDAOException.class);
try {
adminService.getSubscriptionPolicy(subscriptionPolicy.getPolicyName());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't retrieve Subscription policy with name: " + subscriptionPolicy.getPolicyName());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetBlockConditionByUUID.
@Test(description = "Test getting block condition by uuid")
public void testGetBlockConditionByUUID() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
Mockito.when(policyDAO.getBlockConditionByUUID(blockConditions.getUuid())).thenReturn(blockConditions);
BlockConditions blockConditionsReturned = adminService.getBlockConditionByUUID(blockConditions.getUuid());
Assert.assertEquals(blockConditionsReturned, blockConditions);
// Error path
Mockito.when(policyDAO.getBlockConditionByUUID(blockConditions.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getBlockConditionByUUID(blockConditions.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Couldn't get block condition by UUID: " + blockConditions.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class SampleTestObjectCreator method createDefaultPolicy.
public static void createDefaultPolicy(PolicyDAO policyDAO) throws APIMgtDAOException {
QuotaPolicy quotaPolicy = new QuotaPolicy();
quotaPolicy.setType(REQUEST_COUNT_TYPE);
quotaPolicy.setLimit(new RequestCountLimit(SECONDS_TIMUNIT, 60, 1));
unlimitedApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addApiPolicy(unlimitedApiPolicy);
goldApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addApiPolicy(goldApiPolicy);
silverApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addApiPolicy(silverApiPolicy);
bronzeApiPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addApiPolicy(bronzeApiPolicy);
unlimitedSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addSubscriptionPolicy(unlimitedSubscriptionPolicy);
goldSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addSubscriptionPolicy(goldSubscriptionPolicy);
silverSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addSubscriptionPolicy(silverSubscriptionPolicy);
bronzeSubscriptionPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addSubscriptionPolicy(bronzeSubscriptionPolicy);
fiftyPerMinApplicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addApplicationPolicy(fiftyPerMinApplicationPolicy);
twentyPerMinApplicationPolicy.setDefaultQuotaPolicy(quotaPolicy);
policyDAO.addApplicationPolicy(twentyPerMinApplicationPolicy);
}
Aggregations