Search in sources :

Example 81 with ApplicationPolicy

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy 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");
    }
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 82 with ApplicationPolicy

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy 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());
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 83 with ApplicationPolicy

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.

the class PolicyDAOImplIT method testFingerprintAfterUpdatingApplicationPolicy.

@Test
public void testFingerprintAfterUpdatingApplicationPolicy() throws Exception {
    ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    policyDAO.addApplicationPolicy(policy);
    String fingerprintBeforeUpdatingPolicy = ETagUtils.generateETag(policyDAO.getLastUpdatedTimeOfThrottlingPolicy(APIMgtAdminService.PolicyLevel.application, policy.getPolicyName()));
    Assert.assertNotNull(fingerprintBeforeUpdatingPolicy);
    ApplicationPolicy updatedPolicy = SampleTestObjectCreator.updateApplicationPolicy(policy);
    Thread.sleep(100L);
    policyDAO.updateApplicationPolicy(updatedPolicy);
    String fingerprintAfterUpdatingPolicy = ETagUtils.generateETag(policyDAO.getLastUpdatedTimeOfThrottlingPolicy(APIMgtAdminService.PolicyLevel.application, updatedPolicy.getPolicyName()));
    Assert.assertNotNull(fingerprintAfterUpdatingPolicy);
    Assert.assertNotEquals(fingerprintBeforeUpdatingPolicy, fingerprintAfterUpdatingPolicy, "Policy " + "fingerprint expected to be different before and after updating for policy: " + policy.getPolicyName());
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 84 with ApplicationPolicy

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.

the class PolicyDAOImplIT method testGetApplicationPolicies.

@Test(description = "Get Application Policies")
public void testGetApplicationPolicies() throws Exception {
    ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    // add policy
    policyDAO.addApplicationPolicy(policy);
    List<ApplicationPolicy> policyList = policyDAO.getApplicationPolicies();
    Assert.assertNotNull(policyList);
    Assert.assertNotNull(policyDAO.getApplicationPolicy(policy.getPolicyName()), "Retrieving Application policy by " + "name failed for policy with name: " + policy.getPolicyName());
    Assert.assertNotNull(policyDAO.getApplicationPolicyByUuid(policy.getUuid()), "Retrieving Application policy " + "by id failed for policy with id: " + policy.getUuid());
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 85 with ApplicationPolicy

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.

the class PolicyDAOImplIT method testPolicyExists.

@Test(description = "policy exists test")
public void testPolicyExists() throws Exception {
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
    policyDAO.addApplicationPolicy(applicationPolicy);
    Assert.assertTrue(policyDAO.policyExists(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName()), "Application policy with name: " + applicationPolicy.getPolicyName() + " does not exist");
    policyDAO.deletePolicyByUuid(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getUuid());
    Assert.assertFalse(policyDAO.policyExists(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName()), "Deleted Application policy with name: " + applicationPolicy.getPolicyName() + " still exists");
    SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    policyDAO.addSubscriptionPolicy(subscriptionPolicy);
    Assert.assertTrue(policyDAO.policyExists(APIMgtAdminService.PolicyLevel.subscription, subscriptionPolicy.getPolicyName()), "Subscription policy with name: " + subscriptionPolicy.getPolicyName() + " does not exist");
    policyDAO.deletePolicyByUuid(APIMgtAdminService.PolicyLevel.subscription, subscriptionPolicy.getUuid());
    Assert.assertFalse(policyDAO.policyExists(APIMgtAdminService.PolicyLevel.subscription, subscriptionPolicy.getPolicyName()), "Deleted Subscription policy with name: " + subscriptionPolicy.getPolicyName() + " still exists");
    APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
    policyDAO.addApiPolicy(apiPolicy);
    Assert.assertTrue(policyDAO.policyExists(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName()), "API" + " policy with name: " + apiPolicy.getPolicyName() + " does not exist");
    policyDAO.deletePolicyByUuid(APIMgtAdminService.PolicyLevel.api, apiPolicy.getUuid());
    Assert.assertFalse(policyDAO.policyExists(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName()), "Deleted API policy with name: " + apiPolicy.getPolicyName() + " still exists");
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Aggregations

ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)56 Test (org.testng.annotations.Test)30 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)29 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)24 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)18 Application (org.wso2.carbon.apimgt.core.models.Application)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)13 BeforeTest (org.testng.annotations.BeforeTest)13 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)13 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)13 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)13 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)12 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)12