use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testGetPoliciesByLevel.
@Test
public void testGetPoliciesByLevel() throws Exception {
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
int policySize;
// api policy by level
policySize = policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.api).size();
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
policyDAO.addApiPolicy(apiPolicy);
Assert.assertTrue(policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.api).size() == policySize + 1);
Assert.assertEquals(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName()).getUuid(), apiPolicy.getUuid());
Assert.assertEquals(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName()).getUuid(), apiPolicy.getUuid());
// application policy by level
policySize = policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application).size();
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
policyDAO.addApplicationPolicy(applicationPolicy);
Assert.assertTrue(policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application).size() == policySize + 1);
Assert.assertEquals(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName()).getUuid(), applicationPolicy.getUuid());
Assert.assertEquals(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName()).getUuid(), applicationPolicy.getUuid());
// subscription policy by level
policySize = policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.subscription).size();
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
policyDAO.addSubscriptionPolicy(subscriptionPolicy);
Assert.assertTrue(policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.subscription).size() == policySize + 1);
Assert.assertEquals(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, subscriptionPolicy.getPolicyName()).getUuid(), subscriptionPolicy.getUuid());
Assert.assertEquals(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, subscriptionPolicy.getPolicyName()).getUuid(), subscriptionPolicy.getUuid());
// When policy is not in the DB
try {
policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, "test");
} catch (APIMgtResourceNotFoundException ex) {
Assert.assertEquals(ex.getMessage(), "Policy " + APIMgtAdminService.PolicyLevel.api + "Couldn't found " + "test");
}
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testAddGetDeleteSubscriptionPolicies.
@Test(description = "Add,Get and Delete Subscription Policies")
public void testAddGetDeleteSubscriptionPolicies() throws Exception {
SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
policy.setUuid("3d253272-25b3-11e7-93ae-92361f002671");
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
// add policy
policyDAO.addSubscriptionPolicy(policy);
// get added policy
Policy addedPolicy = policyDAO.getSubscriptionPolicy(policy.getPolicyName());
Assert.assertNotNull(addedPolicy);
Assert.assertEquals(addedPolicy.getPolicyName(), policy.getPolicyName());
// delete policy
policyDAO.deletePolicy(APIMgtAdminService.PolicyLevel.subscription, policy.getPolicyName());
// get policy after deletion
try {
policyDAO.getSubscriptionPolicy(policy.getPolicyName());
Assert.fail("Exception expected, but not thrown.");
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Subscription Policy not found for name: " + addedPolicy.getPolicyName());
}
// test for exception: retrieving not available policy
try {
policyDAO.getSubscriptionPolicyByUuid(policy.getUuid());
Assert.fail("Exception expected, but not thrown.");
} catch (APIMgtDAOException ex) {
Assert.assertEquals(ex.getMessage(), "Subscription 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 testGetPolicyByLevelAndUUUID.
@Test
public void testGetPolicyByLevelAndUUUID() throws Exception {
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
policyDAO.addApiPolicy(apiPolicy);
policyDAO.addApplicationPolicy(applicationPolicy);
policyDAO.addSubscriptionPolicy(subscriptionPolicy);
Assert.assertEquals(policyDAO.getPolicyByLevelAndUUID(APIMgtAdminService.PolicyLevel.api, apiPolicy.getUuid()).getPolicyName(), apiPolicy.getPolicyName());
Assert.assertEquals(policyDAO.getPolicyByLevelAndUUID(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getUuid()).getPolicyName(), applicationPolicy.getPolicyName());
Assert.assertEquals(policyDAO.getPolicyByLevelAndUUID(APIMgtAdminService.PolicyLevel.subscription, subscriptionPolicy.getUuid()).getPolicyName(), subscriptionPolicy.getPolicyName());
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testGetAPIPolicies.
@Test(description = "Get API Policies")
public void testGetAPIPolicies() throws Exception {
APIPolicy policy = SampleTestObjectCreator.createDefaultAPIPolicy();
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
// add policy
policyDAO.addApiPolicy(policy);
List<APIPolicy> policyList = policyDAO.getApiPolicies();
Assert.assertNotNull(policyList);
Assert.assertNotNull(policyDAO.getApiPolicy(policy.getPolicyName()), "Retrieving API policy by name failed " + "for policy with name: " + policy.getPolicyName());
Assert.assertNotNull(policyDAO.getApiPolicyByUuid(policy.getUuid()), "Retrieving API policy by id failed for " + "policy with id: " + policy.getUuid());
}
use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.
the class PolicyDAOImplIT method testGetCustomPolicies.
@Test
public void testGetCustomPolicies() throws Exception {
PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
int size = policyDAO.getCustomPolicies().size();
CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
policyDAO.addCustomPolicy(customPolicy);
Assert.assertTrue(policyDAO.getCustomPolicies().size() == size + 1);
}
Aggregations