aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2012-01-08 18:34:40 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2012-01-09 07:08:48 +0100
commit7658d8f74f2fda7765d6e728f409a8ea6a894095 (patch)
treedd936b9aa29ed7d014de5722fdc422a8b83974b6 /sonar-core/src
parent7778aa10c624005180946fa135c410cf961fa40f (diff)
downloadsonarqube-7658d8f74f2fda7765d6e728f409a8ea6a894095.tar.gz
sonarqube-7658d8f74f2fda7765d6e728f409a8ea6a894095.zip
Add some unit tests
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java5
-rw-r--r--sonar-core/src/main/java/org/sonar/core/review/ReviewMapper.java2
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/review/ReviewMapper.xml111
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/DerbyTest.java13
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/MsSqlTest.java15
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/OracleTest.java17
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/dialect/PostgreSqlTest.java16
7 files changed, 98 insertions, 81 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
index b53150def63..8c4d5b93b44 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoUtils.java
@@ -28,6 +28,7 @@ import org.sonar.core.rule.RuleDao;
import org.sonar.core.template.LoadedTemplateDao;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
public final class DaoUtils {
@@ -36,13 +37,13 @@ public final class DaoUtils {
}
public static List<Class<?>> getDaoClasses() {
- return Arrays.asList(
+ return Collections.unmodifiableList(Arrays.asList(
ActiveDashboardDao.class,
DashboardDao.class,
DuplicationDao.class,
LoadedTemplateDao.class,
ResourceIndexerDao.class,
ReviewDao.class,
- RuleDao.class);
+ RuleDao.class));
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/review/ReviewMapper.java b/sonar-core/src/main/java/org/sonar/core/review/ReviewMapper.java
index e2c2f879cf0..2b8853a9f95 100644
--- a/sonar-core/src/main/java/org/sonar/core/review/ReviewMapper.java
+++ b/sonar-core/src/main/java/org/sonar/core/review/ReviewMapper.java
@@ -32,6 +32,4 @@ public interface ReviewMapper {
List<ReviewDto> selectByResource(int resourceId);
List<ReviewDto> selectByQuery(ReviewQuery query);
-
- List<ReviewDto> selectCloseables(@Param("resourceId") int resourceId, @Param("snapshotId") int snapshotId);
}
diff --git a/sonar-core/src/main/resources/org/sonar/core/review/ReviewMapper.xml b/sonar-core/src/main/resources/org/sonar/core/review/ReviewMapper.xml
index 5ccb4e72519..2f897ff6e1c 100644
--- a/sonar-core/src/main/resources/org/sonar/core/review/ReviewMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/review/ReviewMapper.xml
@@ -3,68 +3,55 @@
<mapper namespace="org.sonar.core.review.ReviewMapper">
- <resultMap id="reviewResultMap" type="Review">
- <result property="createdAt" column="created_at"/>
- <result property="updatedAt" column="updated_at"/>
- <result property="userId" column="user_id"/>
- <result property="assigneeId" column="assignee_id"/>
- <result property="violationPermanentId" column="rule_failure_permanent_id"/>
- <result property="projectId" column="project_id"/>
- <result property="resourceId" column="resource_id"/>
- <result property="line" column="resource_line"/>
- <result property="ruleId" column="rule_id"/>
- <result property="manualViolation" column="manual_violation"/>
- </resultMap>
-
- <sql id="reviewColumns">id, created_at, updated_at, user_id, assignee_id, title,status,resolution,rule_failure_permanent_id,project_id, resource_id, resource_line, severity, rule_id,
- manual_violation
- </sql>
-
- <select id="selectById" parameterType="long" resultMap="reviewResultMap">
- select
- <include refid="reviewColumns"/>
- from reviews where id=#{id}
- </select>
-
- <select id="selectByResource" parameterType="int" resultMap="reviewResultMap">
- select
- <include refid="reviewColumns"/>
- from reviews where resource_id=#{id}
- </select>
-
- <select id="selectByQuery" parameterType="org.sonar.core.review.ReviewQuery" resultMap="reviewResultMap">
- select
- <include refid="reviewColumns"/>
- from reviews
- <where>
- <if test="userId != null">user_id = #{userId}</if>
- <if test="violationPermanentIds != null">AND rule_failure_permanent_id in
- <foreach item="permanentId" index="index" collection="violationPermanentIds"
- open="(" separator="," close=")"> #{permanentId}
- </foreach>
- </if>
- <if test="ruleId != null">AND rule_id = #{ruleId}</if>
- <if test="resourceId != null">AND resource_id = #{resourceId}</if>
- <if test="status != null">AND status = #{status}</if>
- <if test="manualViolation != null">AND manual_violation = #{manualViolation}</if>
- <if test="manualSeverity != null">AND manual_severity = #{manualSeverity}</if>
- <if test="resolution != null">AND resolution = #{resolution}</if>
- </where>
- </select>
-
- <select id="selectCloseables" parameterType="map" resultMap="reviewResultMap">
- select
- <include refid="reviewColumns"/>
- from reviews
- <where>
- resource_id=#{resourceId} AND
- (
- (manual_violation=false AND status!='CLOSED' AND rule_failure_permanent_id NOT IN (SELECT permanent_id FROM rule_failures WHERE snapshot_id=#{snapshotId} AND permanent_id IS NOT NULL))
- OR
- (manual_violation=true AND status='RESOLVED')
- )
- </where>
- </select>
+ <resultMap id="reviewResultMap" type="Review">
+ <result property="createdAt" column="created_at"/>
+ <result property="updatedAt" column="updated_at"/>
+ <result property="userId" column="user_id"/>
+ <result property="assigneeId" column="assignee_id"/>
+ <result property="violationPermanentId" column="rule_failure_permanent_id"/>
+ <result property="projectId" column="project_id"/>
+ <result property="resourceId" column="resource_id"/>
+ <result property="line" column="resource_line"/>
+ <result property="ruleId" column="rule_id"/>
+ <result property="manualViolation" column="manual_violation"/>
+ </resultMap>
+
+ <sql id="reviewColumns">id, created_at, updated_at, user_id, assignee_id,
+ title,status,resolution,rule_failure_permanent_id,project_id, resource_id, resource_line, severity, rule_id,
+ manual_violation
+ </sql>
+
+ <select id="selectById" parameterType="long" resultMap="reviewResultMap">
+ select
+ <include refid="reviewColumns"/>
+ from reviews where id=#{id}
+ </select>
+
+ <select id="selectByResource" parameterType="int" resultMap="reviewResultMap">
+ select
+ <include refid="reviewColumns"/>
+ from reviews where resource_id=#{id}
+ </select>
+
+ <select id="selectByQuery" parameterType="org.sonar.core.review.ReviewQuery" resultMap="reviewResultMap">
+ select
+ <include refid="reviewColumns"/>
+ from reviews
+ <where>
+ <if test="userId != null">user_id = #{userId}</if>
+ <if test="violationPermanentIds != null">AND rule_failure_permanent_id in
+ <foreach item="permanentId" index="index" collection="violationPermanentIds"
+ open="(" separator="," close=")">#{permanentId}
+ </foreach>
+ </if>
+ <if test="ruleId != null">AND rule_id = #{ruleId}</if>
+ <if test="resourceId != null">AND resource_id = #{resourceId}</if>
+ <if test="status != null">AND status = #{status}</if>
+ <if test="manualViolation != null">AND manual_violation = #{manualViolation}</if>
+ <if test="manualSeverity != null">AND manual_severity = #{manualSeverity}</if>
+ <if test="resolution != null">AND resolution = #{resolution}</if>
+ </where>
+ </select>
</mapper>
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/DerbyTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/DerbyTest.java
index 93e743077c7..27803cfa7e6 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/dialect/DerbyTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/dialect/DerbyTest.java
@@ -25,9 +25,18 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
public class DerbyTest {
+
+ private Derby derby = new Derby();
+
@Test
public void matchesJdbcURL() {
- assertThat(new Derby().matchesJdbcURL("jdbc:derby:foo"), is(true));
- assertThat(new Derby().matchesJdbcURL("jdbc:hsql:foo"), is(false));
+ assertThat(derby.matchesJdbcURL("jdbc:derby:foo"), is(true));
+ assertThat(derby.matchesJdbcURL("jdbc:hsql:foo"), is(false));
+ }
+
+ @Test
+ public void testBooleanSqlValues() {
+ assertThat(derby.getTrueSqlValue(), is("true"));
+ assertThat(derby.getFalseSqlValue(), is("false"));
}
}
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 161e9a6d0ce..ffc8dcc40db 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
@@ -26,13 +26,20 @@ import static org.junit.Assert.assertThat;
public class MsSqlTest {
+ private MsSql msSql = new MsSql();
+
@Test
public void matchesJdbcURL() {
- assertThat(new MsSql().matchesJdbcURL("jdbc:jtds:sqlserver://localhost;databaseName=SONAR;SelectMethod=Cursor"), is(true));
- assertThat(new MsSql().matchesJdbcURL("jdbc:microsoft:sqlserver://localhost:1433;databasename=sonar"), is(true));
+ 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(new MsSql().matchesJdbcURL("jdbc:hsql:foo"), is(false));
- assertThat(new MsSql().matchesJdbcURL("jdbc:mysql:foo"), is(false));
+ assertThat(msSql.matchesJdbcURL("jdbc:hsql:foo"), is(false));
+ assertThat(msSql.matchesJdbcURL("jdbc:mysql:foo"), is(false));
}
+ @Test
+ public void testBooleanSqlValues() {
+ assertThat(msSql.getTrueSqlValue(), is("1"));
+ assertThat(msSql.getFalseSqlValue(), is("0"));
+ }
}
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 2478dd5a384..2ddd7c8068e 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
@@ -27,10 +27,13 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
public class OracleTest {
+
+ private Oracle oracle = new Oracle();
+
@Test
public void matchesJdbcURL() {
- assertThat(new Oracle().matchesJdbcURL("jdbc:oracle:thin:@localhost/XE"), is(true));
- assertThat(new Oracle().matchesJdbcURL("jdbc:hsql:foo"), is(false));
+ assertThat(oracle.matchesJdbcURL("jdbc:oracle:thin:@localhost/XE"), is(true));
+ assertThat(oracle.matchesJdbcURL("jdbc:hsql:foo"), is(false));
}
/**
@@ -38,15 +41,19 @@ public class OracleTest {
*/
@Test
public void shouldChangeOracleSchema() {
- String initStatement = new Oracle().getConnectionInitStatement("my_schema");
+ String initStatement = oracle.getConnectionInitStatement("my_schema");
assertThat(initStatement, Is.is("ALTER SESSION SET CURRENT_SCHEMA = \"my_schema\""));
}
@Test
public void shouldNotChangeOracleSchemaByDefault() {
- assertNull(new Oracle().getConnectionInitStatement(null));
+ assertNull(oracle.getConnectionInitStatement(null));
}
-
+ @Test
+ public void testBooleanSqlValues() {
+ assertThat(oracle.getTrueSqlValue(), is("1"));
+ assertThat(oracle.getFalseSqlValue(), is("0"));
+ }
}
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 dbf36e94758..328a41318cb 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
@@ -27,10 +27,13 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
public class PostgreSqlTest {
+
+ private PostgreSql postgreSql = new PostgreSql();
+
@Test
public void matchesJdbcURL() {
- assertThat(new PostgreSql().matchesJdbcURL("jdbc:postgresql://localhost/sonar"), is(true));
- assertThat(new PostgreSql().matchesJdbcURL("jdbc:hsql:foo"), is(false));
+ assertThat(postgreSql.matchesJdbcURL("jdbc:postgresql://localhost/sonar"), is(true));
+ assertThat(postgreSql.matchesJdbcURL("jdbc:hsql:foo"), is(false));
}
/**
@@ -38,14 +41,19 @@ public class PostgreSqlTest {
*/
@Test
public void shouldChangePostgreSearchPath() {
- String initStatement = new PostgreSql().getConnectionInitStatement("my_schema");
+ String initStatement = postgreSql.getConnectionInitStatement("my_schema");
assertThat(initStatement, Is.is("SET SEARCH_PATH TO my_schema"));
}
@Test
public void shouldNotChangePostgreSearchPathByDefault() {
- assertNull(new PostgreSql().getConnectionInitStatement(null));
+ assertNull(postgreSql.getConnectionInitStatement(null));
}
+ @Test
+ public void testBooleanSqlValues() {
+ assertThat(postgreSql.getTrueSqlValue(), is("true"));
+ assertThat(postgreSql.getFalseSqlValue(), is("false"));
+ }
}