use of org.wso2.carbon.apimgt.core.models.policy.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());
}
use of org.wso2.carbon.apimgt.core.models.policy.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());
}
use of org.wso2.carbon.apimgt.core.models.policy.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());
}
use of org.wso2.carbon.apimgt.core.models.policy.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");
}
use of org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAPISubscriptionsByApplication.
@Test(description = "Get API subscriptions by application")
public void testGetAPISubscriptionsByApplication() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO);
Application application = new Application(APP_NAME, USER_NAME);
application.setPolicy(new ApplicationPolicy(TIER));
application.setId(UUID);
apiStore.getAPISubscriptionsByApplication(application);
Mockito.verify(apiSubscriptionDAO, Mockito.times(1)).getAPISubscriptionsByApplication(UUID);
}
Aggregations