From 28287efade86c3b7ada5d38481c0b6b644fe6c0a Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 11 Jul 2013 09:49:48 +0200 Subject: [PATCH] SONAR-4490 When creating the H2 db, selected issues should be the unresolved ones and not ones with status != CLOSED --- .../persistence/DryRunDatabaseFactory.java | 4 +- .../DryRunDatabaseFactoryTest.java | 12 ++++ .../should_create_database_with_issues.xml | 24 ------- ...create_database_with_unresolved_issues.xml | 69 +++++++++++++++++++ 4 files changed, 83 insertions(+), 26 deletions(-) create mode 100644 sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_unresolved_issues.xml diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java index b6cd161d28f..0111aa19950 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DryRunDatabaseFactory.java @@ -22,12 +22,12 @@ package org.sonar.core.persistence; import com.google.common.io.Files; import org.apache.commons.dbcp.BasicDataSource; import org.sonar.api.ServerComponent; -import org.sonar.api.issue.Issue; import org.sonar.api.platform.ServerFileSystem; import org.sonar.api.utils.SonarException; import javax.annotation.Nullable; import javax.sql.DataSource; + import java.io.File; import java.io.IOException; import java.sql.SQLException; @@ -83,7 +83,7 @@ public class DryRunDatabaseFactory implements ServerComponent { String forRootModule = "(root_component_id in (select id from projects where id=" + projectId + " and qualifier='TRK'))"; String forSubModule = "(component_id in (select id from projects where id=" + projectId + " or root_id=" + projectId + "))"; - template.copyTable(source, dest, "issues", "(" + forRootModule + ") or( " + forSubModule + ")", "status<>'" + Issue.STATUS_CLOSED + "'"); + template.copyTable(source, dest, "issues", "(" + forRootModule + ") or( " + forSubModule + ")", "resolution is null"); } } diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java index 11b35e77c97..3e0e4bc69ff 100644 --- a/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java +++ b/sonar-core/src/test/java/org/sonar/core/persistence/DryRunDatabaseFactoryTest.java @@ -97,6 +97,18 @@ public class DryRunDatabaseFactoryTest extends AbstractDaoTestCase { assertThat(rowCount("issues")).isEqualTo(1); } + @Test + public void should_create_database_with_unresolved_issues() throws IOException, SQLException { + setupData("should_create_database_with_unresolved_issues"); + + when(serverFileSystem.getTempDir()).thenReturn(temporaryFolder.newFolder()); + + byte[] database = localDatabaseFactory.createDatabaseForDryRun(399L); + dataSource = createDatabase(database); + + assertThat(rowCount("issues")).isEqualTo(1); + } + @Test public void should_export_issues_of_project_tree() throws IOException, SQLException { setupData("multi-modules-with-issues"); diff --git a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_issues.xml b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_issues.xml index d25ce652ec8..04e17ab8f0d 100644 --- a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_issues.xml +++ b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_issues.xml @@ -42,28 +42,4 @@ updated_at="[null]" /> - - \ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_unresolved_issues.xml b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_unresolved_issues.xml new file mode 100644 index 00000000000..d25ce652ec8 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/persistence/DryRunDatabaseFactoryTest/should_create_database_with_unresolved_issues.xml @@ -0,0 +1,69 @@ + + \ No newline at end of file -- 2.39.5