</if>
where
p.enabled=${_true}
- and p.copy_component_uuid is null
+ AND p.main_branch_project_uuid is null
+ AND p.copy_component_uuid is null
<if test="organizationUuid!=null">
and p.organization_uuid=#{organizationUuid,jdbcType=VARCHAR}
</if>
where
s2.id is null
and p.qualifier='TRK'
+ and p.main_branch_project_uuid is null
and p.copy_component_uuid is null
<if test="query!=null">
and (
from projects p
<where>
p.enabled=${_true}
+ AND p.main_branch_project_uuid is null
AND p.copy_component_uuid is null
<if test="includeModules == false">
AND p.qualifier = 'TRK'
where
proj.qualifier = 'TRK'
and proj.enabled = ${_true}
+ and proj.main_branch_project_uuid is null
and proj.copy_component_uuid is null
<choose>
<when test="query.membership() == 'selected'">
where
pj.scope = 'PRJ'
and pj.qualifier = 'TRK'
+ and pj.main_branch_project_uuid is null
and upper(pj.name) like #{nameQuery, jdbcType=VARCHAR}
and pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
order by pj.name ASC
FROM projects pj
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
- WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
+ WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null
AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
AND pp.profile_key IS NULL
AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
FROM projects pj
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
- WHERE pj.scope='PRJ' AND pj.qualifier='TRK'
+ WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null
AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
AND pj.organization_uuid = #{organizationUuid, jdbcType=VARCHAR}
ORDER BY pj.name ASC
assertThat(underTest.countGhostProjects(dbSession, organization.getUuid(), null)).isEqualTo(3);
}
+ @Test
+ public void dont_select_branch_ghost_projects() {
+ OrganizationDto organization = db.organizations().insert();
+
+ // ghosts because has at least one snapshot with status U but none with status P
+ ComponentDto ghostProject = db.components().insertPrivateProject(organization);
+ db.components().insertSnapshot(ghostProject, dto -> dto.setStatus("U"));
+ db.components().insertSnapshot(ghostProject, dto -> dto.setStatus("U"));
+ ComponentDto ghostBranchProject = db.components().insertProjectBranch(ghostProject);
+
+ db.components().insertSnapshot(ghostBranchProject, dto -> dto.setStatus("U"));
+
+ assertThat(underTest.selectGhostProjects(dbSession, organization.getUuid(), null, 0, 10))
+ .extracting(ComponentDto::uuid)
+ .containsOnly(ghostProject.uuid());
+ assertThat(underTest.countGhostProjects(dbSession, organization.getUuid(), null)).isEqualTo(1);
+ }
+
@Test
public void selectByProjectUuid() {
ComponentDto project = db.components().insertPrivateProject();
.isEmpty();
}
+ @Test
+ public void selectByQuery_should_not_return_branches() {
+ ComponentDto main = db.components().insertMainBranch();
+ ComponentDto branch = db.components().insertProjectBranch(main);
+
+ assertThat(underTest.selectByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY, 0, 2)).hasSize(1);
+ assertThat(underTest.selectByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY, 0, 2).get(0).uuid()).isEqualTo(main.uuid());
+ }
+
+ @Test
+ public void countByQuery_should_not_include_branches() {
+ ComponentDto main = db.components().insertMainBranch();
+ ComponentDto branch = db.components().insertProjectBranch(main);
+
+ assertThat(underTest.countByQuery(dbSession, ALL_PROJECTS_COMPONENT_QUERY)).isEqualTo(1);
+ }
+
@Test
public void countByQuery_with_organization_filters_on_specified_organization() {
OrganizationDto organization1 = db.organizations().insert();
assertThat(components).extracting("organizationUuid").containsOnly(organizationDto.getUuid());
}
+ @Test
+ public void select_projects_by_name_ignore_branches() {
+ OrganizationDto organizationDto = db.organizations().insert();
+ ComponentDto project1 = db.components().insertComponent(ComponentTesting.newPrivateProjectDto(organizationDto).setName("project1"));
+ ComponentDto module1 = db.components().insertComponent(newModuleDto(project1).setName("project1"));
+ ComponentDto subModule1 = db.components().insertComponent(newModuleDto(module1).setName("project1"));
+
+ db.components().insertComponent(newFileDto(subModule1).setName("project1"));
+ db.components().insertProjectBranch(project1, b -> b.setKey("branch1"));
+
+ // check that branch is present with same name as main branch
+ assertThat(underTest.selectByKeyAndBranch(dbSession, project1.getKey(), "branch1").get().name()).isEqualTo("project1");
+
+ // branch is not returned
+ assertThat(underTest.selectProjectsByNameQuery(dbSession, null, false)).extracting(ComponentDto::uuid)
+ .containsOnly(project1.uuid());
+ assertThat(underTest.selectProjectsByNameQuery(dbSession, "project", false)).extracting(ComponentDto::uuid)
+ .containsOnly(project1.uuid());
+ }
+
@Test
public void select_projects_by_name_query() {
OrganizationDto organizationDto = db.organizations().insert();
*/
package org.sonar.db.qualitygate;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.util.List;
import java.util.Optional;
+
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.System2;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.property.PropertyDto;
-import static org.assertj.core.api.Assertions.assertThat;
-
public class ProjectQgateAssociationDaoTest {
@Rule
QProfileDto profileWithProjects = db.qualityProfiles().insert(organization);
ComponentDto project1 = db.components().insertPrivateProject(organization);
ComponentDto project2 = db.components().insertPrivateProject(organization);
+
db.qualityProfiles().associateWithProject(project1, profileWithProjects);
db.qualityProfiles().associateWithProject(project2, profileWithProjects);
ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
OrganizationDto organization2 = db.organizations().insert();
ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+ ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
OrganizationDto organization2 = db.organizations().insert();
ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+ ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"), t -> t.setOrganizationUuid(organization.getUuid()));
OrganizationDto organization2 = db.organizations().insert();
ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"), t -> t.setOrganizationUuid(organization2.getUuid()));
+ ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
root_uuid="A"
project_uuid="A"
kee="project-one"
+ main_branch_project_uuid="[null]"
name="Project One"
qualifier="TRK"
scope="PRJ"
root_uuid="B"
project_uuid="B"
kee="project-two"
+ main_branch_project_uuid="[null]"
name="Project Two"
qualifier="TRK"
scope="PRJ"
root_uuid="C"
project_uuid="C"
kee="project-three"
+ main_branch_project_uuid="[null]"
name="Project Three"
qualifier="TRK"
scope="PRJ"
root_uuid="D"
project_uuid="D"
kee="project-four"
+ main_branch_project_uuid="[null]"
name="Project Four"
qualifier="TRK"
scope="PRJ"
root_uuid="E"
project_uuid="E"
kee="project-five"
+ main_branch_project_uuid="[null]"
name="Project Five"
qualifier="TRK"
scope="PRJ"
root_uuid="F"
project_uuid="F"
kee="view-six"
+ main_branch_project_uuid="[null]"
name="View Six"
qualifier="VW"
scope="PRJ"
root_uuid="G"
project_uuid="G"
kee="file-one"
+ main_branch_project_uuid="[null]"
name="File One"
qualifier="TRK"
scope="FIL"
copy_component_uuid="C"
id="7"
private="[false]"/>
+ <projects organization_uuid="org1"
+ uuid="H"
+ uuid_path="NOT_USED"
+ root_uuid="H"
+ project_uuid="H"
+ kee="branch"
+ main_branch_project_uuid="A"
+ name="branch"
+ qualifier="TRK"
+ scope="PRJ"
+ enabled="[true]"
+ copy_component_uuid="[null]"
+ id="8"
+ private="[false]"/>
<properties id="1"
prop_key="sonar.qualitygate"