Skip to content

Commit

Permalink
SONAR-10441 project is provisioned if no analysis on any branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Brandhof authored and SonarTech committed Apr 5, 2018
1 parent c9b849f commit 2104453
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
Expand Up @@ -340,6 +340,11 @@
</if> </if>
<if test="query.isOnProvisionedOnly()"> <if test="query.isOnProvisionedOnly()">
and not exists(select 1 from snapshots sp where sp.component_uuid=p.uuid) and not exists(select 1 from snapshots sp where sp.component_uuid=p.uuid)
and not exists(
select 1 from snapshots sp
inner join project_branches pb on sp.component_uuid = pb.uuid
where pb.project_uuid = p.uuid
)
</if> </if>
</sql> </sql>


Expand Down
Expand Up @@ -903,14 +903,16 @@ public void select_all_roots_by_organization_does_not_return_branches() {
@Test @Test
public void selectByQuery_provisioned() { public void selectByQuery_provisioned() {
OrganizationDto organization = db.organizations().insert(); OrganizationDto organization = db.organizations().insert();

ComponentDto provisionedProject = db.components() ComponentDto provisionedProject = db.components()
.insertComponent(newPrivateProjectDto(organization).setDbKey("provisioned.project").setName("Provisioned Project")); .insertPrivateProject(organization, p -> p.setDbKey("provisioned.project").setName("Provisioned Project"));
ComponentDto provisionedView = db.components().insertView(organization); ComponentDto provisionedPortfolio = db.components().insertPrivatePortfolio(organization);
String projectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)).getComponentUuid();
String disabledProjectUuid = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization).setEnabled(false)).getComponentUuid(); SnapshotDto analyzedProject = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization));
String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid(); SnapshotDto analyzedDisabledProject = db.components().insertProjectAndSnapshot(newPrivateProjectDto(organization)
.setEnabled(false));
SnapshotDto analyzedPortfolio = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization));


Set<String> projectQualifiers = newHashSet(Qualifiers.PROJECT);
Supplier<ComponentQuery.Builder> query = () -> ComponentQuery.builder().setQualifiers(Qualifiers.PROJECT).setOnProvisionedOnly(true); Supplier<ComponentQuery.Builder> query = () -> ComponentQuery.builder().setQualifiers(Qualifiers.PROJECT).setOnProvisionedOnly(true);
assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10)) assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10))
.extracting(ComponentDto::uuid) .extracting(ComponentDto::uuid)
Expand All @@ -926,7 +928,7 @@ public void selectByQuery_provisioned() {
.containsOnly(provisionedProject.uuid()); .containsOnly(provisionedProject.uuid());
assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW).build(), 0, 10)) assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW).build(), 0, 10))
.extracting(ComponentDto::uuid) .extracting(ComponentDto::uuid)
.containsOnly(provisionedProject.uuid(), provisionedView.uuid()); .containsOnly(provisionedProject.uuid(), provisionedPortfolio.uuid());


// match key // match key
assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery(provisionedProject.getDbKey()).build(), 0, 10)) assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().setNameOrKeyQuery(provisionedProject.getDbKey()).build(), 0, 10))
Expand All @@ -945,6 +947,28 @@ public void selectByQuery_provisioned() {
.containsExactly(provisionedProject.uuid()); .containsExactly(provisionedProject.uuid());
} }


@Test
public void selectByQuery_onProvisionedOnly_filters_projects_with_analysis_on_branch() {
Supplier<ComponentQuery.Builder> query = () -> ComponentQuery.builder()
.setQualifiers(Qualifiers.PROJECT)
.setOnProvisionedOnly(true);

// the project does not have any analysis
OrganizationDto organization = db.organizations().insert();
ComponentDto project = db.components().insertMainBranch(organization);
assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10))
.extracting(ComponentDto::uuid)
.containsOnly(project.uuid());

// the project does not have analysis of main branch but only
// analysis of non-main branches
ComponentDto branchWithoutAnalysis = db.components().insertProjectBranch(project);
ComponentDto branchWithAnalysis = db.components().insertProjectBranch(project);
db.components().insertSnapshot(branchWithAnalysis);
assertThat(underTest.selectByQuery(dbSession, organization.getUuid(), query.get().build(), 0, 10))
.isEmpty();
}

@Test @Test
public void count_provisioned() { public void count_provisioned() {
OrganizationDto organization = db.organizations().insert(); OrganizationDto organization = db.organizations().insert();
Expand Down

0 comments on commit 2104453

Please sign in to comment.