]> source.dussan.org Git - sonarqube.git/commitdiff
Add unit tests for important setings
authorDavid Gageot <david@gageot.net>
Wed, 18 Jul 2012 07:44:34 +0000 (09:44 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 18 Jul 2012 07:44:34 +0000 (09:44 +0200)
sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java
sonar-core/src/test/java/org/sonar/core/persistence/dialect/MsSqlTest.java
sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java
sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java
sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java

index a57517bba71e3d4ca7b5725eef4f92955467e69c..54e1319a736fe7b9759e2540673b136a95e39bcd 100644 (file)
@@ -21,8 +21,7 @@ package org.sonar.core.persistence.dialect;
 
 import org.junit.Test;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class H2Test {
 
@@ -30,13 +29,22 @@ public class H2Test {
 
   @Test
   public void matchesJdbcURL() {
-    assertThat(h2.matchesJdbcURL("jdbc:h2:foo"), is(true));
-    assertThat(h2.matchesJdbcURL("jdbc:hsql:foo"), is(false));
+    assertThat(h2.matchesJdbcURL("jdbc:h2:foo")).isTrue();
+    assertThat(h2.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
   }
 
   @Test
   public void testBooleanSqlValues() {
-    assertThat(h2.getTrueSqlValue(), is("true"));
-    assertThat(h2.getFalseSqlValue(), is("false"));
+    assertThat(h2.getTrueSqlValue()).isEqualTo("true");
+    assertThat(h2.getFalseSqlValue()).isEqualTo("false");
+  }
+
+  @Test
+  public void should_configure() {
+    assertThat(h2.getId()).isEqualTo("h2");
+    assertThat(h2.getActiveRecordDialectCode()).isEqualTo("h2");
+    assertThat(h2.getActiveRecordJdbcAdapter()).isEqualTo("jdbc");
+    assertThat(h2.getDefaultDriverClassName()).isEqualTo("org.h2.Driver");
+    assertThat(h2.getValidationQuery()).isEqualTo("SELECT 1");
   }
 }
index c203dc588503e32ece3a72b539bfed0e9c3ad1dc..4b1570c8570c4b50d0cde404eccc90cc8009c98f 100644 (file)
@@ -21,8 +21,7 @@ package org.sonar.core.persistence.dialect;
 
 import org.junit.Test;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class MsSqlTest {
 
@@ -30,16 +29,25 @@ public class MsSqlTest {
 
   @Test
   public void matchesJdbcURL() {
-    assertThat(msSql.matchesJdbcURL("jdbc:jtds:sqlserver://localhost;databaseName=SONAR;SelectMethod=Cursor"), is(true));
-    assertThat(msSql.matchesJdbcURL("jdbc:microsoft:sqlserver://localhost:1433;databasename=sonar"), is(true));
+    assertThat(msSql.matchesJdbcURL("jdbc:jtds:sqlserver://localhost;databaseName=SONAR;SelectMethod=Cursor")).isTrue();
+    assertThat(msSql.matchesJdbcURL("jdbc:microsoft:sqlserver://localhost:1433;databasename=sonar")).isTrue();
 
-    assertThat(msSql.matchesJdbcURL("jdbc:hsql:foo"), is(false));
-    assertThat(msSql.matchesJdbcURL("jdbc:mysql:foo"), is(false));
+    assertThat(msSql.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
+    assertThat(msSql.matchesJdbcURL("jdbc:mysql:foo")).isFalse();
   }
 
   @Test
   public void testBooleanSqlValues() {
-    assertThat(msSql.getTrueSqlValue(), is("1"));
-    assertThat(msSql.getFalseSqlValue(), is("0"));
+    assertThat(msSql.getTrueSqlValue()).isEqualTo("1");
+    assertThat(msSql.getFalseSqlValue()).isEqualTo("0");
+  }
+
+  @Test
+  public void should_configure() {
+    assertThat(msSql.getId()).isEqualTo("mssql");
+    assertThat(msSql.getActiveRecordDialectCode()).isEqualTo("sqlserver");
+    assertThat(msSql.getActiveRecordJdbcAdapter()).isEqualTo("jdbc");
+    assertThat(msSql.getDefaultDriverClassName()).isEqualTo("net.sourceforge.jtds.jdbc.Driver");
+    assertThat(msSql.getValidationQuery()).isEqualTo("SELECT 1");
   }
 }
index 24cb09f7d91a975a6c4650a845c4b9afcd39fbc3..dd1d9b47198bed91e6c20a4c5b4924445d1396e5 100644 (file)
@@ -21,8 +21,7 @@ package org.sonar.core.persistence.dialect;
 
 import org.junit.Test;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class MySqlTest {
 
@@ -30,17 +29,25 @@ public class MySqlTest {
 
   @Test
   public void matchesJdbcURL() {
-    assertThat(mySql.matchesJdbcURL("jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8"), is(true));
-    assertThat(mySql.matchesJdbcURL("JDBC:MYSQL://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8"), is(true));
+    assertThat(mySql.matchesJdbcURL("jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8")).isTrue();
+    assertThat(mySql.matchesJdbcURL("JDBC:MYSQL://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8")).isTrue();
 
-    assertThat(mySql.matchesJdbcURL("jdbc:hsql:foo"), is(false));
-    assertThat(mySql.matchesJdbcURL("jdbc:oracle:foo"), is(false));
+    assertThat(mySql.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
+    assertThat(mySql.matchesJdbcURL("jdbc:oracle:foo")).isFalse();
   }
 
   @Test
   public void testBooleanSqlValues() {
-    assertThat(mySql.getTrueSqlValue(), is("true"));
-    assertThat(mySql.getFalseSqlValue(), is("false"));
+    assertThat(mySql.getTrueSqlValue()).isEqualTo("true");
+    assertThat(mySql.getFalseSqlValue()).isEqualTo("false");
   }
-}
 
+  @Test
+  public void should_configure() {
+    assertThat(mySql.getId()).isEqualTo("mysql");
+    assertThat(mySql.getActiveRecordDialectCode()).isEqualTo("mysql");
+    assertThat(mySql.getActiveRecordJdbcAdapter()).isEqualTo("jdbc");
+    assertThat(mySql.getDefaultDriverClassName()).isEqualTo("com.mysql.jdbc.Driver");
+    assertThat(mySql.getValidationQuery()).isEqualTo("SELECT 1");
+  }
+}
index 018acf965554ec614695a898e863759eaf12a957..203bc53477bd60872454a72c96a7344a843be8f2 100644 (file)
  */
 package org.sonar.core.persistence.dialect;
 
-import org.hamcrest.core.Is;
 import org.junit.Test;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 
 public class OracleTest {
-  
+
   private Oracle oracle = new Oracle();
 
   @Test
   public void matchesJdbcURL() {
-    assertThat(oracle.matchesJdbcURL("jdbc:oracle:thin:@localhost/XE"), is(true));
-    assertThat(oracle.matchesJdbcURL("jdbc:hsql:foo"), is(false));
+    assertThat(oracle.matchesJdbcURL("jdbc:oracle:thin:@localhost/XE")).isTrue();
+    assertThat(oracle.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
   }
 
   /**
@@ -43,17 +40,26 @@ public class OracleTest {
   public void shouldChangeOracleSchema() {
     String initStatement = oracle.getConnectionInitStatement("my_schema");
 
-    assertThat(initStatement, Is.is("ALTER SESSION SET CURRENT_SCHEMA = \"my_schema\""));
+    assertThat(initStatement).isEqualTo("ALTER SESSION SET CURRENT_SCHEMA = \"my_schema\"");
   }
 
   @Test
   public void shouldNotChangeOracleSchemaByDefault() {
-    assertNull(oracle.getConnectionInitStatement(null));
+    assertThat(oracle.getConnectionInitStatement(null)).isNull();
   }
 
   @Test
   public void testBooleanSqlValues() {
-    assertThat(oracle.getTrueSqlValue(), is("1"));
-    assertThat(oracle.getFalseSqlValue(), is("0"));
+    assertThat(oracle.getTrueSqlValue()).isEqualTo("1");
+    assertThat(oracle.getFalseSqlValue()).isEqualTo("0");
+  }
+
+  @Test
+  public void should_configure() {
+    assertThat(oracle.getId()).isEqualTo("oracle");
+    assertThat(oracle.getActiveRecordDialectCode()).isEqualTo("oracle");
+    assertThat(oracle.getActiveRecordJdbcAdapter()).isEqualTo("oracle_enhanced");
+    assertThat(oracle.getDefaultDriverClassName()).isEqualTo("oracle.jdbc.OracleDriver");
+    assertThat(oracle.getValidationQuery()).isEqualTo("SELECT 1 FROM DUAL");
   }
 }
index 20696247f7d55e56333bffd43e8edd4c3f5ec779..bde06f8579dbf30f5d7db668a13dbcd0ad8117db 100644 (file)
@@ -22,8 +22,7 @@ package org.sonar.core.persistence.dialect;
 import org.hamcrest.core.Is;
 import org.junit.Test;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
+import static org.fest.assertions.Assertions.assertThat;
 import static org.junit.Assert.assertThat;
 
 public class PostgreSqlTest {
@@ -32,15 +31,12 @@ public class PostgreSqlTest {
 
   @Test
   public void matchesJdbcURL() {
-    assertThat(postgreSql.matchesJdbcURL("jdbc:postgresql://localhost/sonar"), is(true));
-    assertThat(postgreSql.matchesJdbcURL("jdbc:hsql:foo"), is(false));
+    assertThat(postgreSql.matchesJdbcURL("jdbc:postgresql://localhost/sonar")).isTrue();
+    assertThat(postgreSql.matchesJdbcURL("jdbc:hsql:foo")).isFalse();
   }
 
-  /**
-   * Avoid conflicts with other schemas
-   */
   @Test
-  public void shouldChangePostgreSearchPath() {
+  public void should_avoid_conflict_with_other_schemas() {
     String initStatement = postgreSql.getConnectionInitStatement("my_schema");
 
     assertThat(initStatement, Is.is("SET SEARCH_PATH TO my_schema"));
@@ -48,12 +44,21 @@ public class PostgreSqlTest {
 
   @Test
   public void shouldNotChangePostgreSearchPathByDefault() {
-    assertNull(postgreSql.getConnectionInitStatement(null));
+    assertThat(postgreSql.getConnectionInitStatement(null)).isNull();
   }
 
   @Test
   public void testBooleanSqlValues() {
-    assertThat(postgreSql.getTrueSqlValue(), is("true"));
-    assertThat(postgreSql.getFalseSqlValue(), is("false"));
+    assertThat(postgreSql.getTrueSqlValue()).isEqualTo("true");
+    assertThat(postgreSql.getFalseSqlValue()).isEqualTo("false");
+  }
+
+  @Test
+  public void should_configure() {
+    assertThat(postgreSql.getId()).isEqualTo("postgresql");
+    assertThat(postgreSql.getActiveRecordDialectCode()).isEqualTo("postgre");
+    assertThat(postgreSql.getActiveRecordJdbcAdapter()).isEqualTo("jdbc");
+    assertThat(postgreSql.getDefaultDriverClassName()).isEqualTo("org.postgresql.Driver");
+    assertThat(postgreSql.getValidationQuery()).isEqualTo("SELECT 1");
   }
 }