From 48d48e90931782cc1e94768a83ada71275476ceb Mon Sep 17 00:00:00 2001 From: Teryk Bellahsene Date: Thu, 25 Sep 2014 18:11:03 +0200 Subject: [PATCH] SONAR-5624 - test dao --- .../computation/db/AnalysisReportDaoTest.java | 62 +++++++++++++++++++ .../AnalysisReportDaoTest/insert-result.xml | 33 +++------- .../db/migrate/702_create_analysis_reports.rb | 1 - .../computation/db/AnalysisReportMapper.xml | 4 +- .../org/sonar/core/persistence/schema-h2.ddl | 2 - 5 files changed, 71 insertions(+), 31 deletions(-) create mode 100644 server/sonar-server/src/test/java/org/sonar/server/computation/db/AnalysisReportDaoTest.java 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 @@ - - - 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 @@ - - insert into activities + + insert into analysis_reports (project_key, report_status, report_data, created_at, updated_at) values (#{projectKey}, #{status}, #{data}, #{createdAt}, #{updatedAt}) 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"); -- 2.39.5