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;
}
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()));
}
}
}
}
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);
}
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.");
}
}
}
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());
}
Aggregations