Search in sources :

Example 86 with PolicyDAO

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

the class APIPublisherImplTestCase method getDefaultMockedPolicyDAO.

private PolicyDAO getDefaultMockedPolicyDAO() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
    return policyDAO;
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO)

Example 87 with PolicyDAO

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

the class ApiDAOImplIT method testGetResourcesOfApi.

@Test
public void testGetResourcesOfApi() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    List<UriTemplate> uriTemplateList = apiDAO.getResourcesOfApi(api.getContext(), api.getVersion());
    for (Map.Entry<String, UriTemplate> entry : api.getUriTemplates().entrySet()) {
        UriTemplate uriTemplate = entry.getValue();
        for (UriTemplate v : uriTemplateList) {
            if (v.getTemplateId().equals(uriTemplate.getTemplateId())) {
                Assert.assertEquals(uriTemplate.getAuthType(), v.getAuthType(), TestUtil.printDiff(uriTemplate.getAuthType(), v.getAuthType()));
                Assert.assertEquals(uriTemplate.getHttpVerb(), v.getHttpVerb(), TestUtil.printDiff(uriTemplate.getHttpVerb(), v.getHttpVerb()));
                Assert.assertEquals(uriTemplate.getUriTemplate(), v.getUriTemplate(), TestUtil.printDiff(uriTemplate.getUriTemplate(), v.getUriTemplate()));
                Assert.assertEquals(uriTemplate.getPolicy().getPolicyName(), policyDAO.getApiPolicyByUuid(v.getPolicy().getUuid()).getPolicyName(), TestUtil.printDiff(uriTemplate.getPolicy().getPolicyName(), policyDAO.getApiPolicyByUuid(v.getPolicy().getUuid()).getPolicyName()));
            }
        }
    }
}
Also used : CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) HashMap(java.util.HashMap) Map(java.util.Map) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 88 with PolicyDAO

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

the class DAOIntegrationTestBase method setUp.

@BeforeMethod
public void setUp() throws Exception {
    String sqlFilePath = null;
    if (H2.equals(database)) {
        ((H2DataSource) dataSource).resetDB();
        sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "h2.sql";
    } else if (MYSQL.contains(database)) {
        ((MySQLDataSource) dataSource).resetDB();
        sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "mysql.sql";
    } else if (POSTGRES.contains(database)) {
        ((PostgreDataSource) dataSource).resetDB();
        sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "postgres.sql";
    } else if (MSSQL.contains(database)) {
        ((MSSQLDataSource) dataSource).resetDB();
        sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "mssql.sql";
    } else if (ORACLE.contains(database)) {
        ((OracleDataSource) dataSource).resetDB();
        sqlFilePath = ".." + File.separator + ".." + File.separator + ".." + File.separator + "features" + File.separator + "apimgt" + File.separator + "org.wso2.carbon.apimgt.core.feature" + File.separator + "resources" + File.separator + "dbscripts" + File.separator + "oracle.sql";
    }
    DAOUtil.clearDataSource();
    DAOUtil.initialize(dataSource);
    try (Connection connection = DAOUtil.getConnection()) {
        DBScriptRunnerUtil.executeSQLScript(sqlFilePath, connection);
    }
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    SampleTestObjectCreator.createDefaultPolicy(policyDAO);
}
Also used : Connection(java.sql.Connection) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 89 with PolicyDAO

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

the class ApplicationDAOImplIT method testGetAllApplicationsForValidation.

@Test
public void testGetAllApplicationsForValidation() throws Exception {
    // add 4 apps
    String username = "admin";
    Application app1 = TestUtil.addCustomApplication("App1", username);
    Application app2 = TestUtil.addCustomApplication("App2", username);
    Application app3 = TestUtil.addCustomApplication("App3", username);
    Application app4 = TestUtil.addCustomApplication("App4", username);
    ApplicationDAO applicationDAO = DAOFactory.getApplicationDAO();
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    // get added apps
    List<Application> appsFromDB = applicationDAO.getAllApplications();
    Assert.assertNotNull(appsFromDB);
    Assert.assertEquals(appsFromDB.size(), 4);
    for (Application application : appsFromDB) {
        Assert.assertNotNull(application);
        if (application.getName().equals(app1.getName())) {
            validateApp(application, app1, policyDAO);
        } else if (application.getName().equals(app2.getName())) {
            validateApp(application, app2, policyDAO);
        } else if (application.getName().equals(app3.getName())) {
            validateApp(application, app3, policyDAO);
        } else if (application.getName().equals(app4.getName())) {
            validateApp(application, app4, policyDAO);
        } else {
            Assert.fail("Invalid Application returned.");
        }
    }
}
Also used : ApplicationDAO(org.wso2.carbon.apimgt.core.dao.ApplicationDAO) Application(org.wso2.carbon.apimgt.core.models.Application) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 90 with PolicyDAO

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

the class PolicyDAOImplIT method testFingerprintAfterUpdatingAPIPolicy.

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

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