summaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-18 09:44:34 +0200
committerDavid Gageot <david@gageot.net>2012-07-18 09:44:34 +0200
commite0e247b684d77a4522f3b393db86d4501aa27e3a (patch)
tree413f77b4e0d2b0b54ee4fea12797d92c6de69180 /sonar-core/src
parentfdc4b664a5d841ec80e15c0867d697dc02f2f4cb (diff)
downloadsonarqube-e0e247b684d77a4522f3b393db86d4501aa27e3a.tar.gz
sonarqube-e0e247b684d77a4522f3b393db86d4501aa27e3a.zip
Add unit tests for important setings
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java20
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/MsSqlTest.java24
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java25
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java28
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java27
5 files changed, 79 insertions, 45 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java
index a57517bba71..54e1319a736 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/H2Test.java
@@ -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");
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MsSqlTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MsSqlTest.java
index c203dc58850..4b1570c8570 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MsSqlTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MsSqlTest.java
@@ -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");
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java
index 24cb09f7d91..dd1d9b47198 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/MySqlTest.java
@@ -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");
+ }
+}
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java
index 018acf96555..203bc53477b 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java
@@ -19,21 +19,18 @@
*/
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");
}
}
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java
index 20696247f7d..bde06f8579d 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java
@@ -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");
}
}