use of org.sonar.api.config.internal.Settings in project sonarqube by SonarSource.
the class CoreTestDb method init.
private CoreTestDb init(@Nullable String schemaPath, boolean databaseToUpper) {
Consumer<Settings> noExtraSettingsLoaded = settings -> {
};
Function<Settings, Database> databaseCreator = settings -> {
String dialect = settings.getString("sonar.jdbc.dialect");
// test relying on CoreTestDb can only run on H2
if (dialect != null && !"h2".equals(dialect)) {
throw new AssumptionViolatedException("This test is intended to be run on H2 only");
}
String name = "h2Tests-" + (schemaPath == null ? "empty" : DigestUtils.md5Hex(schemaPath));
if (!databaseToUpper) {
name = name + ";DATABASE_TO_UPPER=FALSE";
}
name = name + ";NON_KEYWORDS=VALUE";
return new CoreH2Database(name);
};
Consumer<Database> databaseInitializer = database -> {
if (schemaPath == null) {
return;
}
((CoreH2Database) database).executeScript(schemaPath);
};
BiConsumer<Database, Boolean> noPostStartAction = (db, created) -> {
};
init(noExtraSettingsLoaded, databaseCreator, databaseInitializer, noPostStartAction);
return this;
}
use of org.sonar.api.config.internal.Settings in project sonarqube by SonarSource.
the class CoreTestDb method init.
protected void init(Consumer<Settings> settingsLoader, Function<Settings, Database> databaseCreator, Consumer<Database> databaseInitializer, BiConsumer<Database, Boolean> extendedStart) {
if (db == null) {
Settings settings = new MapSettings().addProperties(System.getProperties());
settingsLoader.accept(settings);
logJdbcSettings(settings);
db = databaseCreator.apply(settings);
db.start();
databaseInitializer.accept(db);
Loggers.get(getClass()).debug("Test Database: " + db);
String login = settings.getString(JDBC_USERNAME.getKey());
extendedStart.accept(db, true);
} else {
extendedStart.accept(db, false);
}
}
use of org.sonar.api.config.internal.Settings in project sonarqube by SonarSource.
the class TestDbImpl method init.
private void init(@Nullable String schemaPath, MyBatisConfExtension[] confExtensions) {
Consumer<Settings> loadOrchestratorSettings = OrchestratorSettingsUtils::loadOrchestratorSettings;
Function<Settings, Database> databaseCreator = settings -> {
String dialect = settings.getString("sonar.jdbc.dialect");
if (dialect != null && !"h2".equals(dialect)) {
return new DefaultDatabase(new LogbackHelper(), settings);
}
return SQDatabase.newH2Database("h2Tests" + DigestUtils.md5Hex(StringUtils.defaultString(schemaPath)), schemaPath == null);
};
Consumer<Database> schemaPathExecutor = database -> {
if (schemaPath == null) {
return;
}
// scripts are assumed to be using H2 specific syntax, ignore the test if not on H2
if (!database.getDialect().getId().equals("h2")) {
database.stop();
throw new AssumptionViolatedException("This test is intended to be run on H2 only");
}
((SQDatabase) database).executeScript(schemaPath);
};
BiConsumer<Database, Boolean> createMyBatis = (db, created) -> myBatis = newMyBatis(db, confExtensions);
init(loadOrchestratorSettings, databaseCreator, schemaPathExecutor, createMyBatis);
}
Aggregations