use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testGetAPIPolicyWithBandwidthLimit.
@Test(description = "Get API Policies with bandwidth limit")
public void testGetAPIPolicyWithBandwidthLimit() throws Exception {
APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicyWithBandwidthLimit();
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
// add policy
policyDAO.addApiPolicy(policy);
Policy policyAdded = policyDAO.getApiPolicy(policy.getPolicyName());
Assert.assertNotNull(policyAdded);
Assert.assertEquals(policyAdded.getPolicyName(), policy.getPolicyName());
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testAddGetAndDeleteApplicationPolicy.
@Test(description = "Add, Get and Delete an Application policy")
public void testAddGetAndDeleteApplicationPolicy() throws Exception {
ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
// add policy
policyDAO.addApplicationPolicy(policy);
// get added policy
Policy addedPolicy = policyDAO.getApplicationPolicy(policy.getPolicyName());
Assert.assertNotNull(addedPolicy);
Assert.assertEquals(addedPolicy.getPolicyName(), policy.getPolicyName());
// delete policy
policyDAO.deletePolicy(APIMgtAdminService.PolicyLevel.application, policy.getPolicyName());
// get policy after deletion
try {
policyDAO.getApplicationPolicy(policy.getPolicyName());
Assert.fail("Exception expected, but not thrown.");
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Application Policy not found for name: " + addedPolicy.getPolicyName());
}
try {
policyDAO.getApplicationPolicyByUuid(policy.getUuid());
Assert.fail("Exception expected, but not thrown.");
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Application Policy not found for id: " + addedPolicy.getUuid());
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testGetSubscriptionPolicyByUUIDandName.
@Test(description = "Get Subscription Policy by Name and UUID")
public void testGetSubscriptionPolicyByUUIDandName() throws Exception {
SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
// add policy
policyDAO.addSubscriptionPolicy(policy);
SubscriptionPolicy retrievedPolicy = policyDAO.getSubscriptionPolicy(policy.getPolicyName());
Assert.assertNotNull(retrievedPolicy);
Assert.assertEquals(retrievedPolicy.getPolicyName(), policy.getPolicyName(), "Subscription policy name mismatch");
Assert.assertEquals(retrievedPolicy.getDisplayName(), policy.getDisplayName(), "Subscription policy display name mismatch");
Assert.assertEquals(retrievedPolicy.getDescription(), policy.getDescription(), "Subscription policy description mismatch");
Assert.assertEquals(retrievedPolicy.isDeployed(), policy.isDeployed(), "Subscription policy isDeployed mismatch");
Assert.assertEquals(retrievedPolicy.getRateLimitCount(), policy.getRateLimitCount(), "Subscription policy rate limit mismatch");
Assert.assertEquals(retrievedPolicy.getRateLimitTimeUnit(), policy.getRateLimitTimeUnit(), "Subscription policy rate limit mismatch");
Assert.assertEquals(retrievedPolicy.isStopOnQuotaReach(), policy.isStopOnQuotaReach(), "Subscription policy stop on quota reach mismatch");
Assert.assertEquals(retrievedPolicy.getCustomAttributes(), policy.getCustomAttributes(), "Subscription policy custom attribute mismatch");
Assert.assertEquals(retrievedPolicy.getDefaultQuotaPolicy().getType(), policy.getDefaultQuotaPolicy().getType(), "Subscription policy default quota type mismatch");
RequestCountLimit limitRetrieved = (RequestCountLimit) retrievedPolicy.getDefaultQuotaPolicy().getLimit();
RequestCountLimit policyLimit = (RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit();
Assert.assertEquals(limitRetrieved.getRequestCount(), policyLimit.getRequestCount(), "Subscription policy default quota count mismatch");
Assert.assertEquals(limitRetrieved.getTimeUnit(), policyLimit.getTimeUnit(), "Subscription policy default quota time unit mismatch");
Assert.assertEquals(limitRetrieved.getUnitTime(), policyLimit.getUnitTime(), "Subscription policy default quota unit time mismatch");
// get the UUID of the created policy. since this value is generated in the code, we use previously retrieved
// policy to get the uuid and again query the policy
String uuid = retrievedPolicy.getUuid();
retrievedPolicy = policyDAO.getSubscriptionPolicyByUuid(uuid);
Assert.assertNotNull(retrievedPolicy);
Assert.assertEquals(retrievedPolicy.getPolicyName(), policy.getPolicyName(), "Subscription policy name mismatch");
Assert.assertEquals(retrievedPolicy.getDisplayName(), policy.getDisplayName(), "Subscription policy display name mismatch");
Assert.assertEquals(retrievedPolicy.getDescription(), policy.getDescription(), "Subscription policy description mismatch");
Assert.assertEquals(retrievedPolicy.isDeployed(), policy.isDeployed(), "Subscription policy isDeployed mismatch");
Assert.assertEquals(retrievedPolicy.getRateLimitCount(), policy.getRateLimitCount(), "Subscription policy rate limit mismatch");
Assert.assertEquals(retrievedPolicy.getRateLimitTimeUnit(), policy.getRateLimitTimeUnit(), "Subscription policy rate limit mismatch");
Assert.assertEquals(retrievedPolicy.isStopOnQuotaReach(), policy.isStopOnQuotaReach(), "Subscription policy stop on quota reach mismatch");
Assert.assertEquals(retrievedPolicy.getCustomAttributes(), policy.getCustomAttributes(), "Subscription policy custom attribute mismatch");
Assert.assertEquals(retrievedPolicy.getDefaultQuotaPolicy().getType(), policy.getDefaultQuotaPolicy().getType(), "Subscription policy default quota type mismatch");
limitRetrieved = (RequestCountLimit) retrievedPolicy.getDefaultQuotaPolicy().getLimit();
policyLimit = (RequestCountLimit) policy.getDefaultQuotaPolicy().getLimit();
Assert.assertEquals(limitRetrieved.getRequestCount(), policyLimit.getRequestCount(), "Subscription policy default quota count mismatch");
Assert.assertEquals(limitRetrieved.getTimeUnit(), policyLimit.getTimeUnit(), "Subscription policy default quota time unit mismatch");
Assert.assertEquals(limitRetrieved.getUnitTime(), policyLimit.getUnitTime(), "Subscription policy default quota unit time mismatch");
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testUpdateApplication.
@Test(description = "Update an application")
public void testUpdateApplication() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIGateway apiGateway = Mockito.mock(APIGateway.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO, apiGateway);
Application existingApplication = SampleTestObjectCreator.createDefaultApplication();
String appUUID = existingApplication.getUuid();
existingApplication.setStatus(ApplicationStatus.APPLICATION_APPROVED);
Mockito.when(applicationDAO.getApplication(appUUID)).thenReturn(existingApplication);
// Updating the existing application
Application updatedApplication = SampleTestObjectCreator.createDefaultApplication();
updatedApplication.setDescription("updated description");
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
applicationPolicy.setPolicyName(TIER);
updatedApplication.setPolicy(applicationPolicy);
updatedApplication.setStatus(ApplicationStatus.APPLICATION_APPROVED);
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName())).thenReturn(applicationPolicy);
apiStore.updateApplication(appUUID, updatedApplication);
Mockito.verify(applicationDAO, Mockito.times(1)).updateApplication(appUUID, updatedApplication);
// Error
// APIMgtDAOException
Mockito.doThrow(APIMgtDAOException.class).when(applicationDAO).updateApplication(appUUID, updatedApplication);
try {
apiStore.updateApplication(appUUID, updatedApplication);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while updating the application - " + appUUID);
}
// Error path
// When specified tier in the updated application is invalid
Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName())).thenReturn(null);
try {
apiStore.updateApplication(appUUID, updatedApplication);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Specified tier " + applicationPolicy + " is invalid");
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testAddApplicationNullPolicy.
@Test(description = "Add an application with null policy", expectedExceptions = APIManagementException.class)
public void testAddApplicationNullPolicy() throws Exception {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
WorkflowDAO workflowDAO = Mockito.mock(WorkflowDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, policyDAO, workflowDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setPolicy(new ApplicationPolicy(TIER));
Mockito.when(applicationDAO.isApplicationNameExists(APP_NAME)).thenReturn(false);
Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, TIER)).thenReturn(null);
apiStore.addApplication(application);
}
Aggregations