aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorMichal Duda <michal.duda@sonarsource.com>2020-12-21 17:55:10 +0100
committersonartech <sonartech@sonarsource.com>2020-12-22 20:09:39 +0000
commit5bfa95f6d5928460f1d8102417d5b6604f96feba (patch)
treeb3bec61cc2bed8fbdbbb31d80385b228686ffa33 /server/sonar-db-dao
parent255d1fb82f78f046ef95f2e7a45cc5d4ba94c97e (diff)
downloadsonarqube-5bfa95f6d5928460f1d8102417d5b6604f96feba.tar.gz
sonarqube-5bfa95f6d5928460f1d8102417d5b6604f96feba.zip
SONAR-13999 Remove OrganizationDbTester
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java15
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java125
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java8
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java31
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java20
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java33
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java24
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java9
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java46
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java17
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java58
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java13
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java28
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java12
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java26
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java10
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java33
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java251
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java49
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java27
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java81
-rw-r--r--server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationTesting.java46
26 files changed, 259 insertions, 723 deletions
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
index faf9cee5e27..b2d0f5e16d2 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeActivityDaoTest.java
@@ -768,17 +768,22 @@ public class CeActivityDaoTest {
insert("TASK_1", REPORT, MAINCOMPONENT_1, SUCCESS);
insert("TASK_2", REPORT, MAINCOMPONENT_1, FAILED);
- ProjectDto projectDto1 = db.components()
- .insertPrivateProjectDto(db.getDefaultOrganization(), branchDto -> branchDto.setNeedIssueSync(false));
+ ProjectDto projectDto1 = db.components().insertPrivateProjectDto(
+ branchDto -> branchDto.setNeedIssueSync(false), c -> {
+ }, p -> {
+ });
insert("TASK_3", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto1.getUuid(), projectDto1.getUuid(), SUCCESS);
- ProjectDto projectDto2 = db.components()
- .insertPrivateProjectDto(db.getDefaultOrganization(), branchDto -> branchDto.setNeedIssueSync(false));
+ ProjectDto projectDto2 = db.components().insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(false), c -> {
+ }, p -> {
+ });
insert("TASK_4", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto2.getUuid(), projectDto2.getUuid(), SUCCESS);
assertThat(underTest.hasAnyFailedIssueSyncTask(db.getSession())).isFalse();
- ProjectDto projectDto3 = db.components().insertPrivateProjectDto(db.getDefaultOrganization(), branchDto -> branchDto.setNeedIssueSync(false));
+ ProjectDto projectDto3 = db.components().insertPrivateProjectDto(branchDto -> branchDto.setNeedIssueSync(false), c -> {
+ }, p -> {
+ });
insert("TASK_5", CeTaskTypes.BRANCH_ISSUE_SYNC, projectDto3.getUuid(), projectDto3.getUuid(), SUCCESS);
BranchDto projectBranch = db.components()
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index 9e07a000cf4..5f39008bf3d 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -50,7 +50,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.RowNotFoundException;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.source.FileSourceDto;
import static com.google.common.collect.ImmutableSet.of;
@@ -96,14 +95,14 @@ public class ComponentDaoTest {
private static final String A_VIEW_UUID = "view-uuid";
private static final ComponentQuery ALL_PROJECTS_COMPONENT_QUERY = ComponentQuery.builder().setQualifiers("TRK").build();
- private System2 system2 = new AlwaysIncreasingSystem2(1000L);
+ private final System2 system2 = new AlwaysIncreasingSystem2(1000L);
@Rule
public DbTester db = DbTester.create(system2);
- private Random random = new Random();
- private DbSession dbSession = db.getSession();
- private ComponentDao underTest = new ComponentDao();
+ private final Random random = new Random();
+ private final DbSession dbSession = db.getSession();
+ private final ComponentDao underTest = new ComponentDao();
private static ComponentTreeQuery.Builder newTreeQuery(String baseUuid) {
return ComponentTreeQuery.builder()
@@ -113,16 +112,15 @@ public class ComponentDaoTest {
@Test
public void get_by_uuid() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization, p -> p
+ ComponentDto project = db.components().insertPrivateProject(p -> p
.setDbKey("org.struts:struts")
.setName("Struts")
.setLongName("Apache Struts"));
- ComponentDto anotherProject = db.components().insertPrivateProject(organization);
+ ComponentDto anotherProject = db.components().insertPrivateProject();
ComponentDto result = underTest.selectByUuid(dbSession, project.uuid()).get();
assertThat(result).isNotNull();
- assertThat(result.getOrganizationUuid()).isEqualTo(organization.getUuid());
+ assertThat(result.getOrganizationUuid()).isEqualTo(db.getDefaultOrganization().getUuid());
assertThat(result.uuid()).isEqualTo(project.uuid());
assertThat(result.getUuidPath()).isEqualTo(".");
assertThat(result.moduleUuid()).isNull();
@@ -143,7 +141,7 @@ public class ComponentDaoTest {
@Test
public void get_by_uuid_on_technical_project_copy() {
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPublicPortfolio();
ComponentDto project = db.components().insertPublicProject(p -> p
.setDbKey("org.struts:struts")
.setName("Struts")
@@ -188,8 +186,7 @@ public class ComponentDaoTest {
@Test
public void selectByKey() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto directory = db.components().insertComponent(newDirectory(project, "src"));
ComponentDto file = db.components().insertComponent(newFileDto(project, directory)
.setDbKey("org.struts:struts-core:src/org/struts/RequestContext.java")
@@ -201,7 +198,7 @@ public class ComponentDaoTest {
Optional<ComponentDto> optional = underTest.selectByKey(dbSession, file.getDbKey());
ComponentDto result = optional.get();
- assertThat(result.getOrganizationUuid()).isEqualTo(organization.getUuid());
+ assertThat(result.getOrganizationUuid()).isEqualTo(db.getDefaultOrganization().getUuid());
assertThat(result.uuid()).isEqualTo(file.uuid());
assertThat(result.getDbKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
assertThat(result.path()).isEqualTo("src/RequestContext.java");
@@ -683,12 +680,14 @@ public class ComponentDaoTest {
@Test
public void select_views_and_sub_views_and_applications() {
- OrganizationDto organization = db.organizations().insert();
- db.components().insertView(organization, "ABCD");
- db.components().insertView(organization, "IJKL");
- ComponentDto view = db.components().insertView(organization, "EFGH");
+ db.components().insertPublicPortfolio("ABCD", p -> {
+ });
+ db.components().insertPublicPortfolio("IJKL", p -> {
+ });
+ ComponentDto view = db.components().insertPublicPortfolio("EFGH", p -> {
+ });
db.components().insertSubView(view, dto -> dto.setUuid("FGHI"));
- ComponentDto application = db.components().insertPublicApplication(organization);
+ ComponentDto application = db.components().insertPublicApplication();
assertThat(underTest.selectAllViewsAndSubViews(dbSession)).extracting(UuidWithProjectUuidDto::getUuid)
.containsExactlyInAnyOrder("ABCD", "EFGH", "FGHI", "IJKL", application.uuid());
@@ -981,7 +980,7 @@ public class ComponentDaoTest {
db.components().insertComponent(newProjectCopy(project2, viewWithSubView));
ComponentDto subView = db.components().insertSubView(viewWithSubView);
db.components().insertComponent(newProjectCopy(project1, subView));
- ComponentDto viewWithoutProject = db.components().insertView();
+ ComponentDto viewWithoutProject = db.components().insertPrivatePortfolio();
assertThat(underTest.selectProjectsFromView(dbSession, view.uuid(), view.uuid())).containsExactlyInAnyOrder(project1.uuid());
assertThat(underTest.selectProjectsFromView(dbSession, viewWithSubView.uuid(), viewWithSubView.uuid())).containsExactlyInAnyOrder(project1.uuid(), project2.uuid());
@@ -993,7 +992,7 @@ public class ComponentDaoTest {
@Test
public void select_projects() {
ComponentDto provisionedProject = db.components().insertPrivateProject();
- ComponentDto provisionedView = db.components().insertView();
+ ComponentDto provisionedView = db.components().insertPrivatePortfolio();
String projectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto()).getComponentUuid();
String disabledProjectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto().setEnabled(false)).getComponentUuid();
String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView()).getComponentUuid();
@@ -1186,9 +1185,8 @@ public class ComponentDaoTest {
}
private ListAssert<String> assertSelectForIndexing(@Nullable String projectUuid) {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization, "U1");
- ComponentDto removedProject = db.components().insertPrivateProject(organization, p -> p.setEnabled(false));
+ ComponentDto project = db.components().insertPrivateProject("U1");
+ ComponentDto removedProject = db.components().insertPrivateProject(p -> p.setEnabled(false));
ComponentDto module = db.components().insertComponent(newModuleDto("U2", project));
ComponentDto removedModule = db.components().insertComponent(newModuleDto(project).setEnabled(false));
ComponentDto directory = db.components().insertComponent(newDirectory(module, "U3", "src"));
@@ -1196,10 +1194,11 @@ public class ComponentDaoTest {
ComponentDto file = db.components().insertComponent(newFileDto(module, directory, "U4"));
ComponentDto removedFile = db.components().insertComponent(newFileDto(module, directory).setEnabled(false));
- ComponentDto view = db.components().insertView(organization, "VW1");
+ ComponentDto view = db.components().insertPublicPortfolio("VW1", p -> {
+ });
db.components().insertComponent(newProjectCopy("COPY8", project, view));
- ComponentDto project2 = db.components().insertPrivateProject(organization, "U5");
+ ComponentDto project2 = db.components().insertPrivateProject("U5");
ComponentDto moduleOnProject2 = db.components().insertComponent(newModuleDto("U6", project2));
List<ComponentDto> components = new ArrayList<>();
@@ -1210,7 +1209,7 @@ public class ComponentDaoTest {
@Test
public void update() {
- db.components().insertPrivateProject(db.getDefaultOrganization(), "U1");
+ db.components().insertPrivateProject("U1");
underTest.update(dbSession, new ComponentUpdateDto()
.setUuid("U1")
@@ -1300,8 +1299,8 @@ public class ComponentDaoTest {
@Test
public void delete() {
- ComponentDto project1 = db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setDbKey("PROJECT_1"));
- db.components().insertPrivateProject(db.getDefaultOrganization(), (t) -> t.setDbKey("PROJECT_2"));
+ ComponentDto project1 = db.components().insertPrivateProject(t -> t.setDbKey("PROJECT_1"));
+ db.components().insertPrivateProject(t -> t.setDbKey("PROJECT_2"));
underTest.delete(dbSession, project1.uuid());
dbSession.commit();
@@ -1373,7 +1372,7 @@ public class ComponentDaoTest {
@Test
public void selectByQuery_name_with_special_characters() {
- db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization()).setName("project-\\_%/-name"));
+ db.components().insertProjectAndSnapshot(newPrivateProjectDto().setName("project-\\_%/-name"));
ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("-\\_%/-").setQualifiers(PROJECT).build();
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
@@ -1384,8 +1383,8 @@ public class ComponentDaoTest {
@Test
public void selectByQuery_key_with_special_characters() {
- db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert()).setDbKey("project-_%-key"));
- db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert()).setDbKey("project-key-that-does-not-match"));
+ db.components().insertProjectAndSnapshot(newPrivateProjectDto().setDbKey("project-_%-key"));
+ db.components().insertProjectAndSnapshot(newPrivateProjectDto().setDbKey("project-key-that-does-not-match"));
ComponentQuery query = ComponentQuery.builder().setNameOrKeyQuery("project-_%-key").setQualifiers(PROJECT).build();
List<ComponentDto> result = underTest.selectByQuery(dbSession, query, 0, 10);
@@ -1396,7 +1395,7 @@ public class ComponentDaoTest {
@Test
public void selectByQuery_on_key_partial_match_case_insensitive() {
- db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.organizations().insert()).setDbKey("project-key"));
+ db.components().insertProjectAndSnapshot(newPrivateProjectDto().setDbKey("project-key"));
ComponentQuery query = ComponentQuery.builder()
.setNameOrKeyQuery("JECT-K")
@@ -1505,8 +1504,8 @@ public class ComponentDaoTest {
@Test
public void selectByQuery_filter_on_visibility() {
- db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization()).setDbKey("private-key"));
- db.components().insertComponent(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()).setDbKey("public-key"));
+ db.components().insertComponent(newPrivateProjectDto().setDbKey("private-key"));
+ db.components().insertComponent(ComponentTesting.newPublicProjectDto().setDbKey("public-key"));
ComponentQuery privateProjectsQuery = ComponentQuery.builder().setPrivate(true).setQualifiers(PROJECT).build();
ComponentQuery publicProjectsQuery = ComponentQuery.builder().setPrivate(false).setQualifiers(PROJECT).build();
@@ -1531,10 +1530,9 @@ public class ComponentDaoTest {
@Test
public void selectByQuery_on_component_keys() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto sonarqube = db.components().insertComponent(newPrivateProjectDto(organizationDto));
- ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto(organizationDto));
- ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto(organizationDto));
+ ComponentDto sonarqube = db.components().insertComponent(newPrivateProjectDto());
+ ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto());
+ ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto());
ComponentQuery query = ComponentQuery.builder().setQualifiers(PROJECT)
.setComponentKeys(newHashSet(sonarqube.getDbKey(), jdk8.getDbKey())).build();
@@ -1559,10 +1557,9 @@ public class ComponentDaoTest {
@Test
public void selectByQuery_on_component_uuids() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto sonarqube = db.components().insertComponent(newPrivateProjectDto(organizationDto));
- ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto(organizationDto));
- ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto(organizationDto));
+ ComponentDto sonarqube = db.components().insertComponent(newPrivateProjectDto());
+ ComponentDto jdk8 = db.components().insertComponent(newPrivateProjectDto());
+ ComponentDto cLang = db.components().insertComponent(newPrivateProjectDto());
ComponentQuery query = ComponentQuery.builder().setQualifiers(PROJECT)
.setComponentUuids(newHashSet(sonarqube.uuid(), jdk8.uuid())).build();
@@ -1575,10 +1572,8 @@ public class ComponentDaoTest {
@Test
public void selectAncestors() {
- // organization
- OrganizationDto organization = db.organizations().insert();
// project -> module -> file
- ComponentDto project = newPrivateProjectDto(organization, PROJECT_UUID);
+ ComponentDto project = newPrivateProjectDto(PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
ComponentDto module = newModuleDto(MODULE_UUID, project);
db.components().insertComponent(module);
@@ -1602,7 +1597,7 @@ public class ComponentDaoTest {
@Test
public void select_descendants_with_children_strategy() {
// project has 2 children: module and file 1. Other files are part of module.
- ComponentDto project = newPrivateProjectDto(db.organizations().insert(), PROJECT_UUID);
+ ComponentDto project = newPrivateProjectDto(PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
ComponentDto module = newModuleDto(MODULE_UUID, project);
db.components().insertComponent(module);
@@ -1677,7 +1672,7 @@ public class ComponentDaoTest {
@Test
public void select_descendants_with_leaves_strategy() {
- ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization(), PROJECT_UUID);
+ ComponentDto project = newPrivateProjectDto(PROJECT_UUID);
db.components().insertProjectAndSnapshot(project);
db.components().insertComponent(newModuleDto("module-1-uuid", project));
db.components().insertComponent(newFileDto(project, null, "file-1-uuid"));
@@ -1700,21 +1695,20 @@ public class ComponentDaoTest {
@Test
public void select_descendants_of_a_view_and_filter_by_name() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto view = newView(organizationDto, A_VIEW_UUID);
+ ComponentDto view = newView(A_VIEW_UUID);
db.components().insertViewAndSnapshot(view);
// one subview
ComponentDto subView = newSubView(view, "subview-uuid", "subview-key").setName("subview name");
db.components().insertComponent(subView);
// one project and its copy linked to the view
- ComponentDto project = newPrivateProjectDto(organizationDto, PROJECT_UUID).setName("project name");
+ ComponentDto project = newPrivateProjectDto(PROJECT_UUID).setName("project name");
db.components().insertProjectAndSnapshot(project);
db.components().insertComponent(newProjectCopy("project-copy-uuid", project, view));
ComponentTreeQuery dbQuery = newTreeQuery(A_VIEW_UUID).setNameOrKeyQuery("name").setStrategy(CHILDREN).build();
List<ComponentDto> components = underTest.selectDescendants(dbSession, dbQuery);
assertThat(components).extracting("uuid").containsOnly("project-copy-uuid", "subview-uuid");
- assertThat(components).extracting("organizationUuid").containsOnly(organizationDto.getUuid());
+ assertThat(components).extracting("organizationUuid").containsOnly(db.getDefaultOrganization().getUuid());
}
@Test
@@ -1722,13 +1716,12 @@ public class ComponentDaoTest {
String uuid1 = "uuid1";
String uuid2 = "uuid2";
- OrganizationDto organizationDto = db.organizations().insert();
String[] uuids = {
- db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(true)).uuid(),
- db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid1).setPrivate(false)).uuid(),
- db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(true)).uuid(),
- db.components().insertComponent(newPrivateProjectDto(organizationDto).setProjectUuid(uuid2).setPrivate(false)).uuid(),
- db.components().insertComponent(newPrivateProjectDto(organizationDto).setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(),
+ db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid1).setPrivate(true)).uuid(),
+ db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid1).setPrivate(false)).uuid(),
+ db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid2).setPrivate(true)).uuid(),
+ db.components().insertComponent(newPrivateProjectDto().setProjectUuid(uuid2).setPrivate(false)).uuid(),
+ db.components().insertComponent(newPrivateProjectDto().setRootUuid(uuid1).setProjectUuid("foo").setPrivate(false)).uuid(),
};
underTest.setPrivateForRootComponentUuid(db.getSession(), uuid1, true);
@@ -1767,25 +1760,21 @@ public class ComponentDaoTest {
@Test
public void selectPrivateProjectsWithNcloc() {
MetricDto metric = db.measures().insertMetric(m -> m.setKey("ncloc"));
- OrganizationDto organizationDto = db.organizations().insert();
// project1, not the biggest branch - not returned
- final ComponentDto project1 = db.components().insertPrivateProject(organizationDto, b -> b.setName("foo"));
+ final ComponentDto project1 = db.components().insertPrivateProject(b -> b.setName("foo"));
insertMeasure(20d, project1, metric);
// branch of project1 - returned
insertMeasure(30d, db.components().insertProjectBranch(project1, b -> b.setBranchType(BRANCH)), metric);
// project2 - returned
- insertMeasure(10d, db.components().insertPrivateProject(organizationDto, b -> b.setName("bar")), metric);
+ insertMeasure(10d, db.components().insertPrivateProject(b -> b.setName("bar")), metric);
// public project - not returned
- insertMeasure(11d, db.components().insertPublicProject(organizationDto, b -> b.setPrivate(false)), metric);
-
- // different org - not returned
- insertMeasure(12d, db.components().insertPrivateProject(db.organizations().insert()), metric);
+ insertMeasure(11d, db.components().insertPublicProject(b -> b.setName("other")), metric);
- List<ProjectNclocDistributionDto> result = underTest.selectPrivateProjectsWithNcloc(db.getSession(), organizationDto.getUuid());
+ List<ProjectNclocDistributionDto> result = underTest.selectPrivateProjectsWithNcloc(db.getSession(), db.getDefaultOrganization().getUuid());
assertThat(result).extracting(ProjectNclocDistributionDto::getName).containsExactly("foo", "bar");
assertThat(result).extracting(ProjectNclocDistributionDto::getNcloc).containsExactly(30L, 10L);
@@ -1793,12 +1782,12 @@ public class ComponentDaoTest {
@Test
public void existAnyOfComponentsWithQualifiers() {
- ComponentDto projectDto = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization()));
+ ComponentDto projectDto = db.components().insertComponent(newPrivateProjectDto());
- ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization()));
+ ComponentDto view = db.components().insertComponent(newView());
ComponentDto subview = db.components().insertComponent(newSubView(view));
- ComponentDto app = db.components().insertComponent(newApplication(db.getDefaultOrganization()));
+ ComponentDto app = db.components().insertComponent(newApplication());
assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), emptyList(), newHashSet(APP, VIEW, SUBVIEW))).isFalse();
assertThat(underTest.existAnyOfComponentsWithQualifiers(db.getSession(), singletonList("not-existing-component"), newHashSet(APP, VIEW, SUBVIEW))).isFalse();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java
index 0271571a08f..b9654462500 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDtoTest.java
@@ -22,10 +22,8 @@ package org.sonar.db.component;
import org.junit.Test;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.resources.Scopes;
-import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
public class ComponentDtoTest {
@@ -87,15 +85,13 @@ public class ComponentDtoTest {
@Test
public void formatUuidPathFromParent() {
- ComponentDto parent = ComponentTesting.newPrivateProjectDto(newOrganizationDto(), "123").setUuidPath(ComponentDto.UUID_PATH_OF_ROOT);
+ ComponentDto parent = ComponentTesting.newPrivateProjectDto("123").setUuidPath(ComponentDto.UUID_PATH_OF_ROOT);
assertThat(ComponentDto.formatUuidPathFromParent(parent)).isEqualTo(".123.");
}
@Test
public void getUuidPathLikeIncludingSelf() {
- OrganizationDto organizationDto = newOrganizationDto();
-
- ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto).setUuidPath(ComponentDto.UUID_PATH_OF_ROOT);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto().setUuidPath(ComponentDto.UUID_PATH_OF_ROOT);
assertThat(project.getUuidPathLikeIncludingSelf()).isEqualTo("." + project.uuid() + ".%");
ComponentDto module = ComponentTesting.newModuleDto(project);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java
index c9491da15c3..bc768f8a133 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java
@@ -34,7 +34,6 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentKeyUpdaterDao.RekeyedResource;
-import org.sonar.db.organization.OrganizationDto;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
@@ -81,9 +80,8 @@ public class ComponentKeyUpdaterDaoTest {
@Test
public void updateKey_updates_disabled_components() {
- OrganizationDto organizationDto = db.organizations().insert();
ComponentDto project = db.components().insertComponent(
- newPrivateProjectDto(organizationDto, "A")
+ newPrivateProjectDto("A")
.setDbKey("my_project"));
ComponentDto directory = db.components().insertComponent(
newDirectory(project, "B")
@@ -133,7 +131,7 @@ public class ComponentKeyUpdaterDaoTest {
}
@Test
- public void update_application_branch_key_will_fail_if_newKey_exist(){
+ public void update_application_branch_key_will_fail_if_newKey_exist() {
ComponentDto app = db.components().insertPublicProject();
ComponentDto appBranch = db.components().insertProjectBranch(app);
db.components().insertProjectBranch(app, b -> b.setKey("newName"));
@@ -368,15 +366,14 @@ public class ComponentKeyUpdaterDaoTest {
@Test
public void shouldNotUpdateAllSubmodules() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization, t1 -> t1.setDbKey("org.struts:struts").setUuid("A"));
+ ComponentDto project1 = db.components().insertPrivateProject(t1 -> t1.setDbKey("org.struts:struts").setUuid("A"));
ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setDbKey("org.struts:struts-core").setUuid("B"));
ComponentDto directory1 = db.components().insertComponent(newDirectory(module1, "/src/org/struts").setUuid("C"));
db.components().insertComponent(ComponentTesting.newFileDto(module1, directory1).setDbKey("org.struts:struts-core:/src/org/struts/RequestContext.java").setUuid("D"));
ComponentDto module2 = db.components().insertComponent(newModuleDto(project1).setDbKey("foo:struts-ui").setUuid("E"));
ComponentDto directory2 = db.components().insertComponent(newDirectory(module2, "/src/org/struts").setUuid("F"));
db.components().insertComponent(ComponentTesting.newFileDto(module2, directory2).setDbKey("foo:struts-ui:/src/org/struts/RequestContext.java").setUuid("G"));
- ComponentDto project2 = db.components().insertPublicProject(organization, t1 -> t1.setDbKey("foo:struts-core").setUuid("H"));
+ ComponentDto project2 = db.components().insertPublicProject(t1 -> t1.setDbKey("foo:struts-core").setUuid("H"));
underTest.bulkUpdateKey(dbSession, "A", "org.struts", "org.apache.struts", doNotReturnAnyRekeyedResource());
dbSession.commit();
@@ -396,8 +393,7 @@ public class ComponentKeyUpdaterDaoTest {
@Test
public void updateKey_throws_IAE_when_sub_component_key_is_too_long() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = newPrivateProjectDto(organizationDto, "project-uuid").setDbKey("old-project-key");
+ ComponentDto project = newPrivateProjectDto("project-uuid").setDbKey("old-project-key");
db.components().insertComponent(project);
db.components().insertComponent(newFileDto(project, null).setDbKey("old-project-key:file"));
String newLongProjectKey = Strings.repeat("a", 400);
@@ -430,9 +426,8 @@ public class ComponentKeyUpdaterDaoTest {
@Test
public void check_component_keys_checks_inactive_components() {
- OrganizationDto organizationDto = db.organizations().insert();
- db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("my-project"));
- db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey("your-project").setEnabled(false));
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey("my-project"));
+ db.components().insertComponent(ComponentTesting.newPrivateProjectDto().setDbKey("your-project").setEnabled(false));
Map<String, Boolean> result = underTest.checkComponentKeys(dbSession, newArrayList("my-project", "your-project", "new-project"));
@@ -454,10 +449,10 @@ public class ComponentKeyUpdaterDaoTest {
@Test
public void simulate_bulk_update_key_does_not_return_disable_components() {
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "A").setDbKey("project"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto("A").setDbKey("project"));
db.components().insertComponent(newModuleDto(project).setDbKey("project:enabled-module"));
db.components().insertComponent(newModuleDto(project).setDbKey("project:disabled-module").setEnabled(false));
- db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "D").setDbKey("other-project"));
+ db.components().insertComponent(newPrivateProjectDto("D").setDbKey("other-project"));
Map<String, String> result = underTest.simulateBulkUpdateKey(dbSession, "A", "project", "new-project");
@@ -468,8 +463,7 @@ public class ComponentKeyUpdaterDaoTest {
@Test
public void simulate_bulk_update_key_fails_if_invalid_componentKey() {
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organizationDto, "A").setDbKey("project"));
+ ComponentDto project = db.components().insertComponent(newPrivateProjectDto("A").setDbKey("project"));
db.components().insertComponent(newModuleDto(project).setDbKey("project:enabled-module"));
db.components().insertComponent(newModuleDto(project).setDbKey("project:disabled-module").setEnabled(false));
@@ -489,14 +483,13 @@ public class ComponentKeyUpdaterDaoTest {
}
private void populateSomeData() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization, t -> t.setDbKey("org.struts:struts").setUuid("A"));
+ ComponentDto project1 = db.components().insertPrivateProject(t -> t.setDbKey("org.struts:struts").setUuid("A"));
ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setDbKey("org.struts:struts-core").setUuid("B"));
ComponentDto directory1 = db.components().insertComponent(newDirectory(module1, "/src/org/struts").setUuid("C"));
db.components().insertComponent(ComponentTesting.newFileDto(module1, directory1).setDbKey("org.struts:struts-core:/src/org/struts/RequestContext.java").setUuid("D"));
ComponentDto module2 = db.components().insertComponent(newModuleDto(project1).setDbKey("org.struts:struts-ui").setUuid("E"));
ComponentDto directory2 = db.components().insertComponent(newDirectory(module2, "/src/org/struts").setUuid("F"));
db.components().insertComponent(ComponentTesting.newFileDto(module2, directory2).setDbKey("org.struts:struts-ui:/src/org/struts/RequestContext.java").setUuid("G"));
- ComponentDto project2 = db.components().insertPublicProject(organization, t -> t.setDbKey("foo:struts-core").setUuid("H"));
+ ComponentDto project2 = db.components().insertPublicProject(t -> t.setDbKey("foo:struts-core").setUuid("H"));
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java
index 255225f2b45..8d2d7051072 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentTreeQueryTest.java
@@ -28,7 +28,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.CHILDREN;
import static org.sonar.db.component.ComponentTreeQuery.Strategy.LEAVES;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
public class ComponentTreeQueryTest {
@@ -70,10 +69,10 @@ public class ComponentTreeQueryTest {
@Test
public void test_getUuidPath() {
assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(CHILDREN)
- .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID.");
+ .build().getUuidPath(newPrivateProjectDto("PROJECT_UUID"))).isEqualTo(".PROJECT_UUID.");
assertThat(ComponentTreeQuery.builder().setBaseUuid(BASE_UUID).setStrategy(LEAVES)
- .build().getUuidPath(newPrivateProjectDto(newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%");
+ .build().getUuidPath(newPrivateProjectDto("PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%");
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
index da73a802f49..4bfd2efb7c6 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
@@ -43,7 +43,6 @@ import org.sonar.db.DbTester;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeQueueDto;
import org.sonar.db.ce.CeTaskTypes;
-import org.sonar.db.organization.OrganizationTesting;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.emptyList;
@@ -70,10 +69,9 @@ public class SnapshotDaoTest {
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- private DbClient dbClient = db.getDbClient();
- private DbSession dbSession = db.getSession();
-
- private SnapshotDao underTest = dbClient.snapshotDao();
+ private final DbClient dbClient = db.getDbClient();
+ private final DbSession dbSession = db.getSession();
+ private final SnapshotDao underTest = dbClient.snapshotDao();
@Test
public void test_selectByUuid() {
@@ -155,12 +153,12 @@ public class SnapshotDaoTest {
@Test
public void selectLastSnapshotsByRootComponentUuids_returns_snapshots_flagged_as_last() {
- ComponentDto firstProject = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_1"));
+ ComponentDto firstProject = db.components().insertComponent(newPrivateProjectDto("PROJECT_UUID_1"));
dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(false));
SnapshotDto lastSnapshotOfFirstProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(firstProject).setLast(true));
- ComponentDto secondProject = db.components().insertComponent(newPrivateProjectDto(db.getDefaultOrganization(), "PROJECT_UUID_2"));
+ ComponentDto secondProject = db.components().insertComponent(newPrivateProjectDto("PROJECT_UUID_2"));
SnapshotDto lastSnapshotOfSecondProject = dbClient.snapshotDao().insert(dbSession, newAnalysis(secondProject).setLast(true));
- db.components().insertProjectAndSnapshot(newPrivateProjectDto(db.getDefaultOrganization()));
+ db.components().insertProjectAndSnapshot(newPrivateProjectDto());
List<SnapshotDto> result = underTest.selectLastAnalysesByRootComponentUuids(dbSession, newArrayList(firstProject.uuid(), secondProject.uuid()));
@@ -259,9 +257,7 @@ public class SnapshotDaoTest {
@Test
public void select_first_snapshots() {
- ComponentDto project = newPrivateProjectDto(db.getDefaultOrganization());
- db.getDbClient().componentDao().insert(dbSession, project);
-
+ ComponentDto project = db.components().insertPrivateProject();
db.getDbClient().snapshotDao().insert(dbSession,
newAnalysis(project).setCreatedAt(5L),
newAnalysis(project).setCreatedAt(2L),
@@ -493,7 +489,7 @@ public class SnapshotDaoTest {
}
private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) {
- SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid))
+ SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(projectUuid))
.setLast(isLastFlag)
.setStatus(status)
.setUuid(uuid);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java
index e92978a03a2..0c0214f9abc 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/duplication/DuplicationDaoTest.java
@@ -34,7 +34,6 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.organization.OrganizationDto;
import static com.google.common.collect.ImmutableList.of;
import static java.util.Collections.singletonList;
@@ -46,14 +45,12 @@ public class DuplicationDaoTest {
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- private DbSession dbSession = db.getSession();
-
- private DuplicationDao dao = db.getDbClient().duplicationDao();
+ private final DbSession dbSession = db.getSession();
+ private final DuplicationDao dao = db.getDbClient().duplicationDao();
@Test
public void selectCandidates_returns_block_from_last_snapshot_only_of_component_with_language_and_if_not_specified_analysis() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization);
+ ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto fooFile = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("foo").setEnabled(true));
ComponentDto fooFile1 = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("foo").setEnabled(true));
ComponentDto disabledFooFile = db.components().insertComponent(ComponentTesting.newFileDto(project1).setLanguage("foo").setEnabled(false));
@@ -74,12 +71,10 @@ public class DuplicationDaoTest {
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "foo", singletonList(hash)))
.containsOnly(
tuple(fooFile.uuid(), fooFile.getKey(), lastAnalysis.getUuid(), hash),
- tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), hash)
- );
+ tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), hash));
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "bar", singletonList(hash)))
.containsOnly(
- tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), hash)
- );
+ tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), hash));
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "donut", singletonList(hash)))
.isEmpty();
}
@@ -89,13 +84,11 @@ public class DuplicationDaoTest {
tuple(fooFile.uuid(), fooFile.getKey(), lastAnalysis.getUuid(), "aa"),
tuple(fooFile.uuid(), fooFile.getKey(), lastAnalysis.getUuid(), "bb"),
tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), "aa"),
- tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), "bb")
- );
+ tuple(fooFile1.uuid(), fooFile1.getKey(), lastAnalysis.getUuid(), "bb"));
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "bar", hashes))
.containsOnly(
tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), "aa"),
- tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), "bb")
- );
+ tuple(barFile.uuid(), barFile.getKey(), lastAnalysis.getUuid(), "bb"));
assertThat(dao.selectCandidates(dbSession, newAnalysis.getUuid(), "donut", hashes))
.isEmpty();
}
@@ -116,14 +109,13 @@ public class DuplicationDaoTest {
@Test
public void select_component() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization);
+ ComponentDto project1 = db.components().insertPrivateProject();
SnapshotDto analysis1 = db.components().insertSnapshot(project1);
- ComponentDto project2 = db.components().insertPrivateProject(organization);
+ ComponentDto project2 = db.components().insertPrivateProject();
SnapshotDto analysis2 = db.components().insertSnapshot(project2);
- ComponentDto project3 = db.components().insertPrivateProject(organization);
+ ComponentDto project3 = db.components().insertPrivateProject();
SnapshotDto analysis3 = db.components().insertSnapshot(project3);
- ComponentDto project4 = db.components().insertPrivateProject(organization);
+ ComponentDto project4 = db.components().insertPrivateProject();
insert(project1, analysis1, "bb", 0, 0, 0);
insert(project2, analysis2, "aa", 0, 1, 2);
insert(project3, analysis3, "bb", 0, 0, 0);
@@ -146,8 +138,7 @@ public class DuplicationDaoTest {
@Test
public void insert() {
- OrganizationDto organization = db.organizations().insert();
- ComponentDto project = newPrivateProjectDto(organization);
+ ComponentDto project = newPrivateProjectDto();
SnapshotDto analysis = db.components().insertProjectAndSnapshot(project);
insert(project, analysis, "bb", 0, 1, 2);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java
index 75856b03d47..b2d8a234682 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/event/EventDaoTest.java
@@ -33,7 +33,6 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotDto;
-import org.sonar.db.organization.OrganizationDto;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.stream.Collectors.toList;
@@ -48,14 +47,13 @@ public class EventDaoTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private DbClient dbClient = dbTester.getDbClient();
- private DbSession dbSession = dbTester.getSession();
-
- private EventDao underTest = dbTester.getDbClient().eventDao();
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final DbSession dbSession = dbTester.getSession();
+ private final EventDao underTest = dbTester.getDbClient().eventDao();
@Test
public void select_by_uuid() {
- SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
+ SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto());
dbTester.events().insertEvent(newEvent(analysis).setUuid("A1"));
dbTester.events().insertEvent(newEvent(analysis).setUuid("A2"));
dbTester.events().insertEvent(newEvent(analysis).setUuid("A3"));
@@ -68,9 +66,8 @@ public class EventDaoTest {
@Test
public void select_by_component_uuid() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project1 = ComponentTesting.newPrivateProjectDto(organization);
- ComponentDto project2 = ComponentTesting.newPrivateProjectDto(organization);
+ ComponentDto project1 = ComponentTesting.newPrivateProjectDto();
+ ComponentDto project2 = ComponentTesting.newPrivateProjectDto();
SnapshotDto analysis1 = dbTester.components().insertProjectAndSnapshot(project1);
SnapshotDto analysis2 = dbTester.components().insertProjectAndSnapshot(project2);
String[] eventUuids1 = IntStream.range(0, 1 + new Random().nextInt(10))
@@ -112,7 +109,7 @@ public class EventDaoTest {
@Test
public void select_by_analysis_uuid() {
- ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto project = ComponentTesting.newPrivateProjectDto();
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
SnapshotDto otherAnalysis = dbClient.snapshotDao().insert(dbSession, newAnalysis(project));
dbTester.commit();
@@ -154,8 +151,7 @@ public class EventDaoTest {
@Test
public void return_different_categories() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = ComponentTesting.newPrivateProjectDto(organization);
+ ComponentDto project = ComponentTesting.newPrivateProjectDto();
SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(project);
List<EventDto> events = IntStream.range(0, 1 + new Random().nextInt(10))
.mapToObj(i -> dbTester.events().insertEvent(newEvent(analysis).setCategory("cat_" + i)))
@@ -197,7 +193,7 @@ public class EventDaoTest {
@Test
public void update_name_and_description() {
- SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
+ SnapshotDto analysis = dbTester.components().insertProjectAndSnapshot(ComponentTesting.newPrivateProjectDto());
dbTester.events().insertEvent(newEvent(analysis).setUuid("E1"));
underTest.update(dbSession, "E1", "New Name", "New Description");
@@ -209,7 +205,7 @@ public class EventDaoTest {
@Test
public void delete_by_uuid() {
- dbTester.events().insertEvent(newEvent(newAnalysis(ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization()))).setUuid("E1"));
+ dbTester.events().insertEvent(newEvent(newAnalysis(ComponentTesting.newPrivateProjectDto())).setUuid("E1"));
underTest.delete(dbTester.getSession(), "E1");
dbTester.commit();
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
index 554078dce24..075998d0b06 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java
@@ -37,7 +37,6 @@ import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.ComponentUpdateDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleTesting;
@@ -302,7 +301,6 @@ public class IssueDaoTest {
assertThat(underTest.selectModuleAndDirComponentUuidsOfOpenIssuesForProjectUuid(db.getSession(), randomAlphabetic(12)))
.isEmpty();
- OrganizationDto organization = db.organizations().insert();
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto module11 = db.components().insertComponent(newModuleDto(project1));
ComponentDto dir11 = db.components().insertComponent(newDirectory(module11, randomAlphabetic(10)));
@@ -311,8 +309,8 @@ public class IssueDaoTest {
ComponentDto dir13 = db.components().insertComponent(newDirectory(module12, randomAlphabetic(12)));
ComponentDto dir14 = db.components().insertComponent(newDirectory(project1, randomAlphabetic(13)));
ComponentDto file11 = db.components().insertComponent(newFileDto(project1));
- ComponentDto application = db.components().insertPrivateApplication(organization);
- ComponentDto view = db.components().insertView(organization);
+ ComponentDto application = db.components().insertPrivateApplication();
+ ComponentDto view = db.components().insertPublicPortfolio();
ComponentDto subview = db.components().insertSubView(view);
ComponentDto project2 = db.components().insertPublicProject();
ComponentDto module21 = db.components().insertComponent(newModuleDto(project2));
@@ -418,8 +416,7 @@ public class IssueDaoTest {
private void prepareTables() {
db.rules().insertRule(RULE.setIsExternal(true));
- OrganizationDto organizationDto = db.organizations().insert();
- ComponentDto projectDto = db.components().insertPrivateProject(organizationDto, (t) -> t.setUuid(PROJECT_UUID).setDbKey(PROJECT_KEY));
+ ComponentDto projectDto = db.components().insertPrivateProject(t -> t.setUuid(PROJECT_UUID).setDbKey(PROJECT_KEY));
db.components().insertComponent(newFileDto(projectDto).setUuid(FILE_UUID).setDbKey(FILE_KEY));
underTest.insert(db.getSession(), newIssueDto(ISSUE_KEY1)
.setMessage("the message")
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
index 3660905b3b2..c52fd2367fe 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueMapperTest.java
@@ -47,7 +47,6 @@ import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.db.rule.RuleTesting;
@@ -64,20 +63,16 @@ public class IssueMapperTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private DbSession dbSession = dbTester.getSession();
-
- private IssueMapper underTest = dbSession.getMapper(IssueMapper.class);
-
+ private final DbSession dbSession = dbTester.getSession();
+ private final IssueMapper underTest = dbSession.getMapper(IssueMapper.class);
+ private final Random random = new Random();
+ private final System2 system2 = new AlwaysIncreasingSystem2();
private ComponentDto project, file, file2;
private RuleDto rule;
- private Random random = new Random();
- private System2 system2 = new AlwaysIncreasingSystem2();
@Before
public void setUp() {
- OrganizationDto organizationDto = dbTester.organizations().insert();
- project = ComponentTesting.newPrivateProjectDto(organizationDto);
- dbTester.getDbClient().componentDao().insert(dbSession, project);
+ project = dbTester.components().insertPrivateProject();
file = ComponentTesting.newFileDto(project, null);
dbTester.getDbClient().componentDao().insert(dbSession, file);
file2 = ComponentTesting.newFileDto(project, null).setUuid("file2 uuid");
@@ -252,8 +247,7 @@ public class IssueMapperTest {
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_returns_closed_issues_with_at_least_one_diff_to_CLOSED(RuleType ruleType) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto component = randomComponent(organization);
+ ComponentDto component = randomComponent();
IssueDto expected = insertNewClosedIssue(component, ruleType);
IssueChangeDto changeDto = insertToClosedDiff(expected);
@@ -269,8 +263,7 @@ public class IssueMapperTest {
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_does_not_return_closed_issues_of_non_existing_rule(RuleType ruleType) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto component = randomComponent(organization);
+ ComponentDto component = randomComponent();
IssueDto issueWithRule = insertNewClosedIssue(component, ruleType);
IssueChangeDto issueChange = insertToClosedDiff(issueWithRule);
IssueDto issueWithoutRule = insertNewClosedIssue(component, new RuleDefinitionDto().setType(ruleType).setUuid("uuid-50"));
@@ -287,8 +280,7 @@ public class IssueMapperTest {
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_does_not_return_closed_issues_of_orphan_component(RuleType ruleType) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto component = randomComponent(organization);
+ ComponentDto component = randomComponent();
IssueDto issue = insertNewClosedIssue(component, ruleType);
IssueChangeDto issueChange = insertToClosedDiff(issue);
IssueDto issueMissingComponent = insertNewClosedIssue(component, ruleType, t -> t.setComponentUuid("does_not_exist"));
@@ -307,8 +299,7 @@ public class IssueMapperTest {
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_does_not_return_closed_issues_without_any_status_diff_to_CLOSED(RuleType ruleType) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto component = randomComponent(organization);
+ ComponentDto component = randomComponent();
IssueDto issueWithLineDiff = insertNewClosedIssue(component, ruleType);
IssueChangeDto issueChange = insertToClosedDiff(issueWithLineDiff);
insertNewClosedIssue(component, ruleType);
@@ -324,8 +315,7 @@ public class IssueMapperTest {
@Test
public void scrollClosedByComponentUuid_does_not_return_closed_issues_of_type_SECURITY_HOTSPOT() {
RuleType ruleType = randomSupportedRuleType();
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto component = randomComponent(organization);
+ ComponentDto component = randomComponent();
IssueDto securityHotspotIssue = insertNewClosedIssue(component, RuleType.SECURITY_HOTSPOT);
insertToClosedDiff(securityHotspotIssue);
IssueDto issue = insertNewClosedIssue(component, ruleType);
@@ -342,8 +332,7 @@ public class IssueMapperTest {
@Test
public void scrollClosedByComponentUuid_does_not_return_closed_issues_without_close_date() {
RuleType ruleType = randomSupportedRuleType();
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto component = randomComponent(organization);
+ ComponentDto component = randomComponent();
IssueDto issueWithoutCloseDate = insertNewClosedIssue(component, ruleType, t -> t.setIssueCloseDate(null));
insertToClosedDiff(issueWithoutCloseDate);
IssueDto issueCloseDate = insertNewClosedIssue(component, ruleType);
@@ -361,8 +350,7 @@ public class IssueMapperTest {
@Test
public void scrollClosedByComponentUuid_returns_closed_issues_which_close_date_is_greater_or_equal_to_requested() {
RuleType ruleType = randomSupportedRuleType();
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto component = randomComponent(organization);
+ ComponentDto component = randomComponent();
RuleDefinitionDto rule1 = dbTester.rules().insert(t -> t.setType(ruleType));
IssueDto[] issues = new IssueDto[] {
insertNewClosedIssue(component, rule1, 1_999_999L),
@@ -409,8 +397,7 @@ public class IssueMapperTest {
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_return_one_row_per_status_diff_to_CLOSED_sorted_by_most_recent_creation_date_first(RuleType ruleType) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto component = randomComponent(organization);
+ ComponentDto component = randomComponent();
IssueDto issue = insertNewClosedIssue(component, ruleType);
Date date = new Date();
IssueChangeDto[] changes = new IssueChangeDto[] {
@@ -436,8 +423,7 @@ public class IssueMapperTest {
@Test
@UseDataProvider("closedIssuesSupportedRuleTypes")
public void scrollClosedByComponentUuid_does_not_return_row_for_status_change_from_close(RuleType ruleType) {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto component = randomComponent(organization);
+ ComponentDto component = randomComponent();
IssueDto issue = insertNewClosedIssue(component, ruleType);
Date date = new Date();
IssueChangeDto[] changes = new IssueChangeDto[] {
@@ -526,8 +512,8 @@ public class IssueMapperTest {
return SUPPORTED_RULE_TYPES[new Random().nextInt(SUPPORTED_RULE_TYPES.length)];
}
- private ComponentDto randomComponent(OrganizationDto organization) {
- ComponentDto project = dbTester.components().insertPublicProject(organization);
+ private ComponentDto randomComponent() {
+ ComponentDto project = dbTester.components().insertPublicProject();
ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project));
ComponentDto dir = dbTester.components().insertComponent(ComponentTesting.newDirectory(project, "foo"));
ComponentDto file = dbTester.components().insertComponent(ComponentTesting.newFileDto(project));
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
index 489b83e4313..1c8a2b45b04 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
@@ -36,7 +36,6 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.BranchType;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
@@ -54,7 +53,7 @@ public class LiveMeasureDaoTest {
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
- private LiveMeasureDao underTest = db.getDbClient().liveMeasureDao();
+ private final LiveMeasureDao underTest = db.getDbClient().liveMeasureDao();
private MetricDto metric;
@Before
@@ -303,19 +302,18 @@ public class LiveMeasureDaoTest {
@Test
public void countNcloc() {
- OrganizationDto organization = db.organizations().insert();
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
MetricDto lines = db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString()));
- ComponentDto simpleProject = db.components().insertPublicProject(organization);
+ ComponentDto simpleProject = db.components().insertPublicProject();
db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d));
- ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(organization);
+ ComponentDto projectWithBiggerBranch = db.components().insertPublicProject();
ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH));
db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d));
db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d));
- ComponentDto projectWithLinesButNoLoc = db.components().insertPublicProject(organization);
+ ComponentDto projectWithLinesButNoLoc = db.components().insertPublicProject();
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d));
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d));
@@ -341,18 +339,17 @@ public class LiveMeasureDaoTest {
@Test
public void countNcloc_and_exclude_project() {
- OrganizationDto organization = db.organizations().insert();
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
- ComponentDto simpleProject = db.components().insertPublicProject(organization);
+ ComponentDto simpleProject = db.components().insertPublicProject();
db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d));
- ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(organization);
+ ComponentDto projectWithBiggerBranch = db.components().insertPublicProject();
ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH));
db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d));
db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d));
- ComponentDto projectToExclude = db.components().insertPublicProject(organization);
+ ComponentDto projectToExclude = db.components().insertPublicProject();
ComponentDto projectToExcludeBranch = db.components().insertProjectBranch(projectToExclude, b -> b.setBranchType(BranchType.BRANCH));
db.measures().insertLiveMeasure(projectToExclude, ncloc, m -> m.setValue(300d));
db.measures().insertLiveMeasure(projectToExcludeBranch, ncloc, m -> m.setValue(400d));
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java
index 66349c17b66..32575d5eecb 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/MeasureTreeQueryTest.java
@@ -24,7 +24,6 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.component.ComponentTesting;
-import org.sonar.db.organization.OrganizationTesting;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
@@ -78,10 +77,10 @@ public class MeasureTreeQueryTest {
@Test
public void test_getUuidPath() {
assertThat(MeasureTreeQuery.builder().setStrategy(CHILDREN)
- .build().getUuidPath(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT_UUID.");
+ .build().getUuidPath(ComponentTesting.newPrivateProjectDto("PROJECT_UUID"))).isEqualTo(".PROJECT_UUID.");
assertThat(MeasureTreeQuery.builder().setStrategy(LEAVES)
- .build().getUuidPath(ComponentTesting.newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), "PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%");
+ .build().getUuidPath(ComponentTesting.newPrivateProjectDto("PROJECT_UUID"))).isEqualTo(".PROJECT/_UUID.%");
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
index 28117efbf7d..dc5d99c707f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
@@ -33,7 +33,6 @@ import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures;
import org.sonar.db.metric.MetricDto;
-import org.sonar.db.organization.OrganizationDto;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
@@ -54,13 +53,12 @@ public class ProjectMeasuresIndexerIteratorTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private DbClient dbClient = dbTester.getDbClient();
- private DbSession dbSession = dbTester.getSession();
+ private final DbClient dbClient = dbTester.getDbClient();
+ private final DbSession dbSession = dbTester.getSession();
@Test
public void return_project_measure() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization,
+ ComponentDto project = dbTester.components().insertPrivateProject(
c -> c.setDbKey("Project-Key").setName("Project Name"),
p -> p.setTags(newArrayList("platform", "java")));
@@ -108,8 +106,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_project_measure_having_leak() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization,
+ ComponentDto project = dbTester.components().insertPrivateProject(
c -> c.setDbKey("Project-Key").setName("Project Name"),
p -> p.setTagsString("platform,java"));
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines"));
@@ -122,10 +119,9 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_quality_gate_status_measure() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project1 = dbTester.components().insertPrivateProject(organization);
- ComponentDto project2 = dbTester.components().insertPrivateProject(organization);
- ComponentDto project3 = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project1 = dbTester.components().insertPrivateProject();
+ ComponentDto project2 = dbTester.components().insertPrivateProject();
+ ComponentDto project3 = dbTester.components().insertPrivateProject();
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(LEVEL.name()).setKey("alert_status"));
dbTester.measures().insertLiveMeasure(project2, metric, m -> m.setValue(null).setData(OK.name()));
dbTester.measures().insertLiveMeasure(project3, metric, m -> m.setValue(null).setData(ERROR.name()));
@@ -138,8 +134,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void does_not_fail_when_quality_gate_has_no_value() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(LEVEL.name()).setKey("alert_status"));
dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setVariation(null).setData((String) null));
@@ -150,8 +145,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_language_distribution_measure() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(DATA.name()).setKey("ncloc_language_distribution"));
dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(null).setData("<null>=2;java=6;xoo=18"));
@@ -163,8 +157,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void does_not_return_none_numeric_metrics() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
MetricDto dataMetric = dbTester.measures().insertMetric(m -> m.setValueType(DATA.name()).setKey("data"));
MetricDto distribMetric = dbTester.measures().insertMetric(m -> m.setValueType(DISTRIB.name()).setKey("distrib"));
MetricDto stringMetric = dbTester.measures().insertMetric(m -> m.setValueType(STRING.name()).setKey("string"));
@@ -179,8 +172,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void does_not_return_disabled_metrics() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
MetricDto disabledMetric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setEnabled(false).setHidden(false).setKey("disabled"));
dbTester.measures().insertLiveMeasure(project, disabledMetric, m -> m.setValue(10d));
@@ -191,11 +183,10 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void ignore_measure_that_does_not_have_value() {
- OrganizationDto organization = dbTester.organizations().insert();
MetricDto metric1 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("coverage"));
MetricDto metric2 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc"));
MetricDto leakMetric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("new_lines"));
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
dbTester.measures().insertLiveMeasure(project, metric1, m -> m.setValue(10d));
dbTester.measures().insertLiveMeasure(project, leakMetric, m -> m.setValue(null).setVariation(20d));
@@ -207,10 +198,9 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void ignore_numeric_measure_that_has_text_value_but_not_numeric_value() {
- OrganizationDto organization = dbTester.organizations().insert();
MetricDto metric1 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("coverage"));
MetricDto metric2 = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc"));
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
dbTester.measures().insertLiveMeasure(project, metric1, m -> m.setValue(10d).setData((String) null));
dbTester.measures().insertLiveMeasure(project, metric2, m -> m.setValue(null).setData("foo"));
@@ -220,10 +210,9 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_many_project_measures() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project1 = dbTester.components().insertPrivateProject(organization);
- ComponentDto project2 = dbTester.components().insertPrivateProject(organization);
- ComponentDto project3 = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project1 = dbTester.components().insertPrivateProject();
+ ComponentDto project2 = dbTester.components().insertPrivateProject();
+ ComponentDto project3 = dbTester.components().insertPrivateProject();
dbTester.components().insertSnapshot(project1);
dbTester.components().insertSnapshot(project2);
dbTester.components().insertSnapshot(project3);
@@ -233,7 +222,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_project_without_analysis() {
- ComponentDto project = dbTester.components().insertPrivateProject(dbTester.organizations().insert());
+ ComponentDto project = dbTester.components().insertPrivateProject();
dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setLast(false));
dbSession.commit();
@@ -246,10 +235,9 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_only_docs_from_given_project() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project1 = dbTester.components().insertPrivateProject(organization);
- ComponentDto project2 = dbTester.components().insertPrivateProject(organization);
- ComponentDto project3 = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project1 = dbTester.components().insertPrivateProject();
+ ComponentDto project2 = dbTester.components().insertPrivateProject();
+ ComponentDto project3 = dbTester.components().insertPrivateProject();
SnapshotDto analysis1 = dbTester.components().insertSnapshot(project1);
SnapshotDto analysis2 = dbTester.components().insertSnapshot(project2);
SnapshotDto analysis3 = dbTester.components().insertSnapshot(project3);
@@ -267,8 +255,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_nothing_on_unknown_project() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
dbTester.components().insertSnapshot(project);
Map<String, ProjectMeasures> docsById = createResultSetAndReturnDocsById("UNKNOWN");
@@ -278,8 +265,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void non_main_branches_are_not_indexed() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
MetricDto metric = dbTester.measures().insertMetric(m -> m.setValueType(INT.name()).setKey("ncloc"));
dbTester.measures().insertLiveMeasure(project, metric, m -> m.setValue(10d));
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java
index 1fbce9a9e9a..90af6e67868 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/PermissionQueryTest.java
@@ -23,11 +23,9 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.component.ComponentTesting.newPublicProjectDto;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
public class PermissionQueryTest {
@@ -36,8 +34,7 @@ public class PermissionQueryTest {
@Test
public void create_query() {
- OrganizationDto organization = newOrganizationDto();
- ComponentDto project = newPublicProjectDto(organization);
+ ComponentDto project = newPublicProjectDto();
PermissionQuery query = PermissionQuery.builder()
.setComponent(project)
.setPermission("user")
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
index 644d17895c1..880069adcbd 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java
@@ -63,17 +63,16 @@ public class PropertiesDaoTest {
private static final String VALUE_SIZE_4001 = VALUE_SIZE_4000 + "P";
private static final long INITIAL_DATE = 1_444_000L;
- private AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2(INITIAL_DATE, 1);
+ private final AlwaysIncreasingSystem2 system2 = new AlwaysIncreasingSystem2(INITIAL_DATE, 1);
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public DbTester db = DbTester.create(system2);
- private DbClient dbClient = db.getDbClient();
- private DbSession session = db.getSession();
-
- private PropertiesDao underTest = db.getDbClient().propertiesDao();
+ private final DbClient dbClient = db.getDbClient();
+ private final DbSession session = db.getSession();
+ private final PropertiesDao underTest = db.getDbClient().propertiesDao();
@Test
public void shouldFindUsersForNotification() {
@@ -121,7 +120,7 @@ public class PropertiesDaoTest {
String userUuid1 = db.users().insertUser(u -> u.setLogin("user1")).getUuid();
String userUuid2 = db.users().insertUser(u -> u.setLogin("user2")).getUuid();
String projectUuid = randomAlphabetic(8);
- db.components().insertPrivateProject(db.getDefaultOrganization(), projectUuid);
+ db.components().insertPrivateProject(projectUuid);
// global subscription
insertProperty("notification.DispatcherWithGlobalSubscribers.Email", "true", null, userUuid2);
@@ -1240,7 +1239,7 @@ public class PropertiesDaoTest {
}
private ComponentDto insertPrivateProject(String projectKey) {
- return db.components().insertPrivateProject(db.getDefaultOrganization(), t -> t.setDbKey(projectKey));
+ return db.components().insertPrivateProject(t -> t.setDbKey(projectKey));
}
private static Consumer<UserDto> withEmail(String login) {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
index 80810c1917b..a39d7d7ad59 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
@@ -73,7 +73,6 @@ import org.sonar.db.measure.custom.CustomMeasureDto;
import org.sonar.db.metric.MetricDto;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.rule.RuleDefinitionDto;
@@ -446,7 +445,7 @@ public class PurgeDaoTest {
@Test
public void selectPurgeableAnalyses_does_not_return_the_baseline() {
- ComponentDto project1 = db.components().insertPublicProject(db.getDefaultOrganization(), "master");
+ ComponentDto project1 = db.components().insertPublicProject("master");
SnapshotDto analysis1 = db.components().insertSnapshot(newSnapshot()
.setComponentUuid(project1.uuid())
.setStatus(STATUS_PROCESSED)
@@ -472,7 +471,7 @@ public class PurgeDaoTest {
@Test
public void selectPurgeableAnalyses_does_not_return_the_baseline_of_specific_branch() {
- ComponentDto project = db.components().insertPublicProject(db.getDefaultOrganization(), "master");
+ ComponentDto project = db.components().insertPublicProject("master");
SnapshotDto analysisProject = db.components().insertSnapshot(newSnapshot()
.setComponentUuid(project.uuid())
.setStatus(STATUS_PROCESSED)
@@ -624,11 +623,10 @@ public class PurgeDaoTest {
@Test
public void delete_webhooks_from_project() {
- OrganizationDto organization = db.organizations().insert();
- ProjectDto project1 = db.components().insertPrivateProjectDto(organization);
+ ProjectDto project1 = db.components().insertPrivateProjectDto();
WebhookDto webhook = db.webhooks().insertWebhook(project1);
db.webhookDelivery().insert(webhook);
- ProjectDto projectNotToBeDeleted = db.components().insertPrivateProjectDto(organization);
+ ProjectDto projectNotToBeDeleted = db.components().insertPrivateProjectDto();
WebhookDto webhookNotDeleted = db.webhooks().insertWebhook(projectNotToBeDeleted);
WebhookDeliveryLiteDto webhookDeliveryNotDeleted = db.webhookDelivery().insert(webhookNotDeleted);
@@ -1058,10 +1056,10 @@ public class PurgeDaoTest {
@Test
public void delete_view_and_child() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subView = db.components().insertComponent(newSubView(view));
ComponentDto projectCopy = db.components().insertComponent(newProjectCopy(project, subView));
- ComponentDto otherView = db.components().insertView();
+ ComponentDto otherView = db.components().insertPrivatePortfolio();
ComponentDto otherSubView = db.components().insertComponent(newSubView(otherView));
ComponentDto otherProjectCopy = db.components().insertComponent(newProjectCopy(project, otherSubView));
@@ -1363,8 +1361,8 @@ public class PurgeDaoTest {
verifyNoEffect(componentDbTester.insertPrivateProject());
verifyNoEffect(componentDbTester.insertPublicProject());
- verifyNoEffect(componentDbTester.insertView());
- verifyNoEffect(componentDbTester.insertView(), componentDbTester.insertPrivateProject(), componentDbTester.insertPublicProject());
+ verifyNoEffect(componentDbTester.insertPrivatePortfolio());
+ verifyNoEffect(componentDbTester.insertPrivatePortfolio(), componentDbTester.insertPrivateProject(), componentDbTester.insertPublicProject());
}
@Test
@@ -1429,7 +1427,7 @@ public class PurgeDaoTest {
db.components().insertPrivateProject()
};
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subview1 = db.components().insertComponent(newSubView(view));
ComponentDto subview2 = db.components().insertComponent(newSubView(subview1));
List<ComponentDto> components = asList(
@@ -1475,7 +1473,7 @@ public class PurgeDaoTest {
db.components().insertPrivateProject()
};
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subview1 = db.components().insertComponent(newSubView(view));
ComponentDto subview2 = db.components().insertComponent(newSubView(subview1));
ComponentDto pc1 = db.components().insertComponent(newProjectCopy("a", projects[0], view));
@@ -1495,7 +1493,7 @@ public class PurgeDaoTest {
@Test
public void deleteNonRootComponents_deletes_measures_of_any_non_root_component_of_a_view() {
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subview = db.components().insertComponent(newSubView(view));
ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view));
insertMeasureFor(view, subview, pc);
@@ -1512,7 +1510,7 @@ public class PurgeDaoTest {
@Test
public void deleteNonRootComponents_deletes_properties_of_subviews_of_a_view() {
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subview1 = db.components().insertComponent(newSubView(view));
ComponentDto subview2 = db.components().insertComponent(newSubView(subview1));
ComponentDto subview3 = db.components().insertComponent(newSubView(view));
@@ -1531,7 +1529,7 @@ public class PurgeDaoTest {
@Test
public void deleteNonRootComponentsInView_deletes_manual_measures_of_subviews_of_a_view() {
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subview1 = db.components().insertComponent(newSubView(view));
ComponentDto subview2 = db.components().insertComponent(newSubView(subview1));
ComponentDto subview3 = db.components().insertComponent(newSubView(view));
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java
index 1b400e5e02f..ec1864a0f79 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeMapperTest.java
@@ -83,7 +83,7 @@ public class PurgeMapperTest {
@Test
public void selectRootAndModulesOrSubviewsByProjectUuid_returns_view_with_specified_uuid() {
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
.containsOnly(view.uuid());
@@ -91,7 +91,7 @@ public class PurgeMapperTest {
@Test
public void selectRootAndModulesOrSubviewsByProjectUuid_returns_application_with_specified_uuid() {
- ComponentDto view = db.components().insertPublicApplication(db.getDefaultOrganization());
+ ComponentDto view = db.components().insertPublicApplication();
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
.containsOnly(view.uuid());
@@ -99,7 +99,7 @@ public class PurgeMapperTest {
@Test
public void selectRootAndModulesOrSubviewsByProjectUuid_returns_subviews_with_specified_project_uuid_and_view() {
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPublicPortfolio();
ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view));
ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(view));
ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubView(view));
@@ -111,7 +111,7 @@ public class PurgeMapperTest {
@Test
public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_project_copy_with_specified_project_uuid() {
ComponentDto privateProject = db.components().insertPrivateProject();
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
db.components().insertComponent(ComponentTesting.newProjectCopy("a", view, privateProject));
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(view.uuid()))
@@ -147,7 +147,7 @@ public class PurgeMapperTest {
@Test
public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_subview_with_specified_uuid() {
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubView(view));
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(subview.uuid()))
@@ -157,7 +157,7 @@ public class PurgeMapperTest {
@Test
public void selectRootAndModulesOrSubviewsByProjectUuid_does_not_return_technicalCopy_with_specified_uuid() {
ComponentDto privateProject = db.components().insertPrivateProject();
- ComponentDto view = db.components().insertView();
+ ComponentDto view = db.components().insertPrivatePortfolio();
ComponentDto technicalCopy = db.components().insertComponent(ComponentTesting.newProjectCopy("a", view, privateProject));
assertThat(purgeMapper.selectRootAndModulesOrSubviewsByProjectUuid(technicalCopy.uuid()))
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
index 02b718c992a..564929adf25 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java
@@ -37,7 +37,6 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDefinitionDto;
@@ -703,8 +702,7 @@ public class QualityProfileDaoTest {
ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name"));
ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name"));
ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"));
- OrganizationDto organization2 = db.organizations().insert();
- ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name").setOrganizationUuid(organization2.getUuid()));
+ ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"));
ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
@@ -796,7 +794,6 @@ public class QualityProfileDaoTest {
@Test
public void renameAndCommit_updates_name_of_specified_profiles() {
- OrganizationDto org1 = db.organizations().insert();
QProfileDto fooInOrg1 = db.qualityProfiles().insert(p -> p.setName("foo"));
QProfileDto bar = db.qualityProfiles().insert(p -> p.setName("bar"));
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java
index 25052001869..77157c0b132 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/source/FileSourceDaoTest.java
@@ -41,7 +41,6 @@ import org.sonar.core.util.Uuids;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import static com.google.common.collect.ImmutableList.of;
import static java.util.Collections.emptyList;
@@ -56,14 +55,13 @@ public class FileSourceDaoTest {
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
- private DbSession dbSession = dbTester.getSession();
+ private final DbSession dbSession = dbTester.getSession();
- private FileSourceDao underTest = dbTester.getDbClient().fileSourceDao();
+ private final FileSourceDao underTest = dbTester.getDbClient().fileSourceDao();
@Test
public void select() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
FileSourceDto expected = dbTester.fileSources().insertFileSource(file);
@@ -82,8 +80,7 @@ public class FileSourceDaoTest {
@Test
public void select_line_hashes() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
FileSourceDto expected = dbTester.fileSources().insertFileSource(file);
@@ -95,8 +92,7 @@ public class FileSourceDaoTest {
@Test
public void no_line_hashes_on_unknown_file() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
dbTester.fileSources().insertFileSource(file);
@@ -253,8 +249,7 @@ public class FileSourceDaoTest {
@Test
public void scrollLineHashes_scrolls_hashes_of_specific_keys() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject(organization) : dbTester.components().insertPublicProject(organization);
+ ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject() : dbTester.components().insertPublicProject();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project));
FileSourceDto fileSource1 = dbTester.fileSources().insertFileSource(file1);
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project));
@@ -279,8 +274,7 @@ public class FileSourceDaoTest {
@Test
public void scrollLineHashes_does_not_scroll_hashes_of_component_without_path() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject(organization) : dbTester.components().insertPublicProject(organization);
+ ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject() : dbTester.components().insertPublicProject();
ComponentDto file1 = dbTester.components().insertComponent(newFileDto(project));
FileSourceDto fileSource1 = dbTester.fileSources().insertFileSource(file1);
ComponentDto file2 = dbTester.components().insertComponent(newFileDto(project).setPath(null));
@@ -293,8 +287,7 @@ public class FileSourceDaoTest {
@Test
public void scrollLineHashes_handles_scrolling_more_than_1000_files() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject(organization) : dbTester.components().insertPublicProject(organization);
+ ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPrivateProject() : dbTester.components().insertPublicProject();
List<ComponentDto> files = IntStream.range(0, 1001 + new Random().nextInt(5))
.mapToObj(i -> {
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
@@ -340,8 +333,7 @@ public class FileSourceDaoTest {
@Test
public void update() {
- OrganizationDto organization = dbTester.organizations().insert();
- ComponentDto project = dbTester.components().insertPrivateProject(organization);
+ ComponentDto project = dbTester.components().insertPrivateProject();
ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
FileSourceDto expected = dbTester.fileSources().insertFileSource(file);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java
index c27ba15ecec..719b512918a 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java
@@ -29,8 +29,6 @@ import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDbTester;
-import org.sonar.db.organization.OrganizationDbTester;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,7 +45,6 @@ public class WebhookDaoTest {
private final WebhookDao underTest = dbClient.webhookDao();
private final WebhookDbTester webhookDbTester = dbTester.webhooks();
private final ComponentDbTester componentDbTester = dbTester.components();
- private final OrganizationDbTester organizationDbTester = dbTester.organizations();
@Test
public void selectByUuid_returns_empty_if_uuid_does_not_exist() {
@@ -113,7 +110,7 @@ public class WebhookDaoTest {
assertThat(stored.getUuid()).isEqualTo(dto.getUuid());
assertThat(stored.getName()).isEqualTo(dto.getName());
assertThat(stored.getUrl()).isEqualTo(dto.getUrl());
- assertThat(stored.getOrganizationUuid()).isEqualTo(organizationDbTester.getDefaultOrganization().getUuid());
+ assertThat(stored.getOrganizationUuid()).isEqualTo(dbTester.getDefaultOrganization().getUuid());
assertThat(stored.getProjectUuid()).isNull();
assertThat(stored.getSecret()).isEqualTo(dto.getSecret());
assertThat(new Date(stored.getCreatedAt())).isInSameMinuteWindowAs(new Date(system2.now()));
@@ -189,8 +186,7 @@ public class WebhookDaoTest {
@Test
public void cleanWebhooksOfAProject() {
- OrganizationDto organization = organizationDbTester.insert();
- ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(organization);
+ ProjectDto projectDto = componentDbTester.insertPrivateProjectDto();
webhookDbTester.insertWebhook(projectDto);
webhookDbTester.insertWebhook(projectDto);
webhookDbTester.insertWebhook(projectDto);
@@ -223,7 +219,7 @@ public class WebhookDaoTest {
Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, dto.getUuid());
assertThat(reloaded).isPresent();
- assertThat(reloaded.get().getOrganizationUuid()).isEqualTo(organizationDbTester.getDefaultOrganization().getUuid());
+ assertThat(reloaded.get().getOrganizationUuid()).isEqualTo(dbTester.getDefaultOrganization().getUuid());
}
@Test
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
index 01b9afd9bab..36a067b4423 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/DbTester.java
@@ -42,9 +42,7 @@ import org.sonar.db.issue.IssueDbTester;
import org.sonar.db.measure.MeasureDbTester;
import org.sonar.db.newcodeperiod.NewCodePeriodDbTester;
import org.sonar.db.notification.NotificationDbTester;
-import org.sonar.db.organization.OrganizationDbTester;
import org.sonar.db.organization.OrganizationDto;
-import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.permission.template.PermissionTemplateDbTester;
import org.sonar.db.plugin.PluginDbTester;
import org.sonar.db.property.InternalComponentPropertyDbTester;
@@ -60,6 +58,7 @@ import org.sonar.db.webhook.WebhookDeliveryDbTester;
import static com.google.common.base.Preconditions.checkState;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.sonar.db.organization.OrganizationDto.Subscription.FREE;
/**
* This class should be called using @Rule.
@@ -82,7 +81,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
private final ProjectLinkDbTester componentLinkTester;
private final FavoriteDbTester favoriteTester;
private final EventDbTester eventTester;
- private final OrganizationDbTester organizationTester;
private final PermissionTemplateDbTester permissionTemplateTester;
private final PropertyDbTester propertyTester;
private final QualityGateDbTester qualityGateDbTester;
@@ -111,7 +109,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
this.componentLinkTester = new ProjectLinkDbTester(this);
this.favoriteTester = new FavoriteDbTester(this);
this.eventTester = new EventDbTester(this);
- this.organizationTester = new OrganizationDbTester(this);
this.permissionTemplateTester = new PermissionTemplateDbTester(this);
this.propertyTester = new PropertyDbTester(this);
this.qualityGateDbTester = new QualityGateDbTester(this);
@@ -159,7 +156,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
client = new DbClient(db.getDatabase(), db.getMyBatis(), new TestDBSessions(db.getMyBatis()), daos.toArray(new Dao[daos.size()]));
}
- //TODO remove
+ // TODO remove
@Deprecated
public DbTester setDisableDefaultOrganization(boolean b) {
checkState(!started, "DbTester is already started");
@@ -167,7 +164,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
return this;
}
- //TODO remove
+ // TODO remove
@Deprecated
public DbTester setDefaultOrganizationUuid(String uuid) {
checkState(!started, "DbTester is already started");
@@ -175,7 +172,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
return this;
}
- //TODO remove
+ // TODO remove
@Deprecated
public DbTester setDefaultOrganizationKey(String key) {
checkState(!started, "DbTester is already started");
@@ -194,10 +191,20 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
started = true;
}
- //TODO remove
+ // TODO remove
@Deprecated
private void insertDefaultOrganization() {
- defaultOrganization = OrganizationTesting.newOrganizationDto().setUuid(defaultOrganizationUuid).setKey(defaultOrganizationKey);
+ defaultOrganization = new OrganizationDto()
+ .setName(randomAlphanumeric(64))
+ .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))
+ .setUuid(defaultOrganizationUuid)
+ .setKey(defaultOrganizationKey);
+
try (DbSession dbSession = db.getMyBatis().openSession(false)) {
client.organizationDao().insert(dbSession, defaultOrganization, false);
client.internalPropertiesDao().save(dbSession, "organization.default", defaultOrganization.getUuid());
@@ -205,7 +212,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
}
}
- //TODO remove
+ // TODO remove
@Deprecated
public OrganizationDto getDefaultOrganization() {
checkState(defaultOrganization != null, "Default organization has not been created");
@@ -232,10 +239,6 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
return eventTester;
}
- public OrganizationDbTester organizations() {
- return organizationTester;
- }
-
public PermissionTemplateDbTester permissionTemplates() {
return permissionTemplateTester;
}
@@ -300,7 +303,7 @@ public class DbTester extends AbstractDbTester<TestDbImpl> {
return almSettingsDbTester;
}
- public AlmPatsDbTester almPats(){
+ public AlmPatsDbTester almPats() {
return almPatsDbtester;
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
index 57409686f6b..187534fa923 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
@@ -27,7 +27,6 @@ import org.sonar.api.utils.System2;
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.project.ProjectDto;
import static com.google.common.base.Preconditions.checkArgument;
@@ -65,7 +64,7 @@ public class ComponentDbTester {
}
public ComponentDto insertPrivateProject() {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true,
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true,
defaults(), defaults(), defaults());
}
@@ -79,7 +78,11 @@ public class ComponentDbTester {
}
public ComponentDto insertPublicProject() {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false);
+ return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(), false);
+ }
+
+ public ComponentDto insertPublicProject(String uuid) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(uuid), false);
}
public ComponentDto insertPublicProject(ComponentDto componentDto) {
@@ -87,69 +90,29 @@ public class ComponentDbTester {
}
public ComponentDto insertPrivateProject(String uuid) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization(), uuid), true);
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(uuid), true);
}
public final ComponentDto insertPrivateProject(Consumer<ComponentDto> dtoPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()), true, defaults(),
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true, defaults(),
dtoPopulator);
}
public final ComponentDto insertPrivateProject(Consumer<ComponentDto> componentDtoPopulator, Consumer<ProjectDto> projectDtoPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()),
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(),
true, defaults(), componentDtoPopulator, projectDtoPopulator);
}
public final ComponentDto insertPublicProject(Consumer<ComponentDto> dtoPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, defaults(),
+ return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(), false, defaults(),
dtoPopulator);
}
public final ComponentDto insertPublicProject(Consumer<ComponentDto> componentDtoPopulator, Consumer<ProjectDto> projectDtoPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(db.getDefaultOrganization()), false, defaults(), componentDtoPopulator,
- projectDtoPopulator);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator) {
- return insertPrivateProject(organizationDto, componentDtoPopulator, defaults());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator,
- Consumer<ProjectDto> projectDtoPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, defaults(),
- componentDtoPopulator, projectDtoPopulator);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator) {
- return insertPublicProject(organizationDto, componentDtoPopulator, defaults());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPublicProject(OrganizationDto organizationDto, Consumer<ComponentDto> componentDtoPopulator,
- Consumer<ProjectDto> projectDtoPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false, defaults(), componentDtoPopulator,
+ return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(), false, defaults(), componentDtoPopulator,
projectDtoPopulator);
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public ComponentDto insertPrivateProject(OrganizationDto organizationDto) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public ComponentDto insertPublicProject(OrganizationDto organizationDto) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto), false);
- }
-
public ProjectDto insertPublicProjectDto() {
ComponentDto componentDto = insertPublicProject();
return getProjectDto(componentDto);
@@ -160,32 +123,11 @@ public class ComponentDbTester {
return getProjectDto(componentDto);
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public ProjectDto insertPublicProjectDto(OrganizationDto organization) {
- ComponentDto componentDto = insertPublicProject(organization);
- return getProjectDto(componentDto);
- }
-
public ProjectDto insertPublicProjectDto(Consumer<ComponentDto> dtoPopulator) {
ComponentDto componentDto = insertPublicProject(dtoPopulator);
return getProjectDto(componentDto);
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ProjectDto insertPublicProjectDto(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
- ComponentDto componentDto = insertPublicProject(organization, dtoPopulator);
- return getProjectDto(componentDto);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public ProjectDto insertPrivateProjectDto(OrganizationDto organization) {
- ComponentDto componentDto = insertPrivateProject(organization);
- return getProjectDto(componentDto);
- }
-
public final ProjectDto insertPrivateProjectDto(Consumer<ComponentDto> componentDtoPopulator) {
return insertPrivateProjectDto(componentDtoPopulator, defaults());
}
@@ -195,122 +137,31 @@ public class ComponentDbTester {
return getProjectDto(componentDto);
}
- public final ComponentDto insertPrivateProject(String uuid, Consumer<ComponentDto> dtoPopulator) {
- return insertPrivateProject(db.getDefaultOrganization(), uuid, dtoPopulator);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public ProjectDto insertPrivateProjectDto(OrganizationDto organization, Consumer<BranchDto> branchConsumer) {
- ComponentDto componentDto = insertPrivateProjectWithCustomBranch(organization, branchConsumer, defaults());
+ public ProjectDto insertPrivateProjectDto(Consumer<BranchDto> branchPopulator, Consumer<ComponentDto> componentDtoPopulator,
+ Consumer<ProjectDto> projectDtoPopulator) {
+ ComponentDto componentDto = insertPrivateProjectWithCustomBranch(branchPopulator, componentDtoPopulator, projectDtoPopulator);
return getProjectDto(componentDto);
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public ComponentDto insertPublicProject(OrganizationDto organizationDto, String uuid) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPublicProjectDto(organizationDto, uuid), false);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPrivateProject(OrganizationDto organizationDto, String uuid, Consumer<ComponentDto> dtoPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto, uuid), true, defaults(), dtoPopulator);
+ public final ComponentDto insertPrivateProject(String uuid, Consumer<ComponentDto> dtoPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(uuid), true, defaults(), dtoPopulator);
}
public final ComponentDto insertPrivateProjectWithCustomBranch(String branchKey) {
- return insertPrivateProjectWithCustomBranch(db.getDefaultOrganization(), b -> b.setBranchType(BRANCH).setKey(branchKey), defaults());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPrivateProjectWithCustomBranch(OrganizationDto organizationDto, Consumer<BranchDto> branchPopulator,
- Consumer<ComponentDto> componentPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(organizationDto), true, branchPopulator, componentPopulator);
- }
-
- /**
- * @see #insertPublicPortfolio(java.util.function.Consumer)
- * @deprecated since 6.6
- */
- @Deprecated
- public ComponentDto insertView() {
- return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()), false);
- }
-
- /**
- * @see #insertPublicPortfolio(java.util.function.Consumer)
- * @deprecated since 6.6
- */
- @Deprecated
- public ComponentDto insertView(Consumer<ComponentDto> dtoPopulator) {
- return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization()), false, dtoPopulator);
- }
-
- /**
- * @see #insertPublicPortfolio(java.util.function.Consumer)
- * @deprecated since 6.6
- */
- // TODO remove after getting rid of organization code
- @Deprecated
- public ComponentDto insertView(OrganizationDto organizationDto) {
- return insertComponentImpl(ComponentTesting.newView(organizationDto), false, defaults());
- }
-
- /**
- * @see #insertPublicPortfolio(java.util.function.Consumer)
- * @deprecated since 6.6
- */
- // TODO remove after getting rid of organization code
- @Deprecated
- public ComponentDto insertView(OrganizationDto organizationDto, Consumer<ComponentDto> dtoPopulator) {
- return insertComponentImpl(ComponentTesting.newView(organizationDto), false, dtoPopulator);
+ return insertPrivateProjectWithCustomBranch(b -> b.setBranchType(BRANCH).setKey(branchKey), defaults());
}
- /**
- * @see #insertPublicPortfolio(java.util.function.Consumer)
- * @deprecated since 6.6
- */
- public ComponentDto insertView(String uuid) {
- return insertComponentImpl(ComponentTesting.newView(db.getDefaultOrganization(), uuid), false, defaults());
+ public final ComponentDto insertPrivateProjectWithCustomBranch(Consumer<BranchDto> branchPopulator, Consumer<ComponentDto> componentPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true, branchPopulator, componentPopulator);
}
- /**
- * @see #insertPublicPortfolio(java.util.function.Consumer)
- * @deprecated since 6.6
- */
- // TODO remove after getting rid of organization code
- @Deprecated
- public ComponentDto insertView(OrganizationDto organizationDto, String uuid) {
- return insertComponentImpl(ComponentTesting.newView(organizationDto, uuid), false, defaults());
+ public final ComponentDto insertPrivateProjectWithCustomBranch(Consumer<BranchDto> branchPopulator, Consumer<ComponentDto> componentPopulator,
+ Consumer<ProjectDto> projectPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newPrivateProjectDto(), true, branchPopulator, componentPopulator, projectPopulator);
}
public final ComponentDto insertPublicPortfolio() {
- return insertPublicPortfolio(db.getDefaultOrganization(), defaults());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPublicPortfolio(OrganizationDto organization) {
- return insertPublicPortfolio(organization, defaults());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPublicPortfolio(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
- return insertComponentImpl(ComponentTesting.newView(organization).setPrivate(false), false, dtoPopulator);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPublicPortfolio(OrganizationDto organization, String uuid, Consumer<ComponentDto> dtoPopulator) {
- return insertComponentImpl(ComponentTesting.newView(organization, uuid).setPrivate(false), false, dtoPopulator);
+ return insertPublicPortfolio(defaults());
}
public final ComponentDto insertPublicPortfolio(String uuid, Consumer<ComponentDto> dtoPopulator) {
@@ -334,65 +185,39 @@ public class ComponentDbTester {
}
public final ComponentDto insertPublicApplication() {
- return insertPublicApplication(db.getDefaultOrganization(), defaults());
+ return insertPublicApplication(defaults());
}
public final ComponentDto insertPublicApplication(Consumer<ComponentDto> dtoPopulator) {
- return insertPublicApplication(db.getDefaultOrganization(), dtoPopulator);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPublicApplication(OrganizationDto organization) {
- return insertPublicApplication(organization, defaults());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPublicApplication(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(false), false, defaults(), dtoPopulator);
- }
-
- public final ComponentDto insertPrivateApplication() {
- return insertPrivateApplication(db.getDefaultOrganization());
+ return insertComponentAndBranchAndProject(ComponentTesting.newApplication().setPrivate(false), false, defaults(), dtoPopulator);
}
public final ProjectDto insertPrivateApplicationDto() {
- return getProjectDto(insertPrivateApplication(db.getDefaultOrganization()));
+ return getProjectDto(insertPrivateApplication());
}
public final ProjectDto insertPublicApplicationDto() {
- return getProjectDto(insertPublicApplication(db.getDefaultOrganization()));
+ return getProjectDto(insertPublicApplication());
}
public final ProjectDto insertPrivateApplicationDto(Consumer<ComponentDto> dtoPopulator) {
- return getProjectDto(insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, defaults()));
+ return getProjectDto(insertPrivateApplication(dtoPopulator, defaults()));
}
public final ProjectDto insertPrivateApplicationDto(Consumer<ComponentDto> dtoPopulator, Consumer<ProjectDto> appPopulator) {
- return getProjectDto(insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, appPopulator));
+ return getProjectDto(insertPrivateApplication(dtoPopulator, appPopulator));
}
public final ComponentDto insertPrivateApplication(Consumer<ComponentDto> dtoPopulator) {
- return insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, defaults());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPrivateApplication(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator) {
- return insertPrivateApplication(db.getDefaultOrganization(), dtoPopulator, defaults());
+ return insertPrivateApplication(dtoPopulator, defaults());
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPrivateApplication(OrganizationDto organization) {
- return insertPrivateApplication(organization, defaults(), defaults());
+ public final ComponentDto insertPrivateApplication() {
+ return insertPrivateApplication(defaults(), defaults());
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public final ComponentDto insertPrivateApplication(OrganizationDto organization, Consumer<ComponentDto> dtoPopulator, Consumer<ProjectDto> projectPopulator) {
- return insertComponentAndBranchAndProject(ComponentTesting.newApplication(organization).setPrivate(true), true, defaults(), dtoPopulator, projectPopulator);
+ public final ComponentDto insertPrivateApplication(Consumer<ComponentDto> dtoPopulator, Consumer<ProjectDto> projectPopulator) {
+ return insertComponentAndBranchAndProject(ComponentTesting.newApplication().setPrivate(true), true, defaults(), dtoPopulator, projectPopulator);
}
public final ComponentDto insertSubView(ComponentDto view) {
@@ -539,14 +364,6 @@ public class ComponentDbTester {
return branchDto;
}
- // TODO remove after getting rid of organization code
- @Deprecated
- @SafeVarargs
- public final ComponentDto insertProjectBranch(OrganizationDto organization, Consumer<BranchDto>... dtoPopulators) {
- ComponentDto project = ComponentTesting.newPrivateProjectDto(organization);
- return insertProjectBranch(project, dtoPopulators);
- }
-
public final ComponentDto insertProjectBranch(ProjectDto project, BranchDto branchDto) {
checkArgument(branchDto.getProjectUuid().equals(project.getUuid()));
ComponentDto branch = ComponentTesting.newBranchComponent(project, branchDto);
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
index 4445f7863d8..0a565c03006 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
@@ -217,59 +217,10 @@ public class ComponentTesting {
.setPrivate(false);
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public static ComponentDto newView(OrganizationDto organizationDto) {
- return newView(organizationDto.getUuid(), Uuids.createFast());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public static ComponentDto newView(OrganizationDto organizationDto, String uuid) {
- return newPrivateProjectDto(organizationDto, uuid)
- .setUuid(uuid)
- .setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.VIEW)
- .setPrivate(false);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- private static ComponentDto newView(String organizationUuid, String uuid) {
- return newProjectDto(organizationUuid, uuid, false)
- .setUuid(uuid)
- .setScope(Scopes.PROJECT)
- .setQualifier(Qualifiers.VIEW);
- }
-
public static ComponentDto newApplication() {
return newView(Uuids.createFast()).setQualifier(Qualifiers.APP);
}
- // TODO remove after getting rid of organization code
- @Deprecated
- public static ComponentDto newApplication(OrganizationDto organizationDto) {
- return newApplication(organizationDto.getUuid());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public static ComponentDto newApplication(OrganizationDto organizationDto, String uuid) {
- return newApplication(organizationDto.getUuid(), uuid);
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public static ComponentDto newApplication(String organizationUuid) {
- return newApplication(organizationUuid, Uuids.createFast());
- }
-
- // TODO remove after getting rid of organization code
- @Deprecated
- public static ComponentDto newApplication(String organizationUuid, String uuid) {
- return newView(organizationUuid, uuid).setQualifier(Qualifiers.APP);
- }
-
public static ComponentDto newProjectCopy(ComponentDto project, ComponentDto view) {
return newProjectCopy(Uuids.createFast(), project, view);
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
index e4e8a894188..67db0fd90ea 100644
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
+++ b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/issue/IssueDbTester.java
@@ -30,7 +30,6 @@ import org.sonar.core.issue.FieldDiffs;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.UserDto;
@@ -121,21 +120,13 @@ public class IssueDbTester {
/**
* Inserts an issue.
- */
- @SafeVarargs
- public final IssueDto insertIssue(Consumer<IssueDto>... populateIssueDto) {
- return insertIssue(db.getDefaultOrganization(), populateIssueDto);
- }
-
- /**
- * Inserts an issue.
*
* @throws AssertionError if rule is not Security Hotspot
*/
@SafeVarargs
- public final IssueDto insertIssue(OrganizationDto organizationDto, Consumer<IssueDto>... populators) {
+ public final IssueDto insertIssue(Consumer<IssueDto>... populators) {
RuleDefinitionDto rule = db.rules().insertIssueRule();
- ComponentDto project = db.components().insertPrivateProject(organizationDto);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = newIssue(rule, project, file)
.setType(RULE_TYPES_EXCEPT_HOTSPOTS[new Random().nextInt(RULE_TYPES_EXCEPT_HOTSPOTS.length)]);
@@ -190,17 +181,9 @@ public class IssueDbTester {
* Inserts a Security Hotspot.
*/
@SafeVarargs
- public final IssueDto insertHotspot(Consumer<IssueDto>... populateIssueDto) {
- return insertHotspot(db.getDefaultOrganization(), populateIssueDto);
- }
-
- /**
- * Inserts a Security Hotspot.
- */
- @SafeVarargs
- public final IssueDto insertHotspot(OrganizationDto organizationDto, Consumer<IssueDto>... populators) {
+ public final IssueDto insertHotspot(Consumer<IssueDto>... populators) {
RuleDefinitionDto rule = db.rules().insertHotspotRule();
- ComponentDto project = db.components().insertPrivateProject(organizationDto);
+ ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = newIssue(rule, project, file)
.setType(SECURITY_HOTSPOT)
@@ -231,7 +214,7 @@ public class IssueDbTester {
public void insertFieldDiffs(IssueDto issueDto, FieldDiffs... diffs) {
Arrays.stream(diffs).forEach(diff -> db.getDbClient().issueChangeDao().insert(db.getSession(), IssueChangeDto.of(issueDto.getKey(), diff, issueDto.getProjectUuid())
- .setUuid(Uuids.createFast())));
+ .setUuid(Uuids.createFast())));
db.commit();
}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java
deleted file mode 100644
index 674545c8267..00000000000
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationDbTester.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.db.organization;
-
-import java.util.function.Consumer;
-import javax.annotation.Nullable;
-import org.sonar.db.DbSession;
-import org.sonar.db.DbTester;
-import org.sonar.db.permission.template.DefaultTemplates;
-
-//TODO remove
-@Deprecated
-public class OrganizationDbTester {
- private final DbTester db;
-
- public OrganizationDbTester(DbTester db) {
- this.db = db;
- }
-
- public OrganizationDto getDefaultOrganization() {
- return db.getDefaultOrganization();
- }
-
- /**
- * Insert an {@link OrganizationDto} and commit the session
- */
- public OrganizationDto insert() {
- return insert(OrganizationTesting.newOrganizationDto());
- }
-
- public OrganizationDto insert(Consumer<OrganizationDto> populator) {
- OrganizationDto dto = OrganizationTesting.newOrganizationDto();
- populator.accept(dto);
- return insert(dto);
- }
-
- public OrganizationDto insertForKey(String key) {
- return insert(dto -> dto.setKey(key));
- }
-
- public OrganizationDto insertForUuid(String organizationUuid) {
- return insert(dto -> dto.setUuid(organizationUuid));
- }
-
- /**
- * Insert the provided {@link OrganizationDto} and commit the session
- */
- public OrganizationDto insert(OrganizationDto dto) {
- DbSession dbSession = db.getSession();
- db.getDbClient().organizationDao().insert(dbSession, dto, false);
- dbSession.commit();
- return dto;
- }
-
- public void setDefaultTemplates(String projectDefaultTemplateUuid, @Nullable String applicationDefaultTemplateUuid, @Nullable String portfoliosDefaultTemplateUuid) {
- DbSession dbSession = db.getSession();
- db.getDbClient().organizationDao().setDefaultTemplates(dbSession, db.getDefaultOrganization().getUuid(),
- new DefaultTemplates()
- .setProjectUuid(projectDefaultTemplateUuid)
- .setApplicationsUuid(applicationDefaultTemplateUuid)
- .setPortfoliosUuid(portfoliosDefaultTemplateUuid));
- dbSession.commit();
- }
-}
diff --git a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationTesting.java b/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationTesting.java
deleted file mode 100644
index 23dc2e44722..00000000000
--- a/server/sonar-db-dao/src/testFixtures/java/org/sonar/db/organization/OrganizationTesting.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.db.organization;
-
-import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.sonar.db.organization.OrganizationDto.Subscription.FREE;
-
-public class OrganizationTesting {
-
- private OrganizationTesting() {
- // only statics
- }
-
- /**
- * Creates a new {@link OrganizationDto} with randomly generated field values.
- */
- public static OrganizationDto newOrganizationDto() {
- return new OrganizationDto()
- .setKey(randomAlphanumeric(32))
- .setUuid(randomAlphanumeric(40))
- .setName(randomAlphanumeric(64))
- .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));
- }
-}