]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5624 - test dao
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 25 Sep 2014 16:11:03 +0000 (18:11 +0200)
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>
Thu, 25 Sep 2014 16:15:28 +0000 (18:15 +0200)
server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java [new file with mode: 0644]
server/sonar-server/src/test/resources/org/sonar/server/computation/db/AnalysisReportDaoTest/insert-result.xml
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/702_create_analysis_reports.rb
sonar-core/src/main/resources/org/sonar/core/computation/db/AnalysisReportMapper.xml
sonar-core/src/main/resources/org/sonar/core/persistence/schema-h2.ddl

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 (file)
index 0000000..5397b63
--- /dev/null
@@ -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");
+  }
+}
index 40a6535892295312cd942453871cedb62f55e1a7..a3c233cbee39670ffc6cfc0b041f31b3e4c6c0c5 100644 (file)
@@ -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>
index dfc206776204a0b6374e0b32e0a243df1abdb3ea..88ed1300a78bded07c5bf09954537797656df7a3 100644 (file)
@@ -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
index 8183df183a84a44d13f95e85797bd5b3294860c9..d7b54447271fcbcc39835e8ca20ebf9e7588109c 100644 (file)
@@ -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>
index 253cdc7a5f05d290f50f30c69c6399b4264fb42b..9b6e2b4b1338ee9cc3e26a8dff6815d27ef6167b 100644 (file)
@@ -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");