Search in sources :

Example 96 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO 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 97 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO 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 98 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO 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)

Example 99 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.

the class PolicyDAOImplIT method testAddGetUpdateDeleteCustomPolicy.

@Test
public void testAddGetUpdateDeleteCustomPolicy() throws Exception {
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    CustomPolicy customPolicy = SampleTestObjectCreator.createDefaultCustomPolicy();
    String uuid = policyDAO.addCustomPolicy(customPolicy);
    CustomPolicy policyAdded = policyDAO.getCustomPolicyByUuid(uuid);
    Assert.assertEquals(customPolicy.getSiddhiQuery(), policyAdded.getSiddhiQuery());
    policyAdded.setDescription("updated custom policy");
    policyDAO.updateCustomPolicy(policyAdded);
    Assert.assertEquals(policyDAO.getCustomPolicyByUuid(uuid).getDescription(), "updated custom policy");
    policyDAO.deleteCustomPolicy(uuid);
    CustomPolicy policyDeletion = policyDAO.getCustomPolicyByUuid(uuid);
    Assert.assertNull(policyDeletion);
}
Also used : CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 100 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testGetAPIWithAllowedLifecycleState.

@Test(description = "Test get API with allowed lifecycle states (Published, Prototyped, Deprecated)")
public void testGetAPIWithAllowedLifecycleState() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    Policy policy = new SubscriptionPolicy(UUID, TIER);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, TIER)).thenReturn(policy);
    APIStore apiStore = getApiStoreImpl(apiDAO, Mockito.mock(ApplicationDAO.class), Mockito.mock(APISubscriptionDAO.class), Mockito.mock(WorkflowDAO.class), Mockito.mock(APIGateway.class), policyDAO);
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI();
    String apiId = apiBuilder.getId();
    List<String> allowedStates = new ArrayList<String>() {

        {
            add(APIStatus.PROTOTYPED.getStatus());
            add(APIStatus.PUBLISHED.getStatus());
            add(APIStatus.DEPRECATED.getStatus());
        }
    };
    for (String allowedState : allowedStates) {
        apiBuilder.lifeCycleStatus(allowedState);
        API api = apiBuilder.build();
        Mockito.when(apiDAO.getAPI(apiId)).thenReturn(api);
        API returnedAPI = apiStore.getAPIbyUUID(apiId);
        Assert.assertEquals(returnedAPI.getLifeCycleStatus(), allowedState);
    }
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APISubscriptionDAO(org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) ArrayList(java.util.ArrayList) ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) WorkflowDAO(org.wso2.carbon.apimgt.core.dao.WorkflowDAO) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)106 Test (org.testng.annotations.Test)102 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)50 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)50 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)45 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)36 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)33 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)30 API (org.wso2.carbon.apimgt.core.models.API)28 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)27 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)24 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)24 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)23 BeforeTest (org.testng.annotations.BeforeTest)20 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)20 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)17 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)16 Application (org.wso2.carbon.apimgt.core.models.Application)15 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)14 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)13