diff options
author | Michal Duda <michal.duda@sonarsource.com> | 2020-12-21 17:55:10 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-12-22 20:09:39 +0000 |
commit | 5bfa95f6d5928460f1d8102417d5b6604f96feba (patch) | |
tree | b3bec61cc2bed8fbdbbb31d80385b228686ffa33 /server/sonar-server-common | |
parent | 255d1fb82f78f046ef95f2e7a45cc5d4ba94c97e (diff) | |
download | sonarqube-5bfa95f6d5928460f1d8102417d5b6604f96feba.tar.gz sonarqube-5bfa95f6d5928460f1d8102417d5b6604f96feba.zip |
SONAR-13999 Remove OrganizationDbTester
Diffstat (limited to 'server/sonar-server-common')
7 files changed, 45 insertions, 58 deletions
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java index 30073889618..04595c63b80 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/component/index/ComponentIndexerTest.java @@ -32,7 +32,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentUpdateDto; import org.sonar.db.es.EsQueueDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.server.es.EsClient; import org.sonar.server.es.EsTester; import org.sonar.server.es.IndexingResult; @@ -95,8 +94,7 @@ public class ComponentIndexerTest { @Test public void map_fields() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project = db.components().insertPrivateProject(organization); + ComponentDto project = db.components().insertPrivateProject(); underTest.indexOnStartup(emptySet()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/ProjectIndexersImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/ProjectIndexersImplTest.java index 2d2dc82d710..7f034559d9b 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/ProjectIndexersImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/ProjectIndexersImplTest.java @@ -26,8 +26,6 @@ import org.junit.Test; import org.sonar.db.DbSession; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.ComponentTesting; -import org.sonar.db.organization.OrganizationDto; -import org.sonar.db.organization.OrganizationTesting; import org.sonar.server.es.ProjectIndexer.Cause; import static java.util.Collections.singletonList; @@ -38,8 +36,7 @@ public class ProjectIndexersImplTest { @Test public void commitAndIndex_indexes_project() { - OrganizationDto organization = OrganizationTesting.newOrganizationDto(); - ComponentDto project = ComponentTesting.newPublicProjectDto(organization); + ComponentDto project = ComponentTesting.newPublicProjectDto(); FakeIndexers underTest = new FakeIndexers(); underTest.commitAndIndexComponents(mock(DbSession.class), singletonList(project), Cause.PROJECT_CREATION); @@ -49,8 +46,7 @@ public class ProjectIndexersImplTest { @Test public void commitAndIndex_of_module_indexes_the_project() { - OrganizationDto organization = OrganizationTesting.newOrganizationDto(); - ComponentDto project = ComponentTesting.newPublicProjectDto(organization); + ComponentDto project = ComponentTesting.newPublicProjectDto(); ComponentDto module = ComponentTesting.newModuleDto(project); FakeIndexers underTest = new FakeIndexers(); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java index baf22b047f8..e5c8ff1a338 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/index/IssueIteratorFactoryTest.java @@ -31,7 +31,6 @@ import org.sonar.api.utils.System2; import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.issue.IssueDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import static org.assertj.core.api.Assertions.assertThat; @@ -47,8 +46,7 @@ public class IssueIteratorFactoryTest { @Test public void iterator_over_one_issue() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto file = dbTester.components().insertComponent(newFileDto(project) .setPath("src/main/java/Action.java")); IssueDto expected = dbTester.issues().insert(rule, project, file, @@ -100,8 +98,7 @@ public class IssueIteratorFactoryTest { @Test public void iterator_over_issues() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto directory = dbTester.components().insertComponent(newDirectory(module, "src/main/java")); ComponentDto file = dbTester.components().insertComponent(newFileDto(module, directory) @@ -131,14 +128,13 @@ public class IssueIteratorFactoryTest { @Test public void iterator_over_issue_from_project() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project1 = dbTester.components().insertPrivateProject(organization); + ComponentDto project1 = dbTester.components().insertPrivateProject(); ComponentDto module1 = dbTester.components().insertComponent(newModuleDto(project1)); ComponentDto file1 = dbTester.components().insertComponent(newFileDto(module1)); String[] project1IssueKeys = Stream.of(project1, module1, file1) .map(project1Component -> dbTester.issues().insert(rule, project1, project1Component).getKey()) .toArray(String[]::new); - ComponentDto project2 = dbTester.components().insertPrivateProject(organization); + ComponentDto project2 = dbTester.components().insertPrivateProject(); ComponentDto module2 = dbTester.components().insertComponent(newModuleDto(project2)); ComponentDto file2 = dbTester.components().insertComponent(newFileDto(module2)); String[] project2IssueKeys = Stream.of(project2, module2, file2) @@ -156,8 +152,7 @@ public class IssueIteratorFactoryTest { @Test public void extract_directory_path() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml")); ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(module).setPath("src/main/java/Action.java")); @@ -178,8 +173,7 @@ public class IssueIteratorFactoryTest { @Test public void extract_file_path() { RuleDefinitionDto rule = dbTester.rules().insert(); - OrganizationDto organization = dbTester.organizations().insert(); - ComponentDto project = dbTester.components().insertPrivateProject(organization); + ComponentDto project = dbTester.components().insertPrivateProject(); ComponentDto module = dbTester.components().insertComponent(newModuleDto(project)); ComponentDto fileInRootDir = dbTester.components().insertComponent(newFileDto(module).setPath("pom.xml")); ComponentDto fileInSubDir = dbTester.components().insertComponent(newFileDto(module).setPath("src/main/java/Action.java")); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java index d03deb7c831..83c12e18bbb 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/measure/index/ProjectMeasuresIndexerTest.java @@ -35,7 +35,6 @@ import org.sonar.db.DbTester; import org.sonar.db.component.ComponentDto; import org.sonar.db.component.SnapshotDto; import org.sonar.db.es.EsQueueDto; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.project.ProjectDto; import org.sonar.server.es.EsTester; import org.sonar.server.es.IndexingResult; @@ -98,10 +97,9 @@ public class ProjectMeasuresIndexerTest { @Test public void indexOnStartup_indexes_all_projects() { - OrganizationDto organization = db.organizations().insert(); - SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); - SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); - SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); + SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); + SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); + SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); underTest.indexOnStartup(emptySet()); @@ -111,10 +109,9 @@ public class ProjectMeasuresIndexerTest { @Test public void indexAll_indexes_all_projects() { - OrganizationDto organization = db.organizations().insert(); - SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); - SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); - SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)); + SnapshotDto project1 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); + SnapshotDto project2 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); + SnapshotDto project3 = db.components().insertProjectAndSnapshot(newPrivateProjectDto()); underTest.indexAll(); @@ -146,10 +143,9 @@ public class ProjectMeasuresIndexerTest { @Test public void indexOnStartup_indexes_all_applications() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto application1 = db.components().insertPrivateApplication(organization); - ComponentDto application2 = db.components().insertPrivateApplication(organization); - ComponentDto application3 = db.components().insertPrivateApplication(organization); + ComponentDto application1 = db.components().insertPrivateApplication(); + ComponentDto application2 = db.components().insertPrivateApplication(); + ComponentDto application3 = db.components().insertPrivateApplication(); underTest.indexOnStartup(emptySet()); @@ -159,15 +155,13 @@ public class ProjectMeasuresIndexerTest { @Test public void indexOnStartup_indexes_projects_and_applications() { - OrganizationDto organization = db.organizations().insert(); - ComponentDto project1 = db.components().insertPrivateProject(); ComponentDto project2 = db.components().insertPrivateProject(); ComponentDto project3 = db.components().insertPrivateProject(); - ComponentDto application1 = db.components().insertPrivateApplication(organization); - ComponentDto application2 = db.components().insertPrivateApplication(organization); - ComponentDto application3 = db.components().insertPrivateApplication(organization); + ComponentDto application1 = db.components().insertPrivateApplication(); + ComponentDto application2 = db.components().insertPrivateApplication(); + ComponentDto application3 = db.components().insertPrivateApplication(); underTest.indexOnStartup(emptySet()); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java index d879f705589..f7279a67979 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/organization/DefaultOrganizationProviderImplTest.java @@ -28,17 +28,24 @@ import org.sonar.db.DbSession; import org.sonar.db.DbTester; import org.sonar.db.organization.OrganizationDto; +import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.sonar.db.organization.OrganizationDao.DEFAULT_ORGANIZATION; -import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; +import static org.sonar.db.organization.OrganizationDto.Subscription.FREE; public class DefaultOrganizationProviderImplTest { - private static final OrganizationDto ORGANIZATION_DTO_1 = newOrganizationDto() + private static final OrganizationDto ORGANIZATION_DTO_1 = new OrganizationDto() .setUuid("uuid1") .setName("the name of 1") - .setKey("the key 1"); + .setKey("the key 1") + .setDescription(randomAlphanumeric(256)) + .setAvatarUrl(randomAlphanumeric(256)) + // Default quality gate should be set explicitly when needed in tests + .setDefaultQualityGateUuid("_NOT_SET_") + .setSubscription(FREE) + .setUrl(randomAlphanumeric(256)); private static final long DATE_1 = 1_999_888L; private final System2 system2 = mock(System2.class); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java index 58a0429d748..67fc57965ee 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/rule/index/RuleIndexerTest.java @@ -40,7 +40,6 @@ import org.sonar.api.utils.log.LoggerLevel; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.DbTester; -import org.sonar.db.organization.OrganizationDto; import org.sonar.db.rule.RuleDefinitionDto; import org.sonar.db.rule.RuleDto; import org.sonar.db.rule.RuleDto.Scope; @@ -235,7 +234,6 @@ public class RuleIndexerTest { "bar\n" + "<h2>Recommended Secure Coding Practices</h2>\n" + "foo")); - OrganizationDto organization = dbTester.organizations().insert(); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); assertThat(logTester.getLogs()).hasSize(1); @@ -252,7 +250,6 @@ public class RuleIndexerTest { .setDescription("bar\n" + "<h2>Recommended Secure Coding Practices</h2>\n" + "foo")); - OrganizationDto organization = dbTester.organizations().insert(); underTest.commitAndIndex(dbTester.getSession(), rule.getUuid()); assertThat(logTester.getLogs()).hasSize(1); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java index 2c49c00ba21..a1371bb19a4 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/view/index/ViewIndexerTest.java @@ -20,6 +20,7 @@ package org.sonar.server.view.index; import com.google.common.collect.Maps; +import java.util.Collections; import java.util.List; import java.util.Map; import org.junit.Rule; @@ -52,9 +53,9 @@ public class ViewIndexerTest { @Rule public EsTester es = EsTester.create(); - private DbClient dbClient = db.getDbClient(); - private DbSession dbSession = db.getSession(); - private ViewIndexer underTest = new ViewIndexer(dbClient, es.client()); + private final DbClient dbClient = db.getDbClient(); + private final DbSession dbSession = db.getSession(); + private final ViewIndexer underTest = new ViewIndexer(dbClient, es.client()); @Test public void index_nothing() { @@ -66,19 +67,19 @@ public class ViewIndexerTest { public void index_on_startup() { // simple view ComponentDto project1 = db.components().insertPrivateProject(); - ComponentDto view1 = db.components().insertView(); + ComponentDto view1 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view1, t -> t.setLast(true)); db.components().insertComponent(newProjectCopy(project1, view1)); // view with subview ComponentDto project2 = db.components().insertPrivateProject(); ComponentDto project3 = db.components().insertPrivateProject(); - ComponentDto view2 = db.components().insertView(); + ComponentDto view2 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view2, t -> t.setLast(true)); db.components().insertComponent(newProjectCopy(project2, view2)); ComponentDto subView = db.components().insertComponent(newSubView(view2)); db.components().insertComponent(newProjectCopy(project3, subView)); // view without project - ComponentDto view3 = db.components().insertView(); + ComponentDto view3 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view3, t -> t.setLast(true)); underTest.indexOnStartup(emptySet()); @@ -98,19 +99,19 @@ public class ViewIndexerTest { public void index_root_view() { // simple view ComponentDto project1 = db.components().insertPrivateProject(); - ComponentDto view1 = db.components().insertView(); + ComponentDto view1 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view1, t -> t.setLast(true)); db.components().insertComponent(newProjectCopy(project1, view1)); // view with subview ComponentDto project2 = db.components().insertPrivateProject(); ComponentDto project3 = db.components().insertPrivateProject(); - ComponentDto view2 = db.components().insertView(); + ComponentDto view2 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view2, t -> t.setLast(true)); db.components().insertComponent(newProjectCopy(project2, view2)); ComponentDto subView = db.components().insertComponent(newSubView(view2)); db.components().insertComponent(newProjectCopy(project3, subView)); // view without project - ComponentDto view3 = db.components().insertView(); + ComponentDto view3 = db.components().insertPrivatePortfolio(); db.components().insertSnapshot(view3, t -> t.setLast(true)); underTest.index(view2.uuid()); @@ -138,7 +139,7 @@ public class ViewIndexerTest { @Test public void index_application() { - ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPrivateApplication(); ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy("PC1", project, application)); @@ -153,7 +154,7 @@ public class ViewIndexerTest { @Test public void index_application_on_startup() { - ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPrivateApplication(); ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy("PC1", project, application)); @@ -168,7 +169,7 @@ public class ViewIndexerTest { @Test public void index_application_with_indexAll() { - ComponentDto application = db.components().insertPrivateApplication(db.getDefaultOrganization()); + ComponentDto application = db.components().insertPrivateApplication(); ComponentDto project = db.components().insertPrivateProject(); db.components().insertComponent(newProjectCopy("PC1", project, application)); @@ -208,7 +209,7 @@ public class ViewIndexerTest { @Test public void delete_should_delete_the_view() { - ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(asList("P1")); + ViewDoc view1 = new ViewDoc().setUuid("UUID1").setProjects(Collections.singletonList("P1")); ViewDoc view2 = new ViewDoc().setUuid("UUID2").setProjects(asList("P2", "P3", "P4")); ViewDoc view3 = new ViewDoc().setUuid("UUID3").setProjects(asList("P2", "P3", "P4")); es.putDocuments(TYPE_VIEW, view1); |