import org.sonar.db.metric.MetricDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
import org.sonar.db.permission.GlobalPermission;
+import org.sonar.db.portfolio.PortfolioProjectDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.user.GroupDto;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.db.component.ComponentTesting.newBranchDto;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
assertThat(dbTester.countRowsOfTable("user_dismissed_messages")).isEqualTo(1);
}
+ @Test
+ public void deleteProjectInPortfolios_deletes_project_from_portfolios() {
+ var portfolio1 = dbTester.components().insertPrivatePortfolio();
+ var portfolio2 = dbTester.components().insertPrivatePortfolio();
+ dbTester.components().insertPrivatePortfolio();
+
+ ProjectDto project = dbTester.components().insertPrivateProjectDto();
+ ProjectDto anotherProject = dbTester.components().insertPrivateProjectDto();
+
+ dbTester.components().addPortfolioProject(portfolio1, project.getUuid(), anotherProject.getUuid());
+ dbTester.components().addPortfolioProject(portfolio2, project.getUuid());
+
+ PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler, system2);
+
+ purgeCommands.deleteProjectInPortfolios(project.getUuid());
+
+ assertThat(dbTester.getDbClient().portfolioDao().selectAllPortfolioProjects(dbTester.getSession()))
+ .extracting(PortfolioProjectDto::getPortfolioUuid, PortfolioProjectDto::getProjectUuid)
+ .containsExactlyInAnyOrder(tuple(portfolio1.uuid(), anotherProject.getUuid()));
+ }
+
private void addPermissions(ComponentDto root) {
if (!root.isPrivate()) {
dbTester.users().insertProjectPermissionOnAnyone("foo1", root);
assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(2);
}
- private int countMeasures(SnapshotDto analysis, MetricDto metric) {
- return dbTester.countSql("select count(*) from project_measures where analysis_uuid='" + analysis.getUuid() + "' and metric_id=" + metric.getUuid());
- }
-
private int countComponentOfRoot(ComponentDto projectOrView) {
return dbTester.countSql("select count(1) from components where project_uuid='" + projectOrView.uuid() + "'");
}
import org.sonar.db.metric.MetricDto;
import org.sonar.db.newcodeperiod.NewCodePeriodDto;
import org.sonar.db.newcodeperiod.NewCodePeriodType;
+import org.sonar.db.portfolio.PortfolioProjectDto;
import org.sonar.db.project.ProjectDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.rule.RuleDefinitionDto;
import static java.util.Collections.singletonList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
+import static org.assertj.core.groups.Tuple.tuple;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
@Test
public void selectPurgeableAnalyses() {
- SnapshotDto[] analyses = new SnapshotDto[]{
+ SnapshotDto[] analyses = new SnapshotDto[] {
newSnapshot()
.setUuid("u1")
.setComponentUuid(PROJECT_UUID)
assertThat(dbClient.projectAlmSettingDao().selectByProject(dbSession, otherProject)).isNotEmpty();
}
+ @Test
+ public void deleteProject_deletes_portfolio_projects() {
+ ComponentDto portfolio1 = db.components().insertPrivatePortfolio();
+ ComponentDto portfolio2 = db.components().insertPrivatePortfolio();
+
+ ProjectDto project = db.components().insertPublicProjectDto();
+ ProjectDto otherProject = db.components().insertPublicProjectDto();
+
+ db.components().addPortfolioProject(portfolio1, project.getUuid(), otherProject.getUuid());
+ db.components().addPortfolioProject(portfolio2, project.getUuid());
+
+ underTest.deleteProject(dbSession, project.getUuid(), project.getQualifier(), project.getName(), project.getKey());
+
+ assertThat(dbClient.portfolioDao().selectAllPortfolioProjects(dbSession))
+ .extracting(PortfolioProjectDto::getPortfolioUuid, PortfolioProjectDto::getProjectUuid)
+ .containsExactlyInAnyOrder(tuple(portfolio1.uuid(), otherProject.getUuid()));
+ }
+
@Test
public void deleteNonRootComponents_has_no_effect_when_parameter_is_empty() {
DbSession dbSession = mock(DbSession.class);
private void insertPropertyFor(ComponentDto... components) {
Stream.of(components).forEach(componentDto -> db.properties().insertProperty(new PropertyDto()
- .setKey(randomAlphabetic(3))
- .setValue(randomAlphabetic(3))
- .setComponentUuid(componentDto.uuid()),
+ .setKey(randomAlphabetic(3))
+ .setValue(randomAlphabetic(3))
+ .setComponentUuid(componentDto.uuid()),
componentDto.getKey(), componentDto.name(), componentDto.qualifier(), null));
}
private void insertPropertyFor(Collection<BranchDto> branches) {
branches.stream().forEach(branchDto -> db.properties().insertProperty(new PropertyDto()
- .setKey(randomAlphabetic(3))
- .setValue(randomAlphabetic(3))
- .setComponentUuid(branchDto.getUuid()),
- null, branchDto.getKey(), null,null));
+ .setKey(randomAlphabetic(3))
+ .setValue(randomAlphabetic(3))
+ .setComponentUuid(branchDto.getUuid()),
+ null, branchDto.getKey(), null, null));
}
private Stream<String> getComponentUuidsOfMeasures() {