aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2014-09-25 18:11:03 +0200
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2014-09-25 18:15:28 +0200
commit48d48e90931782cc1e94768a83ada71275476ceb (patch)
tree7d5ce459835603dbe6ad9e9fd01eca46d610f9cb
parent7fd608ab6c9de5df88b77984dc431ce3066782ac (diff)
downloadsonarqube-48d48e90931782cc1e94768a83ada71275476ceb.tar.gz
sonarqube-48d48e90931782cc1e94768a83ada71275476ceb.zip
SONAR-5624 - test dao
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java62
-rw-r--r--server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml33
-rw-r--r--server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb1
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml4
-rw-r--r--sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl2
5 files changed, 71 insertions, 31 deletions
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java
new file mode 100644
index 00000000000..5397b63af15
--- /dev/null
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java
@@ -0,0 +1,62 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.computation.db;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.utils.DateUtils;
+import org.sonar.api.utils.System2;
+import org.sonar.core.computation.db.AnalysisReportDto;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+import org.sonar.core.persistence.DbSession;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class AnalysisReportDaoTest extends AbstractDaoTestCase {
+ private AnalysisReportDao dao;
+ private DbSession session;
+ private System2 system2;
+
+ @Before
+ public void before() {
+ this.session = getMyBatis().openSession(false);
+ this.system2 = mock(System2.class);
+ this.dao = new AnalysisReportDao(system2);
+ }
+
+ @Test
+ public void insert() {
+ when(system2.now()).thenReturn(DateUtils.parseDate("2014-09-26").getTime());
+
+ AnalysisReportDto report = new AnalysisReportDto()
+ .setProjectKey("123456789-987654321")
+ .setData("data-project")
+ .setStatus("pending");
+ report.setCreatedAt(DateUtils.parseDate("2014-09-24"))
+ .setUpdatedAt(DateUtils.parseDate("2014-09-25"));
+
+ dao.insert(session, report);
+ session.commit();
+
+ checkTables("insert", new String[]{"id"}, "analysis_reports");
+ }
+}
diff --git a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
index 40a65358922..a3c233cbee3 100644
--- a/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
+++ b/server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
@@ -1,29 +1,10 @@
-<!--
- ~ SonarQube, open source software quality management tool.
- ~ Copyright (C) 2008-2014 SonarSource
- ~ mailto:contact AT sonarsource DOT com
- ~
- ~ SonarQube is free software; you can redistribute it and/or
- ~ modify it under the terms of the GNU Lesser General Public
- ~ License as published by the Free Software Foundation; either
- ~ version 3 of the License, or (at your option) any later version.
- ~
- ~ SonarQube is distributed in the hope that it will be useful,
- ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
- ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- ~ Lesser General Public License for more details.
- ~
- ~ You should have received a copy of the GNU Lesser General Public License
- ~ along with this program; if not, write to the Free Software Foundation,
- ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- -->
-
<dataset>
- <issues
- id="100"
- project_key="sonarqube"
- created_at="2013-05-21"
- updated_at="2013-05-22"
- version="123456789"
+ <analysis_reports
+ id="1"
+ project_key="123456789-987654321"
+ report_data="data-project"
+ report_status="pending"
+ created_at="2014-09-24"
+ updated_at="2014-09-26"
/>
</dataset>
diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb
index dfc20677620..88ed1300a78 100644
--- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb
+++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb
@@ -31,7 +31,6 @@ class CreateAnalysisReports < ActiveRecord::Migration
t.column :created_at, :datetime, :null => false
t.column :updated_at, :datetime, :null => false
end
- add_varchar_index :analysis_reports, 'project_key', :name => 'analysis_reports_project_key', :unique => true
end
end
diff --git a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml
index 8183df183a8..d7b54447271 100644
--- a/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml
+++ b/sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml
@@ -3,8 +3,8 @@
<mapper namespace="org.sonar.core.computation.db.AnalysisReportMapper">
- <insert id="insert" parameterType="AnalysisReport" useGeneratedKeys="true" >
- insert into activities
+ <insert id="insert" parameterType="AnalysisReport" useGeneratedKeys="true">
+ insert into analysis_reports
(project_key, report_status, report_data, created_at, updated_at)
values (#{projectKey}, #{status}, #{data}, #{createdAt}, #{updatedAt})
</insert>
diff --git a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
index 253cdc7a5f0..9b6e2b4b133 100644
--- a/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
+++ b/sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl
@@ -691,5 +691,3 @@ CREATE UNIQUE INDEX "ACTIVE_RULES_UNIQUE" ON "ACTIVE_RULES" ("PROFILE_ID","RULE_
CREATE INDEX "SNAPSHOT_DATA_RESOURCE_IDS" ON "SNAPSHOT_DATA" ("RESOURCE_ID");
CREATE UNIQUE INDEX "PROFILE_UNIQUE_KEY" ON "RULES_PROFILES" ("KEE");
-
-CREATE UNIQUE INDEX "ANALYSIS_REPORTS_PROJECT_KEY" ON "ANALYSIS_REPORTS" ("PROJECT_KEY");