Search in sources :

Example 1 with MySql

use of org.sonar.db.dialect.MySql in project sonarqube by SonarSource.

the class DatabaseCheckerTest method fail_if_cant_get_db_version.

@Test
public void fail_if_cant_get_db_version() throws Exception {
    SQLException sqlException = new SQLException();
    Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS);
    when(db.getDialect()).thenReturn(new MySql());
    when(db.getDataSource().getConnection().getMetaData()).thenThrow(sqlException);
    try {
        new DatabaseChecker(db).start();
        fail();
    } catch (RuntimeException e) {
        assertThat(e.getCause()).isSameAs(sqlException);
    }
}
Also used : SQLException(java.sql.SQLException) MySql(org.sonar.db.dialect.MySql) Test(org.junit.Test)

Example 2 with MySql

use of org.sonar.db.dialect.MySql in project sonarqube by SonarSource.

the class DatabaseCheckerTest method test_mysql.

@Test
public void test_mysql() throws Exception {
    Database db = mockDb(new MySql(), 5, 7, "5.7");
    new DatabaseChecker(db).start();
// no error
}
Also used : MySql(org.sonar.db.dialect.MySql) Test(org.junit.Test)

Example 3 with MySql

use of org.sonar.db.dialect.MySql in project sonarqube by SonarSource.

the class BooleanColumnDefTest method generate_sql_type.

@Test
public void generate_sql_type() throws Exception {
    BooleanColumnDef def = new BooleanColumnDef.Builder().setColumnName("enabled").setIsNullable(true).build();
    assertThat(def.generateSqlType(new H2())).isEqualTo("BOOLEAN");
    assertThat(def.generateSqlType(new PostgreSql())).isEqualTo("BOOLEAN");
    assertThat(def.generateSqlType(new MsSql())).isEqualTo("BIT");
    assertThat(def.generateSqlType(new MySql())).isEqualTo("TINYINT(1)");
    assertThat(def.generateSqlType(new Oracle())).isEqualTo("NUMBER(1)");
}
Also used : PostgreSql(org.sonar.db.dialect.PostgreSql) MySql(org.sonar.db.dialect.MySql) H2(org.sonar.db.dialect.H2) MsSql(org.sonar.db.dialect.MsSql) Oracle(org.sonar.db.dialect.Oracle) Test(org.junit.Test)

Example 4 with MySql

use of org.sonar.db.dialect.MySql in project sonarqube by SonarSource.

the class DecimalColumnDefTest method generate_sql_type.

@Test
public void generate_sql_type() throws Exception {
    DecimalColumnDef def = new DecimalColumnDef.Builder().setColumnName("issues").setPrecision(30).setScale(20).setIsNullable(true).build();
    assertThat(def.generateSqlType(new H2())).isEqualTo("DOUBLE");
    assertThat(def.generateSqlType(new PostgreSql())).isEqualTo("NUMERIC (30,20)");
    assertThat(def.generateSqlType(new MsSql())).isEqualTo("DECIMAL (30,20)");
    assertThat(def.generateSqlType(new MySql())).isEqualTo("DECIMAL (30,20)");
    assertThat(def.generateSqlType(new Oracle())).isEqualTo("NUMERIC (30,20)");
}
Also used : PostgreSql(org.sonar.db.dialect.PostgreSql) MySql(org.sonar.db.dialect.MySql) H2(org.sonar.db.dialect.H2) MsSql(org.sonar.db.dialect.MsSql) Oracle(org.sonar.db.dialect.Oracle) Test(org.junit.Test)

Example 5 with MySql

use of org.sonar.db.dialect.MySql in project sonarqube by SonarSource.

the class DropIndexBuilderTest method drop_index_in_table.

@Test
public void drop_index_in_table() {
    verifySql(new H2(), "DROP INDEX IF EXISTS issues_key");
    verifySql(new MsSql(), "DROP INDEX issues_key ON issues");
    verifySql(new MySql(), "DROP INDEX issues_key ON issues");
    verifySql(new Oracle(), "DROP INDEX issues_key");
    verifySql(new PostgreSql(), "DROP INDEX IF EXISTS issues_key");
}
Also used : PostgreSql(org.sonar.db.dialect.PostgreSql) MySql(org.sonar.db.dialect.MySql) H2(org.sonar.db.dialect.H2) MsSql(org.sonar.db.dialect.MsSql) Oracle(org.sonar.db.dialect.Oracle) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 MySql (org.sonar.db.dialect.MySql)12 H2 (org.sonar.db.dialect.H2)7 MsSql (org.sonar.db.dialect.MsSql)7 Oracle (org.sonar.db.dialect.Oracle)7 PostgreSql (org.sonar.db.dialect.PostgreSql)7 SQLException (java.sql.SQLException)1 Matchers.anyString (org.mockito.Matchers.anyString)1