aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'server/sonar-db-dao/src/test/java')
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/DaoModuleTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java22
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java47
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java34
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java27
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java10
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/issue/IssueDaoTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java12
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java13
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java172
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java32
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java122
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java43
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java6
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileDaoTest.java45
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java3
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/webhook/WebhookDaoTest.java16
18 files changed, 425 insertions, 190 deletions
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/DaoModuleTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/DaoModuleTest.java
index c3e28196565..20f8df29878 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/DaoModuleTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/DaoModuleTest.java
@@ -30,6 +30,6 @@ public class DaoModuleTest {
public void verify_count_of_added_components() {
ComponentContainer container = new ComponentContainer();
new DaoModule().configure(container);
- assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 65);
+ assertThat(container.size()).isEqualTo(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER + 66);
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
index 09a8f576b5d..474ac89f68f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/setting/ProjectAlmSettingDaoTest.java
@@ -26,7 +26,7 @@ import org.sonar.api.utils.System2;
import org.sonar.core.util.UuidFactory;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
-import org.sonar.db.component.ComponentDto;
+import org.sonar.db.project.ProjectDto;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -54,8 +54,8 @@ public class ProjectAlmSettingDaoTest {
when(uuidFactory.create()).thenReturn(A_UUID);
when(system2.now()).thenReturn(A_DATE);
AlmSettingDto githubAlmSettingDto = db.almSettings().insertGitHubAlmSetting();
- ComponentDto project = db.components().insertPrivateProject();
- ComponentDto anotherProject = db.components().insertPrivateProject();
+ ProjectDto project = db.components().insertPrivateProjectDto();
+ ProjectDto anotherProject = db.components().insertPrivateProjectDto();
ProjectAlmSettingDto githubProjectAlmSettingDto = newGithubProjectAlmSettingDto(githubAlmSettingDto, project);
underTest.insertOrUpdate(dbSession, githubProjectAlmSettingDto);
@@ -63,7 +63,7 @@ public class ProjectAlmSettingDaoTest {
.extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid,
ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug,
ProjectAlmSettingDto::getCreatedAt, ProjectAlmSettingDto::getUpdatedAt)
- .containsExactly(A_UUID, githubAlmSettingDto.getUuid(), project.uuid(),
+ .containsExactly(A_UUID, githubAlmSettingDto.getUuid(), project.getUuid(),
githubProjectAlmSettingDto.getAlmRepo(), githubProjectAlmSettingDto.getAlmSlug(),
A_DATE, A_DATE);
@@ -75,7 +75,7 @@ public class ProjectAlmSettingDaoTest {
when(uuidFactory.create()).thenReturn(A_UUID);
when(system2.now()).thenReturn(A_DATE);
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
- ComponentDto project = db.components().insertPrivateProject();
+ ProjectDto project = db.components().insertPrivateProjectDto();
ProjectAlmSettingDto projectAlmSettingDto = db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project);
AlmSettingDto anotherGithubAlmSetting = db.almSettings().insertGitHubAlmSetting();
@@ -87,7 +87,7 @@ public class ProjectAlmSettingDaoTest {
.extracting(ProjectAlmSettingDto::getUuid, ProjectAlmSettingDto::getAlmSettingUuid, ProjectAlmSettingDto::getProjectUuid,
ProjectAlmSettingDto::getAlmRepo, ProjectAlmSettingDto::getAlmSlug,
ProjectAlmSettingDto::getCreatedAt, ProjectAlmSettingDto::getUpdatedAt)
- .containsExactly(projectAlmSettingDto.getUuid(), anotherGithubAlmSetting.getUuid(), project.uuid(),
+ .containsExactly(projectAlmSettingDto.getUuid(), anotherGithubAlmSetting.getUuid(), project.getUuid(),
newProjectAlmSettingDto.getAlmRepo(), newProjectAlmSettingDto.getAlmSlug(),
A_DATE, A_DATE_LATER);
}
@@ -97,9 +97,9 @@ public class ProjectAlmSettingDaoTest {
when(uuidFactory.create()).thenReturn(A_UUID);
when(system2.now()).thenReturn(A_DATE);
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
- ComponentDto project = db.components().insertPrivateProject();
+ ProjectDto project = db.components().insertPrivateProjectDto();
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project);
- ComponentDto anotherProject = db.components().insertPrivateProject();
+ ProjectDto anotherProject = db.components().insertPrivateProjectDto();
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, anotherProject);
underTest.deleteByProject(dbSession, project);
@@ -113,13 +113,13 @@ public class ProjectAlmSettingDaoTest {
when(uuidFactory.create()).thenReturn(A_UUID);
when(system2.now()).thenReturn(A_DATE);
AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
- ComponentDto project1 = db.components().insertPrivateProject();
- ComponentDto project2 = db.components().insertPrivateProject();
+ ProjectDto project1 = db.components().insertPrivateProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProjectDto();
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project1);
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project2);
AlmSettingDto githubAlmSetting1 = db.almSettings().insertGitHubAlmSetting();
- ComponentDto anotherProject = db.components().insertPrivateProject();
+ ProjectDto anotherProject = db.components().insertPrivateProjectDto();
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting1, anotherProject);
underTest.deleteByAlmSetting(dbSession, githubAlmSetting);
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java
index 593a10efa5a..6ff008db3bd 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/BranchDaoTest.java
@@ -22,6 +22,8 @@ package org.sonar.db.component;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.Rule;
@@ -31,6 +33,7 @@ import org.sonar.api.impl.utils.TestSystem2;
import org.sonar.api.utils.System2;
import org.sonar.db.DbSession;
import org.sonar.db.DbTester;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.protobuf.DbProjectBranches;
import static java.util.Arrays.asList;
@@ -377,6 +380,26 @@ public class BranchDaoTest {
}
@Test
+ public void selectByBranchKeys() {
+ ProjectDto project1 = db.components().insertPrivateProjectDto();
+ ProjectDto project2 = db.components().insertPrivateProjectDto();
+ ProjectDto project3 = db.components().insertPrivateProjectDto();
+
+ BranchDto branch1 = db.components().insertProjectBranch(project1, b -> b.setKey("branch1"));
+ BranchDto branch2 = db.components().insertProjectBranch(project2, b -> b.setKey("branch2"));
+ BranchDto branch3 = db.components().insertProjectBranch(project3, b -> b.setKey("branch3"));
+
+ Map<String, String> branchKeysByProjectUuid = new HashMap<>();
+ branchKeysByProjectUuid.put(project1.getUuid(), "branch1");
+ branchKeysByProjectUuid.put(project2.getUuid(), "branch2");
+ branchKeysByProjectUuid.put(project3.getUuid(), "nonexisting");
+
+ List<BranchDto> branchDtos = underTest.selectByBranchKeys(dbSession, branchKeysByProjectUuid);
+ assertThat(branchDtos).hasSize(2);
+ assertThat(branchDtos).extracting(BranchDto::getUuid).containsExactlyInAnyOrder(branch1.getUuid(), branch2.getUuid());
+ }
+
+ @Test
public void selectByComponent() {
BranchDto mainBranch = new BranchDto();
mainBranch.setProjectUuid("U1");
@@ -452,6 +475,24 @@ public class BranchDaoTest {
}
@Test
+ public void selectByProjectUuid() {
+ ComponentDto project1 = db.components().insertPrivateProject();
+ ComponentDto project2 = db.components().insertPrivateProject();
+
+ ComponentDto branch1 = db.components().insertProjectBranch(project1);
+ ComponentDto branch2 = db.components().insertProjectBranch(project1);
+ ComponentDto branch3 = db.components().insertProjectBranch(project2);
+ ComponentDto branch4 = db.components().insertProjectBranch(project2);
+
+ assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(project1.uuid())))
+ .extracting(BranchDto::getUuid)
+ .containsExactlyInAnyOrder(project1.uuid(), branch1.uuid(), branch2.uuid());
+ assertThat(underTest.selectByProject(dbSession, new ProjectDto().setUuid(project2.uuid())))
+ .extracting(BranchDto::getUuid)
+ .containsExactlyInAnyOrder(project2.uuid(), branch3.uuid(), branch4.uuid());
+ }
+
+ @Test
public void selectByUuid() {
ComponentDto project = db.components().insertPrivateProject();
ComponentDto branch1 = db.components().insertProjectBranch(project);
@@ -460,7 +501,7 @@ public class BranchDaoTest {
assertThat(underTest.selectByUuid(db.getSession(), branch1.uuid()).get())
.extracting(BranchDto::getUuid)
.isEqualTo(branch1.uuid());
- assertThat(underTest.selectByUuid(db.getSession(), project.uuid())).isNotPresent();
+ assertThat(underTest.selectByUuid(db.getSession(), project.uuid())).isPresent();
assertThat(underTest.selectByUuid(db.getSession(), "unknown")).isNotPresent();
}
@@ -485,8 +526,8 @@ public class BranchDaoTest {
ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
ComponentDto pr = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
- assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, 0L)).isEqualTo(2);
- assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, NOW)).isEqualTo(2);
+ assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, 0L)).isEqualTo(3);
+ assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, NOW)).isEqualTo(3);
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.BRANCH, NOW + 100)).isEqualTo(0);
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, 0L)).isEqualTo(1);
assertThat(underTest.countByTypeAndCreationDate(dbSession, BranchType.PULL_REQUEST, NOW)).isEqualTo(1);
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 62177d2dc07..dc4e353c7b0 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
@@ -220,7 +220,7 @@ public class ComponentDaoTest {
@Test
public void selectByKeyAndBranch() {
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch").setBranchType(BRANCH));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
@@ -233,7 +233,7 @@ public class ComponentDaoTest {
@Test
public void selectByKeyAndPullRequest() {
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setKey("my_PR").setBranchType(PULL_REQUEST));
ComponentDto pullRequestNamedAsMainBranch = db.components().insertProjectBranch(project, b -> b.setKey("master").setBranchType(PULL_REQUEST));
@@ -299,7 +299,7 @@ public class ComponentDaoTest {
@Test
public void selectByKeysAndBranch() {
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
ComponentDto file1 = db.components().insertComponent(newFileDto(branch));
ComponentDto file2 = db.components().insertComponent(newFileDto(branch));
@@ -318,9 +318,9 @@ public class ComponentDaoTest {
@Test
public void select_by_keys_and_branches() {
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- ComponentDto application = db.components().insertMainBranch(a -> a.setQualifier(APP));
+ ComponentDto application = db.components().insertPublicProject(a -> a.setQualifier(APP));
ComponentDto applicationBranch = db.components().insertProjectBranch(application, b -> b.setKey("my_branch"));
assertThat(underTest.selectByKeysAndBranches(db.getSession(), ImmutableMap.of(
@@ -1059,7 +1059,7 @@ public class ComponentDaoTest {
@Test
public void select_projects_does_not_return_branches() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project);
assertThat(underTest.selectProjects(dbSession))
@@ -1089,7 +1089,7 @@ public class ComponentDaoTest {
@Test
public void select_projects_by_organization_does_not_return_branches() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertMainBranch(organization);
+ ComponentDto project = db.components().insertPublicProject(organization);
ComponentDto branch = db.components().insertProjectBranch(project);
assertThat(underTest.selectProjectsByOrganization(dbSession, organization.getUuid()))
@@ -1153,7 +1153,7 @@ public class ComponentDaoTest {
// the project does not have any analysis
OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertMainBranch(organization);
+ ComponentDto project = db.components().insertPublicProject(organization);
assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10))
.extracting(ComponentDto::uuid)
.containsOnly(project.uuid());
@@ -1396,7 +1396,7 @@ public class ComponentDaoTest {
"b_enabled as \"bEnabled\", b_uuid_path as \"bUuidPath\", b_language as \"bLanguage\", b_long_name as \"bLongName\"," +
"b_module_uuid as \"bModuleUuid\", b_module_uuid_path as \"bModuleUuidPath\", b_name as \"bName\", " +
"b_path as \"bPath\", b_qualifier as \"bQualifier\" " +
- "from projects where uuid='" + uuid + "'");
+ "from components where uuid='" + uuid + "'");
}
@Test
@@ -1507,7 +1507,7 @@ public class ComponentDaoTest {
@Test
public void selectByQuery_should_not_return_branches() {
- ComponentDto main = db.components().insertMainBranch();
+ ComponentDto main = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(main);
assertThat(underTest.selectByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY, 0, 2)).hasSize(1);
@@ -1516,7 +1516,7 @@ public class ComponentDaoTest {
@Test
public void countByQuery_should_not_include_branches() {
- ComponentDto main = db.components().insertMainBranch();
+ ComponentDto main = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(main);
assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY)).isEqualTo(1);
@@ -1616,12 +1616,12 @@ public class ComponentDaoTest {
long aLongTimeAgo = 1_000_000_000L;
long recentTime = 3_000_000_000L;
// project with only a non-main and old analyzed branch
- ComponentDto oldProject = db.components().insertMainBranch();
+ ComponentDto oldProject = db.components().insertPublicProject();
ComponentDto oldProjectBranch = db.components().insertProjectBranch(oldProject, newBranchDto(oldProject).setBranchType(BRANCH));
db.components().insertSnapshot(oldProjectBranch, s -> s.setLast(true).setCreatedAt(aLongTimeAgo));
// project with only a old main branch and a recent non-main branch
- ComponentDto recentProject = db.components().insertMainBranch();
+ ComponentDto recentProject = db.components().insertPublicProject();
ComponentDto recentProjectBranch = db.components().insertProjectBranch(recentProject, newBranchDto(recentProject).setBranchType(BRANCH));
db.components().insertSnapshot(recentProjectBranch, s -> s.setCreatedAt(recentTime).setLast(true));
db.components().insertSnapshot(recentProjectBranch, s -> s.setCreatedAt(aLongTimeAgo).setLast(false));
@@ -1966,20 +1966,20 @@ public class ComponentDaoTest {
OrganizationDto organizationDto = db.organizations().insert();
// project1, not the biggest branch - not returned
- final ComponentDto project1 = db.components().insertMainBranch(organizationDto, b -> b.setName("foo"));
+ final ComponentDto project1 = db.components().insertPrivateProject(organizationDto, 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().insertMainBranch(organizationDto, b -> b.setName("bar")), metric);
+ insertMeasure(10d, db.components().insertPrivateProject(organizationDto, b -> b.setName("bar")), metric);
// public project - not returned
- insertMeasure(11d, db.components().insertMainBranch(organizationDto, b -> b.setPrivate(false)), metric);
+ insertMeasure(11d, db.components().insertPublicProject(organizationDto, b -> b.setPrivate(false)), metric);
// different org - not returned
- insertMeasure(12d, db.components().insertMainBranch(db.organizations().insert()), metric);
+ insertMeasure(12d, db.components().insertPrivateProject(db.organizations().insert()), metric);
List<ProjectNclocDistributionDto> result = underTest.selectPrivateProjectsWithNcloc(db.getSession(), organizationDto.getUuid());
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 df714521170..085f07a8139 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
@@ -20,6 +20,7 @@
package org.sonar.db.component;
import com.google.common.base.Strings;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -63,7 +64,7 @@ public class ComponentKeyUpdaterDaoTest {
underTest.updateKey(dbSession, "B", "struts:core");
dbSession.commit();
- assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects"))
+ assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from components"))
.extracting(t -> t.get("UUID"), t -> t.get("KEE"))
.containsOnly(
Tuple.tuple("A", "org.struts:struts"),
@@ -101,7 +102,7 @@ public class ComponentKeyUpdaterDaoTest {
@Test
public void updateKey_updates_branches_too() {
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project);
db.components().insertComponent(newFileDto(branch));
db.components().insertComponent(newFileDto(branch));
@@ -122,13 +123,13 @@ public class ComponentKeyUpdaterDaoTest {
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1);
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount);
- db.select(dbSession, "select kee from projects")
+ db.select(dbSession, "select kee from components")
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey)));
}
@Test
public void updateKey_updates_pull_requests_too() {
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
db.components().insertComponent(newFileDto(pullRequest));
db.components().insertComponent(newFileDto(pullRequest));
@@ -149,13 +150,13 @@ public class ComponentKeyUpdaterDaoTest {
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1);
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount);
- db.select(dbSession, "select kee from projects")
+ db.select(dbSession, "select kee from components")
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey)));
}
@Test
public void bulk_updateKey_updates_branches_too() {
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project);
ComponentDto module = db.components().insertComponent(prefixDbKeyWithKey(newModuleDto(branch), project.getKey()));
ComponentDto file1 = db.components().insertComponent(prefixDbKeyWithKey(newFileDto(module), module.getKey()));
@@ -177,7 +178,7 @@ public class ComponentKeyUpdaterDaoTest {
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1);
String newBranchKey = ComponentDto.generateBranchKey(newProjectKey, branch.getBranch());
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newBranchKey)).hasSize(branchComponentCount);
- db.select(dbSession, "select kee from projects")
+ db.select(dbSession, "select kee from components")
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey)));
assertThat(rekeyedResources)
@@ -193,7 +194,7 @@ public class ComponentKeyUpdaterDaoTest {
@Test
public void bulk_updateKey_on_branch_containing_slash() {
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch/with/slash"));
String newKey = "newKey";
@@ -205,7 +206,7 @@ public class ComponentKeyUpdaterDaoTest {
@Test
public void bulk_updateKey_updates_pull_requests_too() {
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST));
ComponentDto module = db.components().insertComponent(prefixDbKeyWithKey(newModuleDto(pullRequest), project.getKey()));
ComponentDto file1 = db.components().insertComponent(prefixDbKeyWithKey(newFileDto(module), module.getKey()));
@@ -227,7 +228,7 @@ public class ComponentKeyUpdaterDaoTest {
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newProjectKey)).hasSize(1);
assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newPullRequestKey)).hasSize(branchComponentCount);
- db.select(dbSession, "select kee from projects")
+ db.select(dbSession, "select kee from components")
.forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey)));
assertThat(rekeyedResources)
@@ -277,7 +278,7 @@ public class ComponentKeyUpdaterDaoTest {
underTest.bulkUpdateKey(dbSession, "A", "org.struts", "org.apache.struts", doNotReturnAnyRekeyedResource());
dbSession.commit();
- assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects"))
+ assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from components"))
.extracting(t -> t.get("UUID"), t -> t.get("KEE"))
.containsOnly(
Tuple.tuple("A", "org.apache.struts:struts"),
@@ -297,7 +298,7 @@ public class ComponentKeyUpdaterDaoTest {
underTest.bulkUpdateKey(dbSession, "A", "struts-ui", "struts-web", doNotReturnAnyRekeyedResource());
dbSession.commit();
- assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects"))
+ assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from components"))
.extracting(t -> t.get("UUID"), t -> t.get("KEE"))
.containsOnly(
Tuple.tuple("A", "org.struts:struts"),
@@ -336,7 +337,7 @@ public class ComponentKeyUpdaterDaoTest {
underTest.bulkUpdateKey(dbSession, "A", "org.struts", "org.apache.struts", doNotReturnAnyRekeyedResource());
dbSession.commit();
- assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from projects"))
+ assertThat(db.select("select uuid as \"UUID\", kee as \"KEE\" from components"))
.extracting(t -> t.get("UUID"), t -> t.get("KEE"))
.containsOnly(
Tuple.tuple("A", "org.apache.struts:struts"),
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 915d14a8d22..13510666665 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
@@ -280,9 +280,9 @@ public class SnapshotDaoTest {
public void selectFinishedByComponentUuidsAndFromDates() {
long from = 1_500_000_000_000L;
long otherFrom = 1_200_000_000_000L;
- ComponentDto firstProject = db.components().insertMainBranch();
- ComponentDto secondProject = db.components().insertMainBranch();
- ComponentDto thirdProject = db.components().insertMainBranch();
+ ComponentDto firstProject = db.components().insertPublicProject();
+ ComponentDto secondProject = db.components().insertPublicProject();
+ ComponentDto thirdProject = db.components().insertPublicProject();
SnapshotDto finishedAnalysis = db.components().insertSnapshot(firstProject, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from));
insertActivity(firstProject.uuid(), finishedAnalysis, SUCCESS);
SnapshotDto otherFinishedAnalysis = db.components().insertSnapshot(firstProject, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from + 1_000_000L));
@@ -305,7 +305,7 @@ public class SnapshotDaoTest {
@Test
public void selectFinishedByComponentUuidsAndFromDates_returns_processed_analysis_even_if_analysis_failed() {
long from = 1_500_000_000_000L;
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
SnapshotDto unprocessedAnalysis = db.components().insertSnapshot(project, s -> s.setStatus(STATUS_UNPROCESSED).setCreatedAt(from + 1_000_000L));
insertActivity(project.uuid(), unprocessedAnalysis, CANCELED);
SnapshotDto finishedAnalysis = db.components().insertSnapshot(project, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from));
@@ -322,7 +322,7 @@ public class SnapshotDaoTest {
@Test
public void selectFinishedByComponentUuidsAndFromDates_return_branches_analysis() {
long from = 1_500_000_000_000L;
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto firstBranch = db.components().insertProjectBranch(project);
ComponentDto secondBranch = db.components().insertProjectBranch(project);
SnapshotDto finishedAnalysis = db.components().insertSnapshot(firstBranch, s -> s.setStatus(STATUS_PROCESSED).setCreatedAt(from));
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 8d661bed97b..04bf2a024f0 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
@@ -193,7 +193,7 @@ public class IssueDaoTest {
@Test
public void selectOpenByComponentUuid() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto projectBranch = db.components().insertProjectBranch(project,
b -> b.setKey("feature/foo")
.setBranchType(BranchType.BRANCH));
@@ -215,7 +215,7 @@ public class IssueDaoTest {
@Test
public void selectOpenByComponentUuid_should_correctly_map_required_fields() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto projectBranch = db.components().insertProjectBranch(project,
b -> b.setKey("feature/foo")
.setBranchType(BranchType.BRANCH));
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 9654923a561..68249a2595e 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
@@ -274,15 +274,15 @@ public class LiveMeasureDaoTest {
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().insertMainBranch(organization);
+ ComponentDto simpleProject = db.components().insertPublicProject(organization);
db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d));
- ComponentDto projectWithBiggerBranch = db.components().insertMainBranch(organization);
+ ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(organization);
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().insertMainBranch(organization);
+ ComponentDto projectWithLinesButNoLoc = db.components().insertPublicProject(organization);
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d));
db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d));
@@ -313,15 +313,15 @@ public class LiveMeasureDaoTest {
OrganizationDto organization = db.organizations().insert();
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
- ComponentDto simpleProject = db.components().insertMainBranch(organization);
+ ComponentDto simpleProject = db.components().insertPublicProject(organization);
db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d));
- ComponentDto projectWithBiggerBranch = db.components().insertMainBranch(organization);
+ ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(organization);
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().insertMainBranch(organization);
+ ComponentDto projectToExclude = db.components().insertPublicProject(organization);
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/ProjectMeasuresIndexerIteratorTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/ProjectMeasuresIndexerIteratorTest.java
index 45d915148eb..770738e9106 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
@@ -22,6 +22,7 @@ package org.sonar.db.measure;
import com.google.common.collect.Maps;
import java.util.Map;
import javax.annotation.Nullable;
+import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -206,7 +207,7 @@ public class ProjectMeasuresIndexerIteratorTest {
@Test
public void return_project_without_analysis() {
- ComponentDto project = dbTester.components().insertComponent(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
+ ComponentDto project = dbTester.components().insertPrivateProject(ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert()));
dbClient.snapshotDao().insert(dbSession, newAnalysis(project).setLast(false));
dbSession.commit();
@@ -218,6 +219,8 @@ public class ProjectMeasuresIndexerIteratorTest {
}
@Test
+ @Ignore
+ //TODO
public void does_not_return_non_active_projects() {
OrganizationDto organization = dbTester.organizations().insert();
// Disabled project
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
index 4a78c097d2c..d6fa90971d9 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/organization/OrganizationDaoTest.java
@@ -308,7 +308,7 @@ public class OrganizationDaoTest {
assertThat(underTest.selectByUuids(
dbSession,
of(ORGANIZATION_DTO_1.getUuid().toUpperCase(Locale.ENGLISH), ORGANIZATION_DTO_2.getUuid().toUpperCase(Locale.ENGLISH))))
- .isEmpty();
+ .isEmpty();
}
@Test
@@ -333,7 +333,7 @@ public class OrganizationDaoTest {
insertOrganization(ORGANIZATION_DTO_1);
insertOrgAlmBinding(ORGANIZATION_DTO_1, GITHUB, "123456");
- assertThat(underTest.selectByOrganizationAlmId(dbSession, GITHUB,"unknown")).isEmpty();
+ assertThat(underTest.selectByOrganizationAlmId(dbSession, GITHUB, "unknown")).isEmpty();
}
@Test
@@ -1027,12 +1027,11 @@ public class OrganizationDaoTest {
OrganizationDto org1 = db.organizations().insert();
// private project with highest ncloc in non-main branch
- ComponentDto project1 = db.components().insertMainBranch(org1);
+ ComponentDto project1 = db.components().insertPrivateProject(org1);
ComponentDto project1Branch = db.components().insertProjectBranch(project1);
db.measures().insertLiveMeasure(project1, ncloc, m -> m.setValue(1_000.0));
db.measures().insertLiveMeasure(project1Branch, ncloc, m -> m.setValue(110_000.0));
-
// public project that must be ignored
ComponentDto project2 = db.components().insertPublicProject(org1);
ComponentDto project2Branch = db.components().insertProjectBranch(project2);
@@ -1213,15 +1212,15 @@ public class OrganizationDaoTest {
private int insertPrivateProjectsWithBranches(OrganizationDto org, MetricDto ncloc) {
// private project
- ComponentDto project1 = db.components().insertMainBranch(org);
+ ComponentDto project1 = db.components().insertPrivateProject(org);
return Math.max(
// Create the ncloc on main branch
insertLiveMeasures(project1, ncloc, 0),
// Create 5 branches and set the ncloc on them
IntStream.range(1, 5)
- .map(i -> insertLiveMeasures(db.components().insertProjectBranch(project1), ncloc, 0))
- .max().orElse(0)
+ .map(i -> insertLiveMeasures(db.components().insertProjectBranch(project1), ncloc, 0))
+ .max().orElse(0)
);
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
new file mode 100644
index 00000000000..e35a0852c27
--- /dev/null
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
@@ -0,0 +1,172 @@
+/*
+ * 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.project;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import javax.annotation.Nullable;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ProjectDaoTest {
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private System2 system2 = new AlwaysIncreasingSystem2(1000L);
+
+ @Rule
+ public DbTester db = DbTester.create(system2);
+
+ private ProjectDao projectDao = new ProjectDao();
+
+ @Test
+ public void should_insert_and_select_by_uuid() {
+ ProjectDto dto = createProject("o1", "p1");
+
+ projectDao.insert(db.getSession(), dto);
+
+ Optional<ProjectDto> projectByUuid = projectDao.selectByUuid(db.getSession(), "uuid_o1_p1");
+ assertThat(projectByUuid).isPresent();
+ assertProject(projectByUuid.get(), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2");
+ assertThat(projectByUuid.get().isPrivate()).isTrue();
+ }
+
+ @Test
+ public void select_project_by_key() {
+ ProjectDto dto = createProject("o1", "p1");
+
+ projectDao.insert(db.getSession(), dto);
+
+ Optional<ProjectDto> projectByKee = projectDao.selectProjectByKey(db.getSession(), "projectKee_o1_p1");
+ assertThat(projectByKee).isPresent();
+ assertProject(projectByKee.get(), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2");
+ }
+
+ @Test
+ public void select_projects() {
+ ProjectDto dto1 = createProject("o1", "p1");
+ ProjectDto dto2 = createProject("o1", "p2");
+
+ projectDao.insert(db.getSession(), dto1);
+ projectDao.insert(db.getSession(), dto2);
+
+ List<ProjectDto> projects = projectDao.selectProjects(db.getSession());
+ assertThat(projects).extracting(ProjectDto::getKey).containsExactlyInAnyOrder("projectKee_o1_p1", "projectKee_o1_p2");
+ }
+
+ @Test
+ public void select_by_organization_uuid() {
+ ProjectDto dto1 = createProject("o1", "p1");
+ ProjectDto dto2 = createProject("o1", "p2");
+ ProjectDto dto3 = createProject("o2", "p1");
+
+ projectDao.insert(db.getSession(), dto1);
+ projectDao.insert(db.getSession(), dto2);
+ projectDao.insert(db.getSession(), dto3);
+
+ List<ProjectDto> projectsByOrg = projectDao.selectByOrganizationUuid(db.getSession(), "org_o1");
+ assertThat(projectsByOrg).hasSize(2);
+ assertProject(projectsByOrg.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2");
+ assertProject(projectsByOrg.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2");
+ }
+
+ @Test
+ public void update_tags() {
+ ProjectDto dto1 = createProject("o1", "p1").setTagsString("");
+ ProjectDto dto2 = createProject("o1", "p2").setTagsString("tag1,tag2");
+
+ projectDao.insert(db.getSession(), dto1);
+ projectDao.insert(db.getSession(), dto2);
+
+ List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
+ assertThat(projectsByUuids).hasSize(2);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", null);
+ assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2");
+
+ dto1.setTags(Collections.singletonList("tag3"));
+ dto2.setTagsString("");
+ projectDao.updateTags(db.getSession(), dto1);
+ projectDao.updateTags(db.getSession(), dto2);
+
+ projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
+ assertThat(projectsByUuids).hasSize(2);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag3");
+ assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", null);
+
+ assertThat(projectsByUuids.get(0).getTags()).containsOnly("tag3");
+ }
+
+ @Test
+ public void select_by_uuids() {
+ ProjectDto dto1 = createProject("o1", "p1");
+ ProjectDto dto2 = createProject("o1", "p2");
+ ProjectDto dto3 = createProject("o1", "p3");
+
+ projectDao.insert(db.getSession(), dto1);
+ projectDao.insert(db.getSession(), dto2);
+ projectDao.insert(db.getSession(), dto3);
+
+ List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
+ assertThat(projectsByUuids).hasSize(2);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "org_o1", "uuid_o1_p1", "desc_p1", "tag1,tag2");
+ assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "org_o1", "uuid_o1_p2", "desc_p2", "tag1,tag2");
+ }
+
+ @Test
+ public void select_empty_by_uuids() {
+ ProjectDto dto1 = createProject("o1", "p1");
+ ProjectDto dto2 = createProject("o1", "p2");
+ ProjectDto dto3 = createProject("o1", "p3");
+
+ projectDao.insert(db.getSession(), dto1);
+ projectDao.insert(db.getSession(), dto2);
+ projectDao.insert(db.getSession(), dto3);
+
+ List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), Collections.emptySet());
+ assertThat(projectsByUuids).hasSize(0);
+ }
+
+ private void assertProject(ProjectDto dto, String name, String kee, String org, String uuid, String desc, @Nullable String tags) {
+ assertThat(dto).extracting("name", "kee", "key", "organizationUuid", "uuid", "description", "tagsString")
+ .containsExactly(name, kee, kee, org, uuid, desc, tags);
+ }
+
+ private ProjectDto createProject(String org, String name) {
+ return new ProjectDto()
+ .setName("projectName_" + name)
+ .setKey("projectKee_" + org + "_" + name)
+ .setQualifier(Qualifiers.PROJECT)
+ .setOrganizationUuid("org_" + org)
+ .setUuid("uuid_" + org + "_" + name)
+ .setTags(Arrays.asList("tag1", "tag2"))
+ .setDescription("desc_" + name)
+ .setPrivate(true);
+ }
+}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
index 8657b4701c3..25b723c7088 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
@@ -29,7 +29,6 @@ import java.util.function.Consumer;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import org.junit.After;
-import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -49,6 +48,7 @@ import org.sonar.db.newcodeperiod.NewCodePeriodType;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
import org.sonar.db.permission.OrganizationPermission;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.GroupDto;
import org.sonar.db.user.UserDto;
@@ -82,11 +82,6 @@ public class PurgeCommandsTest {
dbTester.executeUpdateSql("DELETE FROM analysis_properties");
}
- @Before
- public void setUp() {
-
- }
-
/**
* Test that SQL queries execution do not fail with a huge number of parameter
*/
@@ -218,7 +213,30 @@ public class PurgeCommandsTest {
underTest.deleteComponents(component.uuid());
+ assertThat(dbTester.countRowsOfTable("components")).isZero();
+ assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable("events")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1);
+ }
+
+ @Test
+ public void deleteProjects() {
+ ComponentDto project = dbTester.components().insertPrivateProject();
+ ProjectDto projectDto = dbTester.getDbClient().projectDao().selectProjectByKey(dbTester.getSession(), project.getDbKey()).get();
+ ComponentDto file = dbTester.components().insertComponent(newFileDto(project));
+ SnapshotDto analysis = dbTester.components().insertSnapshot(project);
+ dbTester.events().insertEvent(analysis);
+ IssueDto issue = dbTester.issues().insert(dbTester.rules().insert(), project, file);
+ dbTester.issues().insertChange(issue);
+
+ assertThat(dbTester.countRowsOfTable("projects")).isOne();
+
+ underTest.deleteComponents(project.uuid());
+ underTest.deleteProject(project.uuid());
+
assertThat(dbTester.countRowsOfTable("projects")).isZero();
+ assertThat(dbTester.countRowsOfTable("components")).isZero();
assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("events")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1);
@@ -644,7 +662,7 @@ public class PurgeCommandsTest {
}
private int countComponentOfRoot(ComponentDto projectOrView) {
- return dbTester.countSql("select count(1) from projects where project_uuid='" + projectOrView.uuid() + "'");
+ return dbTester.countSql("select count(1) from components where project_uuid='" + projectOrView.uuid() + "'");
}
private void insertDuplication(ComponentDto project, SnapshotDto analysis) {
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 2bf42aee206..67288494451 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
@@ -75,6 +75,7 @@ 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;
import org.sonar.db.source.FileSourceDto;
@@ -140,7 +141,7 @@ public class PurgeDaoTest {
public void purge_inactive_branches() {
when(system2.now()).thenReturn(new Date().getTime());
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch1 = db.components().insertProjectBranch(project);
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
@@ -157,14 +158,15 @@ public class PurgeDaoTest {
underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, project.uuid(), project.uuid()), PurgeListener.EMPTY, new PurgeProfiler());
dbSession.commit();
- assertThat(uuidsIn("projects")).containsOnly(project.uuid(), branch1.uuid(), branch2.uuid());
+ assertThat(uuidsIn("components")).containsOnly(project.uuid(), branch1.uuid(), branch2.uuid());
+ assertThat(uuidsIn("projects")).containsOnly(project.uuid());
}
@Test
public void purge_inactive_pull_request() {
when(system2.now()).thenReturn(new Date().getTime());
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto nonMainBranch = db.components().insertProjectBranch(project);
ComponentDto recentPullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
@@ -181,14 +183,15 @@ public class PurgeDaoTest {
underTest.purge(dbSession, newConfigurationWith30Days(System2.INSTANCE, project.uuid(), project.uuid()), PurgeListener.EMPTY, new PurgeProfiler());
dbSession.commit();
- assertThat(uuidsIn("projects")).containsOnly(project.uuid(), nonMainBranch.uuid(), recentPullRequest.uuid());
+ assertThat(uuidsIn("components")).containsOnly(project.uuid(), nonMainBranch.uuid(), recentPullRequest.uuid());
+ assertThat(uuidsIn("projects")).containsOnly(project.uuid());
}
@Test
public void purge_inactive_branches_when_analyzing_non_main_branch() {
when(system2.now()).thenReturn(new Date().getTime());
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto nonMainBranch = db.components().insertProjectBranch(project);
when(system2.now()).thenReturn(DateUtils.addDays(new Date(), -31).getTime());
@@ -208,7 +211,8 @@ public class PurgeDaoTest {
dbSession.commit();
// branch1 wasn't deleted since it was being analyzed!
- assertThat(uuidsIn("projects")).containsOnly(project.uuid(), nonMainBranch.uuid(), branch1.uuid());
+ assertThat(uuidsIn("components")).containsOnly(project.uuid(), nonMainBranch.uuid(), branch1.uuid());
+ assertThat(uuidsIn("projects")).containsOnly(project.uuid());
}
@Test
@@ -249,16 +253,10 @@ public class PurgeDaoTest {
tuple(metricWithoutHistory.getId(), otherOldAnalysis.getUuid()));
}
- private Stream<Long> idsOf(String tableName) {
- return db.select("select id as \"ID\" from " + tableName)
- .stream()
- .map(t -> (Long) t.get("ID"));
- }
-
@Test
public void close_issues_clean_index_and_file_sources_of_disabled_components_specified_by_uuid_in_configuration() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
db.components().insertSnapshot(project);
db.components().insertSnapshot(project);
db.components().insertSnapshot(project, s -> s.setLast(false));
@@ -374,7 +372,7 @@ public class PurgeDaoTest {
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectA, null);
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectB, null);
BranchDto branchProjectA = newBranchDto(referencedProjectA);
- ComponentDto cptBranchProjectA = ComponentTesting.newProjectBranch(referencedProjectA, branchProjectA);
+ ComponentDto cptBranchProjectA = ComponentTesting.newBranchComponent(referencedProjectA, branchProjectA);
db.events().insertEventComponentChanges(projectEvent2, projectAnalysis2, randomChangeCategory(), cptBranchProjectA, branchProjectA);
// note: projectEvent3 has no component change
@@ -473,7 +471,7 @@ public class PurgeDaoTest {
@Test
public void selectPurgeableAnalyses_does_not_return_the_baseline() {
- ComponentDto project1 = db.components().insertMainBranch(db.getDefaultOrganization(), "master");
+ ComponentDto project1 = db.components().insertPublicProject(db.getDefaultOrganization(), "master");
SnapshotDto analysis1 = db.components().insertSnapshot(newSnapshot()
.setComponentUuid(project1.uuid())
.setStatus(STATUS_PROCESSED)
@@ -499,7 +497,7 @@ public class PurgeDaoTest {
@Test
public void selectPurgeableAnalyses_does_not_return_the_baseline_of_specific_branch() {
- ComponentDto project = db.components().insertMainBranch(db.getDefaultOrganization(), "master");
+ ComponentDto project = db.components().insertPublicProject(db.getDefaultOrganization(), "master");
SnapshotDto analysisProject = db.components().insertSnapshot(newSnapshot()
.setComponentUuid(project.uuid())
.setStatus(STATUS_PROCESSED)
@@ -563,7 +561,8 @@ public class PurgeDaoTest {
underTest.deleteProject(dbSession, project.uuid());
dbSession.commit();
- assertThat(uuidsIn("projects")).containsOnly(otherProject.uuid(), otherModule.uuid(), otherDirectory.uuid(), otherFile.uuid());
+ assertThat(uuidsIn("components")).containsOnly(otherProject.uuid(), otherModule.uuid(), otherDirectory.uuid(), otherFile.uuid());
+ assertThat(uuidsIn("projects")).containsOnly(otherProject.uuid());
assertThat(uuidsIn("snapshots")).containsOnly(otherAnalysis.getUuid());
assertThat(uuidsIn("issues", "kee")).containsOnly(otherIssue1.getKey(), otherIssue2.getKey());
assertThat(uuidsIn("issue_changes", "kee")).containsOnly(otherIssueChange1.getKey());
@@ -573,21 +572,17 @@ public class PurgeDaoTest {
@Test
public void delete_webhooks_from_project() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto project1 = db.components().insertPrivateProject(organization);
+ ProjectDto project1 = db.components().insertPrivateProjectDto(organization);
WebhookDto webhook = db.webhooks().insertWebhook(project1);
db.webhookDelivery().insert(webhook);
- ComponentDto projectNotToBeDeleted = db.components().insertPrivateProject(organization);
+ ProjectDto projectNotToBeDeleted = db.components().insertPrivateProjectDto(organization);
WebhookDto webhookNotDeleted = db.webhooks().insertWebhook(projectNotToBeDeleted);
WebhookDeliveryLiteDto webhookDeliveryNotDeleted = db.webhookDelivery().insert(webhookNotDeleted);
- underTest.deleteProject(dbSession, project1.uuid());
+ underTest.deleteProject(dbSession, project1.getUuid());
- assertThat(db.select(db.getSession(), "select uuid as \"uuid\" from webhooks"))
- .extracting(m -> m.get("uuid"))
- .containsExactlyInAnyOrder(webhookNotDeleted.getUuid());
- assertThat(db.select(db.getSession(), "select uuid as \"uuid\" from webhook_deliveries"))
- .extracting(m -> m.get("uuid"))
- .containsExactlyInAnyOrder(webhookDeliveryNotDeleted.getUuid());
+ assertThat(uuidsIn("webhooks")).containsOnly(webhookNotDeleted.getUuid());
+ assertThat(uuidsIn("webhook_deliveries")).containsOnly(webhookDeliveryNotDeleted.getUuid());
}
private Stream<String> uuidsOfTable(String tableName) {
@@ -618,8 +613,8 @@ public class PurgeDaoTest {
@Test
public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_activity_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
- ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
+ ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
+ ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
@@ -650,8 +645,8 @@ public class PurgeDaoTest {
@Test
public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_activity_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
- ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
+ ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
+ ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
@@ -682,8 +677,8 @@ public class PurgeDaoTest {
@Test
public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_activity_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
- ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
+ ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
+ ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
@@ -714,8 +709,8 @@ public class PurgeDaoTest {
@Test
public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_activity_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
- ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
+ ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
+ ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
@@ -765,8 +760,8 @@ public class PurgeDaoTest {
@Test
public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_queue_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
- ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
+ ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
+ ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
@@ -797,8 +792,8 @@ public class PurgeDaoTest {
@Test
public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_queue_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
- ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
+ ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
+ ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
@@ -830,8 +825,8 @@ public class PurgeDaoTest {
@Test
public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_queue_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
- ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
+ ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
+ ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
@@ -863,8 +858,8 @@ public class PurgeDaoTest {
@Test
public void delete_row_in_ce_task_message_referring_to_a_row_in_ce_queue_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
- ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
+ ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
+ ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
@@ -896,8 +891,8 @@ public class PurgeDaoTest {
@Test
public void delete_row_in_events_and_event_component_changes_when_deleting_project() {
ComponentDto project = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
- ComponentDto branch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
- ComponentDto anotherBranch = ComponentTesting.newProjectBranch(project, newBranchDto(project));
+ ComponentDto branch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
+ ComponentDto anotherBranch = ComponentTesting.newBranchComponent(project, newBranchDto(project));
ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject);
SnapshotDto projectAnalysis1 = db.components().insertSnapshot(project);
@@ -918,7 +913,7 @@ public class PurgeDaoTest {
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectA, null);
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectB, null);
BranchDto branchProjectA = newBranchDto(referencedProjectA);
- ComponentDto cptBranchProjectA = ComponentTesting.newProjectBranch(referencedProjectA, branchProjectA);
+ ComponentDto cptBranchProjectA = ComponentTesting.newBranchComponent(referencedProjectA, branchProjectA);
db.events().insertEventComponentChanges(projectEvent2, projectAnalysis2, randomChangeCategory(), cptBranchProjectA, branchProjectA);
// note: projectEvent3 has no component change
db.events().insertEventComponentChanges(branchEvent1, branchAnalysis1, randomChangeCategory(), referencedProjectB, null);
@@ -957,7 +952,7 @@ public class PurgeDaoTest {
private ComponentDto insertProjectWithBranchAndRelatedData() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project);
ComponentDto module = db.components().insertComponent(newModuleDto(branch));
ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
@@ -971,19 +966,19 @@ public class PurgeDaoTest {
@Test
public void delete_branch_content_when_deleting_project() {
ComponentDto anotherLivingProject = insertProjectWithBranchAndRelatedData();
- int projectEntryCount = db.countRowsOfTable("projects");
+ int projectEntryCount = db.countRowsOfTable("components");
int issueCount = db.countRowsOfTable("issues");
int branchCount = db.countRowsOfTable("project_branches");
ComponentDto projectToDelete = insertProjectWithBranchAndRelatedData();
- assertThat(db.countRowsOfTable("projects")).isGreaterThan(projectEntryCount);
+ assertThat(db.countRowsOfTable("components")).isGreaterThan(projectEntryCount);
assertThat(db.countRowsOfTable("issues")).isGreaterThan(issueCount);
assertThat(db.countRowsOfTable("project_branches")).isGreaterThan(branchCount);
underTest.deleteProject(dbSession, projectToDelete.uuid());
dbSession.commit();
- assertThat(db.countRowsOfTable("projects")).isEqualTo(projectEntryCount);
+ assertThat(db.countRowsOfTable("components")).isEqualTo(projectEntryCount);
assertThat(db.countRowsOfTable("issues")).isEqualTo(issueCount);
assertThat(db.countRowsOfTable("project_branches")).isEqualTo(branchCount);
}
@@ -1001,7 +996,7 @@ public class PurgeDaoTest {
underTest.deleteProject(dbSession, view.uuid());
dbSession.commit();
- assertThat(uuidsIn("projects"))
+ assertThat(uuidsIn("components"))
.containsOnly(project.uuid(), otherView.uuid(), otherSubView.uuid(), otherProjectCopy.uuid());
}
@@ -1052,7 +1047,7 @@ public class PurgeDaoTest {
@Test
public void should_delete_old_closed_issues() {
RuleDefinitionDto rule = db.rules().insert();
- ComponentDto project = db.components().insertMainBranch();
+ ComponentDto project = db.components().insertPublicProject();
ComponentDto module = db.components().insertComponent(newModuleDto(project));
ComponentDto file = db.components().insertComponent(newFileDto(module));
@@ -1083,7 +1078,7 @@ public class PurgeDaoTest {
@Test
public void delete_disabled_components_without_issues() {
- ComponentDto project = db.components().insertMainBranch(p -> p.setEnabled(true));
+ ComponentDto project = db.components().insertPublicProject(p -> p.setEnabled(true));
ComponentDto enabledFileWithIssues = db.components().insertComponent(newFileDto(project).setEnabled(true));
ComponentDto disabledFileWithIssues = db.components().insertComponent(newFileDto(project).setEnabled(false));
ComponentDto enabledFileWithoutIssues = db.components().insertComponent(newFileDto(project).setEnabled(true));
@@ -1175,7 +1170,7 @@ public class PurgeDaoTest {
@Test
public void delete_ce_analysis_older_than_180_and_scanner_context_older_than_40_days_of_project_and_branches_when_purging_project() {
LocalDateTime now = LocalDateTime.now();
- ComponentDto project1 = db.components().insertMainBranch();
+ ComponentDto project1 = db.components().insertPublicProject();
ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setExcludeFromPurge(true));
Consumer<CeQueueDto> belongsToProject1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(project1.uuid());
Consumer<CeQueueDto> belongsToBranch1 = t -> t.setMainComponentUuid(project1.uuid()).setComponentUuid(branch1.uuid());
@@ -1378,7 +1373,7 @@ public class PurgeDaoTest {
}
@Test
- public void deleteNonRootComponents_deletes_only_non_root_components_of_a_project_from_table_PROJECTS() {
+ public void deleteNonRootComponents_deletes_only_non_root_components_of_a_project_from_table_components() {
ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject() : db.components().insertPrivateProject();
ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1));
@@ -1397,12 +1392,12 @@ public class PurgeDaoTest {
underTest.deleteNonRootComponentsInView(dbSession, components);
- assertThat(uuidsIn("projects"))
+ assertThat(uuidsIn(" components"))
.containsOnly(project.uuid());
}
@Test
- public void deleteNonRootComponents_deletes_only_non_root_components_of_a_view_from_table_PROJECTS() {
+ public void deleteNonRootComponents_deletes_only_non_root_components_of_a_view_from_table_components() {
ComponentDto[] projects = {
db.components().insertPrivateProject(),
db.components().insertPrivateProject(),
@@ -1423,12 +1418,12 @@ public class PurgeDaoTest {
underTest.deleteNonRootComponentsInView(dbSession, components);
- assertThat(uuidsIn("projects"))
+ assertThat(uuidsIn(" components"))
.containsOnly(view.uuid(), projects[0].uuid(), projects[1].uuid(), projects[2].uuid());
}
@Test
- public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_project_from_table_PROJECTS() {
+ public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_project_from_table_components() {
ComponentDto project = new Random().nextBoolean() ? db.components().insertPublicProject() : db.components().insertPrivateProject();
ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project));
ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(module1));
@@ -1439,16 +1434,16 @@ public class PurgeDaoTest {
ComponentDto file3 = db.components().insertComponent(newFileDto(project));
underTest.deleteNonRootComponentsInView(dbSession, singletonList(file3));
- assertThat(uuidsIn("projects"))
+ assertThat(uuidsIn("components"))
.containsOnly(project.uuid(), module1.uuid(), module2.uuid(), dir1.uuid(), dir2.uuid(), file1.uuid(), file2.uuid());
underTest.deleteNonRootComponentsInView(dbSession, asList(module1, dir2, file1));
- assertThat(uuidsIn("projects"))
+ assertThat(uuidsIn("components"))
.containsOnly(project.uuid(), module2.uuid(), dir1.uuid(), file2.uuid());
}
@Test
- public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_view_from_table_PROJECTS() {
+ public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_view_from_table_components() {
ComponentDto[] projects = {
db.components().insertPrivateProject(),
db.components().insertPrivateProject(),
@@ -1463,13 +1458,14 @@ public class PurgeDaoTest {
ComponentDto pc3 = db.components().insertComponent(newProjectCopy("c", projects[2], subview2));
underTest.deleteNonRootComponentsInView(dbSession, singletonList(pc3));
- assertThat(uuidsIn("projects"))
+ assertThat(uuidsIn("components"))
.containsOnly(view.uuid(), projects[0].uuid(), projects[1].uuid(), projects[2].uuid(),
subview1.uuid(), subview2.uuid(), pc1.uuid(), pc2.uuid());
underTest.deleteNonRootComponentsInView(dbSession, asList(subview1, pc2));
- assertThat(uuidsIn("projects"))
+ assertThat(uuidsIn("components"))
.containsOnly(view.uuid(), projects[0].uuid(), projects[1].uuid(), projects[2].uuid(), subview2.uuid(), pc1.uuid());
+ assertThat(uuidsIn("projects")).containsOnly(projects[0].uuid(), projects[1].uuid(), projects[2].uuid());
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java
index d6b147c456b..00cfb75a2e2 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/ProjectQgateAssociationDaoTest.java
@@ -27,6 +27,7 @@ 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 static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
@@ -47,9 +48,9 @@ public class ProjectQgateAssociationDaoTest {
ComponentDto project1 = db.components().insertPrivateProject(organization);
ComponentDto project2 = db.components().insertPrivateProject(organization);
ComponentDto project3 = db.components().insertPrivateProject(organization);
- db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
- db.qualityGates().associateProjectToQualityGate(project2, qualityGate1);
- db.qualityGates().associateProjectToQualityGate(project3, qualityGate2);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project3), qualityGate2);
List<ProjectQgateAssociationDto> result = underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate1)
@@ -70,8 +71,8 @@ public class ProjectQgateAssociationDaoTest {
ComponentDto project1 = db.components().insertPrivateProject(organization);
ComponentDto project2 = db.components().insertPrivateProject(organization);
ComponentDto project3 = db.components().insertPrivateProject(organization);
- db.qualityGates().associateProjectToQualityGate(project1, qualityGate);
- db.qualityGates().associateProjectToQualityGate(project2, qualityGate);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate);
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
@@ -97,8 +98,8 @@ public class ProjectQgateAssociationDaoTest {
ComponentDto project1 = db.components().insertPrivateProject(organization, p -> p.setName("Project One"));
ComponentDto project2 = db.components().insertPrivateProject(organization, p -> p.setName("Project Two"));
ComponentDto project3 = db.components().insertPrivateProject(organization, p -> p.setName("Project Three"));
- db.qualityGates().associateProjectToQualityGate(project1, qualityGate);
- db.qualityGates().associateProjectToQualityGate(project2, qualityGate);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate);
assertThat(underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
@@ -138,8 +139,8 @@ public class ProjectQgateAssociationDaoTest {
QGateWithOrgDto otherQualityGate = db.qualityGates().insertQualityGate(otherOrganization);
ComponentDto project = db.components().insertPrivateProject(organization);
ComponentDto otherProject = db.components().insertPrivateProject(otherOrganization);
- db.qualityGates().associateProjectToQualityGate(project, qualityGate);
- db.qualityGates().associateProjectToQualityGate(otherProject, otherQualityGate);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project), qualityGate);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(otherProject), otherQualityGate);
List<ProjectQgateAssociationDto> result = underTest.selectProjects(dbSession, ProjectQgateAssociationQuery.builder()
.qualityGate(qualityGate)
@@ -154,7 +155,7 @@ public class ProjectQgateAssociationDaoTest {
public void select_qgate_uuid_is_absent() {
ComponentDto project = db.components().insertPrivateProject();
- Optional<String> result = underTest.selectQGateUuidByComponentUuid(dbSession, project.uuid());
+ Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project.uuid());
assertThat(result.isPresent()).isFalse();
}
@@ -166,10 +167,10 @@ public class ProjectQgateAssociationDaoTest {
QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization);
ComponentDto project1 = db.components().insertPrivateProject(organization);
ComponentDto project2 = db.components().insertPrivateProject(organization);
- db.qualityGates().associateProjectToQualityGate(project1, qualityGate1);
- db.qualityGates().associateProjectToQualityGate(project2, qualityGate2);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project1), qualityGate1);
+ db.qualityGates().associateProjectToQualityGate(db.components().getProjectDto(project2), qualityGate2);
- Optional<String> result = underTest.selectQGateUuidByComponentUuid(dbSession, project1.uuid());
+ Optional<String> result = underTest.selectQGateUuidByProjectUuid(dbSession, project1.uuid());
assertThat(result).contains(qualityGate1.getUuid());
}
@@ -178,13 +179,13 @@ public class ProjectQgateAssociationDaoTest {
public void delete_by_project_uuid() {
OrganizationDto organization = db.organizations().insert();
QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ProjectDto project = db.components().insertPrivateProjectDto(organization);
db.qualityGates().associateProjectToQualityGate(project, qualityGate);
- underTest.deleteByProjectUuid(dbSession, project.uuid());
+ underTest.deleteByProjectUuid(dbSession, project.getUuid());
- Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid());
+ Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
assertThat(deletedQualityGate).isEmpty();
}
@@ -193,13 +194,13 @@ public class ProjectQgateAssociationDaoTest {
public void delete_by_qgate_uuid() {
OrganizationDto organization = db.organizations().insert();
QGateWithOrgDto qualityGate = db.qualityGates().insertQualityGate(organization);
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ProjectDto project = db.components().insertPrivateProjectDto(organization);
db.qualityGates().associateProjectToQualityGate(project, qualityGate);
underTest.deleteByQGateUuid(dbSession, qualityGate.getUuid());
- Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid());
+ Optional<String> deletedQualityGate = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
assertThat(deletedQualityGate).isEmpty();
}
@@ -209,13 +210,13 @@ public class ProjectQgateAssociationDaoTest {
OrganizationDto organization = db.organizations().insert();
QGateWithOrgDto firstQualityGate = db.qualityGates().insertQualityGate(organization);
QGateWithOrgDto secondQualityGate = db.qualityGates().insertQualityGate(organization);
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ProjectDto project = db.components().insertPrivateProjectDto(organization);
db.qualityGates().associateProjectToQualityGate(project, firstQualityGate);
- underTest.updateProjectQGateAssociation(dbSession, project.uuid(), secondQualityGate.getUuid());
+ underTest.updateProjectQGateAssociation(dbSession, project.getUuid(), secondQualityGate.getUuid());
- Optional<String> updatedQualityGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.uuid());
+ Optional<String> updatedQualityGateUuid = db.qualityGates().selectQGateUuidByComponentUuid(project.getUuid());
assertThat(updatedQualityGateUuid).contains(secondQualityGate.getUuid());
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
index 264e8ff2c52..f9a502dcc6f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualitygate/QualityGateDaoTest.java
@@ -27,8 +27,8 @@ import org.sonar.api.utils.System2;
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 static java.lang.String.format;
import static java.util.Arrays.asList;
@@ -173,7 +173,7 @@ public class QualityGateDaoTest {
public void select_by_project_uuid() {
OrganizationDto organization = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(organization);
+ ProjectDto project = db.components().insertPrivateProjectDto(organization);
QGateWithOrgDto qualityGate1 = db.qualityGates().insertQualityGate(organization);
QGateWithOrgDto qualityGate2 = db.qualityGates().insertQualityGate(organization);
@@ -183,7 +183,7 @@ public class QualityGateDaoTest {
db.qualityGates().associateProjectToQualityGate(project, qualityGate1);
- assertThat(underTest.selectByProjectUuid(dbSession, project.uuid()).getUuid()).isEqualTo(qualityGate1.getUuid());
+ assertThat(underTest.selectByProjectUuid(dbSession, project.getUuid()).getUuid()).isEqualTo(qualityGate1.getUuid());
assertThat(underTest.selectByProjectUuid(dbSession, "not-existing-uuid")).isNull();
}
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 a5658c673c3..2e8ec49fe34 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
@@ -39,6 +39,7 @@ import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.organization.OrganizationTesting;
+import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDefinitionDto;
import static com.google.common.collect.ImmutableList.of;
@@ -239,9 +240,12 @@ public class QualityProfileDaoTest {
public void test_deleteProjectAssociationsByProfileUuids() {
QProfileDto profile1 = db.qualityProfiles().insert(organization);
QProfileDto profile2 = db.qualityProfiles().insert(organization);
- ComponentDto project1 = db.components().insertPrivateProject(organization);
- ComponentDto project2 = db.components().insertPrivateProject(organization);
- ComponentDto project3 = db.components().insertPrivateProject(organization);
+ ProjectDto project1 = db.components().insertPrivateProjectDto(organization);
+ ProjectDto project2 = db.components().insertPrivateProjectDto(organization);
+ ProjectDto project3 = db.components().insertPrivateProjectDto(organization);
+
+ db.getDbClient().projectDao().selectByUuid(dbSession, project1.getUuid()).get();
+
db.qualityProfiles().associateWithProject(project1, profile1);
db.qualityProfiles().associateWithProject(project2, profile1);
db.qualityProfiles().associateWithProject(project3, profile2);
@@ -250,14 +254,14 @@ public class QualityProfileDaoTest {
List<Map<String, Object>> rows = db.select(dbSession, "select project_uuid as \"projectUuid\", profile_key as \"profileKey\" from project_qprofiles");
assertThat(rows).hasSize(1);
- assertThat(rows.get(0).get("projectUuid")).isEqualTo(project3.uuid());
+ assertThat(rows.get(0).get("projectUuid")).isEqualTo(project3.getUuid());
assertThat(rows.get(0).get("profileKey")).isEqualTo(profile2.getKee());
}
@Test
public void deleteProjectAssociationsByProfileUuids_does_nothing_if_empty_uuids() {
QProfileDto profile = db.qualityProfiles().insert(organization);
- ComponentDto project = db.components().insertPrivateProject();
+ ProjectDto project = db.components().insertPrivateProjectDto();
db.qualityProfiles().associateWithProject(project, profile);
underTest.deleteProjectAssociationsByProfileUuids(dbSession, Collections.emptyList());
@@ -562,7 +566,6 @@ public class QualityProfileDaoTest {
.isNull();
}
-
@Test
public void selectDefaultBuiltInProfilesWithoutActiveRules() {
// a quality profile without active rules but not builtin
@@ -651,15 +654,15 @@ public class QualityProfileDaoTest {
public void countProjectsByProfileKey() {
QProfileDto profileWithoutProjects = db.qualityProfiles().insert(organization);
QProfileDto profileWithProjects = db.qualityProfiles().insert(organization);
- ComponentDto project1 = db.components().insertPrivateProject(organization);
- ComponentDto project2 = db.components().insertPrivateProject(organization);
+ ProjectDto project1 = db.components().insertPrivateProjectDto(organization);
+ ProjectDto project2 = db.components().insertPrivateProjectDto(organization);
db.qualityProfiles().associateWithProject(project1, profileWithProjects);
db.qualityProfiles().associateWithProject(project2, profileWithProjects);
OrganizationDto otherOrg = db.organizations().insert();
QProfileDto profileInOtherOrg = db.qualityProfiles().insert(otherOrg);
- ComponentDto projectInOtherOrg = db.components().insertPrivateProject(otherOrg);
+ ProjectDto projectInOtherOrg = db.components().insertPrivateProjectDto(otherOrg);
db.qualityProfiles().associateWithProject(projectInOtherOrg, profileInOtherOrg);
assertThat(underTest.countProjectsByOrganizationAndProfiles(dbSession, organization, asList(profileWithoutProjects, profileWithProjects, profileInOtherOrg))).containsOnly(
@@ -671,8 +674,8 @@ public class QualityProfileDaoTest {
@Test
public void test_selectAssociatedToProjectAndLanguage() {
OrganizationDto org = db.organizations().insert();
- ComponentDto project1 = db.components().insertPublicProject(org);
- ComponentDto project2 = db.components().insertPublicProject(org);
+ ProjectDto project1 = db.components().insertPublicProjectDto(org);
+ ProjectDto project2 = db.components().insertPublicProjectDto(org);
QProfileDto javaProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("java"));
QProfileDto jsProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("js"));
db.qualityProfiles().associateWithProject(project1, javaProfile, jsProfile);
@@ -690,8 +693,8 @@ public class QualityProfileDaoTest {
@Test
public void test_selectAssociatedToProjectUuidAndLanguages() {
OrganizationDto org = db.organizations().insert();
- ComponentDto project1 = db.components().insertPublicProject(org);
- ComponentDto project2 = db.components().insertPublicProject(org);
+ ProjectDto project1 = db.components().insertPublicProjectDto(org);
+ ProjectDto project2 = db.components().insertPublicProjectDto(org);
QProfileDto javaProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("java"));
QProfileDto jsProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("js"));
db.qualityProfiles().associateWithProject(project1, javaProfile, jsProfile);
@@ -713,7 +716,7 @@ public class QualityProfileDaoTest {
@Test
public void test_updateProjectProfileAssociation() {
OrganizationDto org = db.organizations().insert();
- ComponentDto project = db.components().insertPrivateProject(org);
+ ProjectDto project = db.components().insertPrivateProjectDto(org);
QProfileDto javaProfile1 = db.qualityProfiles().insert(org, p -> p.setLanguage("java"));
QProfileDto jsProfile = db.qualityProfiles().insert(org, p -> p.setLanguage("js"));
QProfileDto javaProfile2 = db.qualityProfiles().insert(org, p -> p.setLanguage("java"));
@@ -749,12 +752,12 @@ public class QualityProfileDaoTest {
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
- db.qualityProfiles().associateWithProject(project1, profile1);
- db.qualityProfiles().associateWithProject(project2, profile1);
+ db.qualityProfiles().associateWithProject(db.components().getProjectDto(project1), profile1);
+ db.qualityProfiles().associateWithProject(db.components().getProjectDto(project2), profile1);
QProfileDto profile2 = newQualityProfileDto();
db.qualityProfiles().insert(profile2);
- db.qualityProfiles().associateWithProject(project3, profile2);
+ db.qualityProfiles().associateWithProject(db.components().getProjectDto(project3), profile2);
QProfileDto profile3 = newQualityProfileDto();
assertThat(underTest.selectSelectedProjects(dbSession, organization, profile1, null))
@@ -778,11 +781,11 @@ public class QualityProfileDaoTest {
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
- db.qualityProfiles().associateWithProject(project1, profile1);
+ db.qualityProfiles().associateWithProject(db.components().getProjectDto(project1), profile1);
QProfileDto profile2 = newQualityProfileDto();
db.qualityProfiles().insert(profile2);
- db.qualityProfiles().associateWithProject(project2, profile2);
+ db.qualityProfiles().associateWithProject(db.components().getProjectDto(project2), profile2);
QProfileDto profile3 = newQualityProfileDto();
assertThat(underTest.selectDeselectedProjects(dbSession, organization, profile1, null))
@@ -806,11 +809,11 @@ public class QualityProfileDaoTest {
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
- db.qualityProfiles().associateWithProject(project1, profile1);
+ db.qualityProfiles().associateWithProject(db.components().getProjectDto(project1), profile1);
QProfileDto profile2 = newQualityProfileDto();
db.qualityProfiles().insert(profile2);
- db.qualityProfiles().associateWithProject(project2, profile2);
+ db.qualityProfiles().associateWithProject(db.components().getProjectDto(project2), profile2);
QProfileDto profile3 = newQualityProfileDto();
assertThat(underTest.selectProjectAssociations(dbSession, organization, profile1, null))
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java
index dcfcb50ebeb..08eb943f58f 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/user/UserDaoTest.java
@@ -36,6 +36,7 @@ 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 static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
@@ -520,7 +521,7 @@ public class UserDaoTest {
session.commit();
- underTest.cleanHomepage(session, new ComponentDto().setUuid("dummy-project-UUID"));
+ underTest.cleanHomepage(session, new ProjectDto().setUuid("dummy-project-UUID"));
UserDto userWithAHomepageReloaded = underTest.selectUserById(session, userUnderTest.getId());
assertThat(userWithAHomepageReloaded.getUpdatedAt()).isEqualTo(NOW);
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 001315f0f25..38e619a7a80 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,9 +29,9 @@ 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.component.ComponentDto;
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;
@@ -149,15 +149,15 @@ public class WebhookDaoTest {
@Test
public void cleanWebhooksOfAProject() {
OrganizationDto organization = organizationDbTester.insert();
- ComponentDto componentDto = componentDbTester.insertPrivateProject(organization);
- webhookDbTester.insertWebhook(componentDto);
- webhookDbTester.insertWebhook(componentDto);
- webhookDbTester.insertWebhook(componentDto);
- webhookDbTester.insertWebhook(componentDto);
+ ProjectDto projectDto = componentDbTester.insertPrivateProjectDto(organization);
+ webhookDbTester.insertWebhook(projectDto);
+ webhookDbTester.insertWebhook(projectDto);
+ webhookDbTester.insertWebhook(projectDto);
+ webhookDbTester.insertWebhook(projectDto);
- underTest.deleteByProject(dbSession, componentDto);
+ underTest.deleteByProject(dbSession, projectDto);
- Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, componentDto.uuid());
+ Optional<WebhookDto> reloaded = underTest.selectByUuid(dbSession, projectDto.getUuid());
assertThat(reloaded).isEmpty();
}