import org.sonar.db.measure.MeasureDto;
import org.sonar.db.measure.custom.CustomMeasureDto;
import org.sonar.db.metric.MetricDto;
+import org.sonar.db.organization.OrganizationDto;
import org.sonar.db.property.PropertyDto;
import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.source.FileSourceDto;
+import org.sonar.db.webhook.WebhookDeliveryLiteDto;
+import org.sonar.db.webhook.WebhookDto;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import static org.sonar.db.ce.CeTaskTypes.REPORT;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
import static org.sonar.db.component.ComponentTesting.newProjectCopy;
-import static org.sonar.db.webhook.WebhookDbTesting.newDto;
-import static org.sonar.db.webhook.WebhookDbTesting.selectAllDeliveryUuids;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.newDto;
+import static org.sonar.db.webhook.WebhookDeliveryTesting.selectAllDeliveryUuids;
public class PurgeDaoTest {
private System2 system2 = mock(System2.class);
@Rule
- public DbTester dbTester = DbTester.create(system2);
+ public DbTester db = DbTester.create(system2);
@Rule
public ExpectedException expectedException = ExpectedException.none();
- private DbClient dbClient = dbTester.getDbClient();
- private DbSession dbSession = dbTester.getSession();
- private PurgeDao underTest = dbTester.getDbClient().purgeDao();
+ private DbClient dbClient = db.getDbClient();
+ private DbSession dbSession = db.getSession();
+ private PurgeDao underTest = db.getDbClient().purgeDao();
@Test
public void purge_failed_ce_tasks() {
- dbTester.prepareDbUnit(getClass(), "shouldDeleteAbortedBuilds.xml");
+ db.prepareDbUnit(getClass(), "shouldDeleteAbortedBuilds.xml");
underTest.purge(dbSession, newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
dbSession.commit();
- dbTester.assertDbUnit(getClass(), "shouldDeleteAbortedBuilds-result.xml", "snapshots");
+ db.assertDbUnit(getClass(), "shouldDeleteAbortedBuilds-result.xml", "snapshots");
}
@Test
public void purge_history_of_project() {
- dbTester.prepareDbUnit(getClass(), "shouldPurgeProject.xml");
+ db.prepareDbUnit(getClass(), "shouldPurgeProject.xml");
underTest.purge(dbSession, newConfigurationWith30Days(), PurgeListener.EMPTY, new PurgeProfiler());
dbSession.commit();
- dbTester.assertDbUnit(getClass(), "shouldPurgeProject-result.xml", "projects", "snapshots");
+ db.assertDbUnit(getClass(), "shouldPurgeProject-result.xml", "projects", "snapshots");
}
@Test
public void purge_inactive_short_living_branches() {
when(system2.now()).thenReturn(new Date().getTime());
- RuleDefinitionDto rule = dbTester.rules().insert();
- ComponentDto project = dbTester.components().insertMainBranch();
- ComponentDto longBranch = dbTester.components().insertProjectBranch(project);
- ComponentDto recentShortBranch = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.SHORT));
+ RuleDefinitionDto rule = db.rules().insert();
+ ComponentDto project = db.components().insertMainBranch();
+ ComponentDto longBranch = db.components().insertProjectBranch(project);
+ ComponentDto recentShortBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.SHORT));
// short branch with other components and issues, updated 31 days ago
when(system2.now()).thenReturn(DateUtils.addDays(new Date(), -31).getTime());
- ComponentDto shortBranch = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.SHORT));
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(shortBranch));
- ComponentDto subModule = dbTester.components().insertComponent(newModuleDto(module));
- ComponentDto file = dbTester.components().insertComponent(newFileDto(subModule));
- dbTester.issues().insert(rule, shortBranch, file);
- dbTester.issues().insert(rule, shortBranch, subModule);
- dbTester.issues().insert(rule, shortBranch, module);
+ ComponentDto shortBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.SHORT));
+ ComponentDto module = db.components().insertComponent(newModuleDto(shortBranch));
+ ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
+ ComponentDto file = db.components().insertComponent(newFileDto(subModule));
+ db.issues().insert(rule, shortBranch, file);
+ db.issues().insert(rule, shortBranch, subModule);
+ db.issues().insert(rule, shortBranch, module);
// back to present
when(system2.now()).thenReturn(new Date().getTime());
@Test
public void purge_inactive_pull_request() {
when(system2.now()).thenReturn(new Date().getTime());
- RuleDefinitionDto rule = dbTester.rules().insert();
- ComponentDto project = dbTester.components().insertMainBranch();
- ComponentDto longBranch = dbTester.components().insertProjectBranch(project);
- ComponentDto recentPullRequest = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
+ RuleDefinitionDto rule = db.rules().insert();
+ ComponentDto project = db.components().insertMainBranch();
+ ComponentDto longBranch = db.components().insertProjectBranch(project);
+ ComponentDto recentPullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
// pull request with other components and issues, updated 31 days ago
when(system2.now()).thenReturn(DateUtils.addDays(new Date(), -31).getTime());
- ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(pullRequest));
- ComponentDto subModule = dbTester.components().insertComponent(newModuleDto(module));
- ComponentDto file = dbTester.components().insertComponent(newFileDto(subModule));
- dbTester.issues().insert(rule, pullRequest, file);
- dbTester.issues().insert(rule, pullRequest, subModule);
- dbTester.issues().insert(rule, pullRequest, module);
+ ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
+ ComponentDto module = db.components().insertComponent(newModuleDto(pullRequest));
+ ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
+ ComponentDto file = db.components().insertComponent(newFileDto(subModule));
+ db.issues().insert(rule, pullRequest, file);
+ db.issues().insert(rule, pullRequest, subModule);
+ db.issues().insert(rule, pullRequest, module);
// back to present
when(system2.now()).thenReturn(new Date().getTime());
@Test
public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
- dbTester.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml");
+ db.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml");
PurgeConfiguration conf = new PurgeConfiguration(new IdUuidPair(THE_PROJECT_ID, "PROJECT_UUID"), asList(Scopes.DIRECTORY, Scopes.FILE),
30, Optional.of(30), System2.INSTANCE, Collections.emptyList());
underTest.purge(dbSession, conf, PurgeListener.EMPTY, new PurgeProfiler());
dbSession.commit();
- dbTester.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots", "project_measures");
+ db.assertDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml", "projects", "snapshots", "project_measures");
}
@Test
public void close_issues_clean_index_and_file_sources_of_disabled_components_specified_by_uuid_in_configuration() {
// components and issues, updated 31 days ago
when(system2.now()).thenReturn(DateUtils.addDays(new Date(), -31).getTime());
- RuleDefinitionDto rule = dbTester.rules().insert();
- ComponentDto project = dbTester.components().insertMainBranch(p -> p.setEnabled(false));
- dbTester.components().insertSnapshot(project);
- dbTester.components().insertSnapshot(project);
- dbTester.components().insertSnapshot(project, s -> s.setLast(false));
-
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(project).setEnabled(false));
- ComponentDto dir = dbTester.components().insertComponent(newDirectory(module, "sub").setEnabled(false));
- ComponentDto srcFile = dbTester.components().insertComponent(newFileDto(module, dir).setEnabled(false));
- ComponentDto testFile = dbTester.components().insertComponent(newFileDto(module, dir).setEnabled(false));
- ComponentDto nonSelectedFile = dbTester.components().insertComponent(newFileDto(module, dir).setEnabled(false));
- IssueDto openOnFile = dbTester.issues().insert(rule, project, srcFile, issue -> issue.setStatus("OPEN"));
- IssueDto confirmOnFile = dbTester.issues().insert(rule, project, srcFile, issue -> issue.setStatus("CONFIRM"));
- IssueDto openOnDir = dbTester.issues().insert(rule, project, dir, issue -> issue.setStatus("OPEN"));
- IssueDto confirmOnDir = dbTester.issues().insert(rule, project, dir, issue -> issue.setStatus("CONFIRM"));
- IssueDto openOnNonSelected = dbTester.issues().insert(rule, project, nonSelectedFile, issue -> issue.setStatus("OPEN"));
- IssueDto confirmOnNonSelected = dbTester.issues().insert(rule, project, nonSelectedFile, issue -> issue.setStatus("CONFIRM"));
-
- assertThat(dbTester.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(0);
-
- assertThat(dbTester.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(0);
- assertThat(dbTester.countSql("select count(*) from issues where resolution = 'REMOVED'")).isEqualTo(0);
-
- dbTester.fileSources().insertFileSource(srcFile);
- dbTester.fileSources().insertFileSource(testFile, f -> f.setDataType("TEST"));
- FileSourceDto nonSelectedFileSource = dbTester.fileSources().insertFileSource(nonSelectedFile);
- assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(3);
+ RuleDefinitionDto rule = db.rules().insert();
+ ComponentDto project = db.components().insertMainBranch(p -> p.setEnabled(false));
+ db.components().insertSnapshot(project);
+ db.components().insertSnapshot(project);
+ db.components().insertSnapshot(project, s -> s.setLast(false));
+
+ ComponentDto module = db.components().insertComponent(newModuleDto(project).setEnabled(false));
+ ComponentDto dir = db.components().insertComponent(newDirectory(module, "sub").setEnabled(false));
+ ComponentDto srcFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
+ ComponentDto testFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
+ ComponentDto nonSelectedFile = db.components().insertComponent(newFileDto(module, dir).setEnabled(false));
+ IssueDto openOnFile = db.issues().insert(rule, project, srcFile, issue -> issue.setStatus("OPEN"));
+ IssueDto confirmOnFile = db.issues().insert(rule, project, srcFile, issue -> issue.setStatus("CONFIRM"));
+ IssueDto openOnDir = db.issues().insert(rule, project, dir, issue -> issue.setStatus("OPEN"));
+ IssueDto confirmOnDir = db.issues().insert(rule, project, dir, issue -> issue.setStatus("CONFIRM"));
+ IssueDto openOnNonSelected = db.issues().insert(rule, project, nonSelectedFile, issue -> issue.setStatus("OPEN"));
+ IssueDto confirmOnNonSelected = db.issues().insert(rule, project, nonSelectedFile, issue -> issue.setStatus("CONFIRM"));
+
+ assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(0);
+
+ assertThat(db.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(0);
+ assertThat(db.countSql("select count(*) from issues where resolution = 'REMOVED'")).isEqualTo(0);
+
+ db.fileSources().insertFileSource(srcFile);
+ db.fileSources().insertFileSource(testFile, f -> f.setDataType("TEST"));
+ FileSourceDto nonSelectedFileSource = db.fileSources().insertFileSource(nonSelectedFile);
+ assertThat(db.countRowsOfTable("file_sources")).isEqualTo(3);
// back to present
when(system2.now()).thenReturn(new Date().getTime());
dbSession.commit();
// set purge_status=1 for non-last snapshot
- assertThat(dbTester.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(1);
+ assertThat(db.countSql("select count(*) from snapshots where purge_status = 1")).isEqualTo(1);
// close open issues of selected
- assertThat(dbTester.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(4);
+ assertThat(db.countSql("select count(*) from issues where status = 'CLOSED'")).isEqualTo(4);
for (IssueDto issue : Arrays.asList(openOnFile, confirmOnFile, openOnDir, confirmOnDir)) {
- assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get())
+ assertThat(db.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get())
.extracting("status", "resolution")
.containsExactlyInAnyOrder("CLOSED", "REMOVED");
}
for (IssueDto issue : Arrays.asList(openOnNonSelected, confirmOnNonSelected)) {
- assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get())
+ assertThat(db.getDbClient().issueDao().selectByKey(dbSession, issue.getKey()).get())
.extracting("status", "resolution")
.containsExactlyInAnyOrder(issue.getStatus(), null);
}
// delete file sources of selected
- assertThat(dbTester.countRowsOfTable("file_sources")).isEqualTo(1);
- assertThat(dbTester.getDbClient().fileSourceDao().selectSourceByFileUuid(dbSession, nonSelectedFileSource.getFileUuid())).isNotNull();
+ assertThat(db.countRowsOfTable("file_sources")).isEqualTo(1);
+ assertThat(db.getDbClient().fileSourceDao().selectSourceByFileUuid(dbSession, nonSelectedFileSource.getFileUuid())).isNotNull();
}
@Test
public void shouldDeleteAnalyses() {
- dbTester.prepareDbUnit(getClass(), "shouldDeleteAnalyses.xml");
+ db.prepareDbUnit(getClass(), "shouldDeleteAnalyses.xml");
underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(3, "u3")));
- dbTester.assertDbUnit(getClass(), "shouldDeleteAnalyses-result.xml", "snapshots");
+ db.assertDbUnit(getClass(), "shouldDeleteAnalyses-result.xml", "snapshots");
}
@Test
public void selectPurgeableAnalyses() {
- dbTester.prepareDbUnit(getClass(), "shouldSelectPurgeableAnalysis.xml");
+ db.prepareDbUnit(getClass(), "shouldSelectPurgeableAnalysis.xml");
List<PurgeableAnalysisDto> analyses = underTest.selectPurgeableAnalyses(THE_PROJECT_UUID, dbSession);
assertThat(analyses).hasSize(3);
@Test
public void delete_project_and_associated_data() {
- dbTester.prepareDbUnit(getClass(), "shouldDeleteProject.xml");
+ db.prepareDbUnit(getClass(), "shouldDeleteProject.xml");
underTest.deleteProject(dbSession, "A");
dbSession.commit();
- assertThat(dbTester.countRowsOfTable("projects")).isZero();
- assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
- assertThat(dbTester.countRowsOfTable("issues")).isZero();
- assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
- assertThat(dbTester.countRowsOfTable("file_sources")).isZero();
+ assertThat(db.countRowsOfTable("projects")).isZero();
+ assertThat(db.countRowsOfTable("snapshots")).isZero();
+ assertThat(db.countRowsOfTable("issues")).isZero();
+ assertThat(db.countRowsOfTable("issue_changes")).isZero();
+ assertThat(db.countRowsOfTable("file_sources")).isZero();
+ }
+
+ @Test
+ public void delete_webhooks_from_project() {
+ OrganizationDto organization = db.organizations().insert();
+ ComponentDto project1 = db.components().insertPrivateProject(organization);
+ WebhookDto webhook = db.webhooks().insertWebhook(project1);
+ db.webhookDelivery().insert(webhook);
+ ComponentDto projectNotToBeDeleted = db.components().insertPrivateProject(organization);
+ WebhookDto webhookNotDeleted = db.webhooks().insertWebhook(projectNotToBeDeleted);
+ WebhookDeliveryLiteDto webhookDeliveryNotDeleted = db.webhookDelivery().insert(webhookNotDeleted);
+
+ underTest.deleteProject(dbSession, project1.uuid());
+
+ 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());
}
@Test
public void delete_branch_and_associated_data() {
- ComponentDto project = dbTester.components().insertMainBranch();
- ComponentDto branch = dbTester.components().insertProjectBranch(project);
+ ComponentDto project = db.components().insertMainBranch();
+ ComponentDto branch = db.components().insertProjectBranch(project);
underTest.deleteBranch(dbSession, project.uuid());
dbSession.commit();
- assertThat(dbTester.countRowsOfTable("project_branches")).isEqualTo(1);
- assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(1);
+ assertThat(db.countRowsOfTable("project_branches")).isEqualTo(1);
+ assertThat(db.countRowsOfTable("projects")).isEqualTo(1);
}
@Test
public void delete_row_in_ce_activity_when_deleting_project() {
- ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
- ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
+ ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
dbSession.commit();
- assertThat(dbTester.countRowsOfTable("ce_activity")).isEqualTo(1);
+ assertThat(db.countRowsOfTable("ce_activity")).isEqualTo(1);
}
@Test
public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_activity_when_deleting_project() {
- ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
- ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
+ ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
dbSession.commit();
- assertThat(dbTester.select("select uuid as \"UUID\" from ce_activity"))
+ assertThat(db.select("select uuid as \"UUID\" from ce_activity"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid());
- assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_input"))
+ assertThat(db.select("select task_uuid as \"UUID\" from ce_task_input"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid(), "non existing task");
}
@Test
public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_activity_when_deleting_project() {
- ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
- ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
+ ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
dbSession.commit();
- assertThat(dbTester.select("select uuid as \"UUID\" from ce_activity"))
+ assertThat(db.select("select uuid as \"UUID\" from ce_activity"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid());
- assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_scanner_context"))
+ assertThat(db.select("select task_uuid as \"UUID\" from ce_scanner_context"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid(), "non existing task");
}
@Test
public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_activity_when_deleting_project() {
- ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
- ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
+ ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
dbSession.commit();
- assertThat(dbTester.select("select uuid as \"UUID\" from ce_activity"))
+ assertThat(db.select("select uuid as \"UUID\" from ce_activity"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid());
- assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
+ assertThat(db.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid(), "non existing task");
}
@Test
public void delete_tasks_in_ce_queue_when_deleting_project() {
- ComponentDto projectToBeDeleted = dbTester.components().insertPrivateProject();
- ComponentDto anotherLivingProject = dbTester.components().insertPrivateProject();
+ ComponentDto projectToBeDeleted = db.components().insertPrivateProject();
+ ComponentDto anotherLivingProject = db.components().insertPrivateProject();
// Insert 3 rows in CE_QUEUE: two for the project that will be deleted (in order to check that status
// is not involved in deletion), and one on another project
underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
dbSession.commit();
- assertThat(dbTester.countRowsOfTable("ce_queue")).isEqualTo(1);
- assertThat(dbTester.countSql("select count(*) from ce_queue where component_uuid='" + projectToBeDeleted.uuid() + "'")).isEqualTo(0);
+ assertThat(db.countRowsOfTable("ce_queue")).isEqualTo(1);
+ assertThat(db.countSql("select count(*) from ce_queue where component_uuid='" + projectToBeDeleted.uuid() + "'")).isEqualTo(0);
}
@Test
public void delete_row_in_ce_task_input_referring_to_a_row_in_ce_queue_when_deleting_project() {
- ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
- ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
+ ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
dbSession.commit();
- assertThat(dbTester.select("select uuid as \"UUID\" from ce_queue"))
+ assertThat(db.select("select uuid as \"UUID\" from ce_queue"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid());
- assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_input"))
+ assertThat(db.select("select task_uuid as \"UUID\" from ce_task_input"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid(), "non existing task");
}
@Test
public void delete_row_in_ce_scanner_context_referring_to_a_row_in_ce_queue_when_deleting_project() {
- ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
- ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
+ ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
dbSession.commit();
- assertThat(dbTester.select("select uuid as \"UUID\" from ce_queue"))
+ assertThat(db.select("select uuid as \"UUID\" from ce_queue"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid());
- assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_scanner_context"))
+ assertThat(db.select("select task_uuid as \"UUID\" from ce_scanner_context"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid(), "non existing task");
}
@Test
public void delete_row_in_ce_task_characteristics_referring_to_a_row_in_ce_queue_when_deleting_project() {
- ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
- ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(dbTester.getDefaultOrganization());
+ ComponentDto projectToBeDeleted = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
+ ComponentDto anotherLivingProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization());
dbClient.componentDao().insert(dbSession, projectToBeDeleted, anotherLivingProject);
// Insert 2 rows in CE_ACTIVITY : one for the project that will be deleted, and one on another project
underTest.deleteProject(dbSession, projectToBeDeleted.uuid());
dbSession.commit();
- assertThat(dbTester.select("select uuid as \"UUID\" from ce_queue"))
+ assertThat(db.select("select uuid as \"UUID\" from ce_queue"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid());
- assertThat(dbTester.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
+ assertThat(db.select("select task_uuid as \"UUID\" from ce_task_characteristics"))
.extracting(row -> (String) row.get("UUID"))
.containsOnly(toNotDelete.getUuid(), "non existing task");
}
private ComponentDto insertProjectWithBranchAndRelatedData() {
- RuleDefinitionDto rule = dbTester.rules().insert();
- ComponentDto project = dbTester.components().insertMainBranch();
- ComponentDto branch = dbTester.components().insertProjectBranch(project);
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(branch));
- ComponentDto subModule = dbTester.components().insertComponent(newModuleDto(module));
- ComponentDto file = dbTester.components().insertComponent(newFileDto(subModule));
- dbTester.issues().insert(rule, branch, file);
- dbTester.issues().insert(rule, branch, subModule);
- dbTester.issues().insert(rule, branch, module);
+ RuleDefinitionDto rule = db.rules().insert();
+ ComponentDto project = db.components().insertMainBranch();
+ ComponentDto branch = db.components().insertProjectBranch(project);
+ ComponentDto module = db.components().insertComponent(newModuleDto(branch));
+ ComponentDto subModule = db.components().insertComponent(newModuleDto(module));
+ ComponentDto file = db.components().insertComponent(newFileDto(subModule));
+ db.issues().insert(rule, branch, file);
+ db.issues().insert(rule, branch, subModule);
+ db.issues().insert(rule, branch, module);
return project;
}
@Test
public void delete_branch_content_when_deleting_project() {
ComponentDto anotherLivingProject = insertProjectWithBranchAndRelatedData();
- int projectEntryCount = dbTester.countRowsOfTable("projects");
- int issueCount = dbTester.countRowsOfTable("issues");
- int branchCount = dbTester.countRowsOfTable("project_branches");
+ int projectEntryCount = db.countRowsOfTable("projects");
+ int issueCount = db.countRowsOfTable("issues");
+ int branchCount = db.countRowsOfTable("project_branches");
ComponentDto projectToDelete = insertProjectWithBranchAndRelatedData();
- assertThat(dbTester.countRowsOfTable("projects")).isGreaterThan(projectEntryCount);
- assertThat(dbTester.countRowsOfTable("issues")).isGreaterThan(issueCount);
- assertThat(dbTester.countRowsOfTable("project_branches")).isGreaterThan(branchCount);
+ assertThat(db.countRowsOfTable("projects")).isGreaterThan(projectEntryCount);
+ assertThat(db.countRowsOfTable("issues")).isGreaterThan(issueCount);
+ assertThat(db.countRowsOfTable("project_branches")).isGreaterThan(branchCount);
underTest.deleteProject(dbSession, projectToDelete.uuid());
dbSession.commit();
- assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(projectEntryCount);
- assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(issueCount);
- assertThat(dbTester.countRowsOfTable("project_branches")).isEqualTo(branchCount);
+ assertThat(db.countRowsOfTable("projects")).isEqualTo(projectEntryCount);
+ assertThat(db.countRowsOfTable("issues")).isEqualTo(issueCount);
+ assertThat(db.countRowsOfTable("project_branches")).isEqualTo(branchCount);
}
@Test
public void delete_view_and_child() {
- dbTester.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
+ db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
underTest.deleteProject(dbSession, "A");
dbSession.commit();
- assertThat(dbTester.countSql("select count(1) from projects where uuid='A'")).isZero();
- assertThat(dbTester.countRowsOfTable("projects")).isZero();
+ assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero();
+ assertThat(db.countRowsOfTable("projects")).isZero();
}
@Test
public void deleteProject_fails_with_IAE_if_specified_component_is_module() {
- ComponentDto privateProject = dbTester.components().insertPrivateProject();
- ComponentDto module = dbTester.components().insertComponent(ComponentTesting.newModuleDto(privateProject));
+ ComponentDto privateProject = db.components().insertPrivateProject();
+ ComponentDto module = db.components().insertComponent(ComponentTesting.newModuleDto(privateProject));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Couldn't find root component with uuid " + module.uuid());
@Test
public void deleteProject_fails_with_IAE_if_specified_component_is_directory() {
- ComponentDto privateProject = dbTester.components().insertPrivateProject();
- ComponentDto directory = dbTester.components().insertComponent(newDirectory(privateProject, "A/B"));
+ ComponentDto privateProject = db.components().insertPrivateProject();
+ ComponentDto directory = db.components().insertComponent(newDirectory(privateProject, "A/B"));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Couldn't find root component with uuid " + directory.uuid());
@Test
public void deleteProject_fails_with_IAE_if_specified_component_is_file() {
- ComponentDto privateProject = dbTester.components().insertPrivateProject();
- ComponentDto file = dbTester.components().insertComponent(newFileDto(privateProject));
+ ComponentDto privateProject = db.components().insertPrivateProject();
+ ComponentDto file = db.components().insertComponent(newFileDto(privateProject));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Couldn't find root component with uuid " + file.uuid());
@Test
public void deleteProject_fails_with_IAE_if_specified_component_is_subview() {
- ComponentDto view = dbTester.components().insertView();
- ComponentDto subview = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
+ ComponentDto view = db.components().insertView();
+ ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubView(view));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Couldn't find root component with uuid " + subview.uuid());
@Test
public void delete_view_sub_view_and_tech_project() {
- dbTester.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
+ db.prepareDbUnit(getClass(), "view_sub_view_and_tech_project.xml");
// view
underTest.deleteProject(dbSession, "A");
dbSession.commit();
- assertThat(dbTester.countSql("select count(1) from projects where uuid='A'")).isZero();
+ assertThat(db.countSql("select count(1) from projects where uuid='A'")).isZero();
}
@Test
public void should_delete_old_closed_issues() {
- RuleDefinitionDto rule = dbTester.rules().insert();
- ComponentDto project = dbTester.components().insertMainBranch();
+ RuleDefinitionDto rule = db.rules().insert();
+ ComponentDto project = db.components().insertMainBranch();
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(project));
- ComponentDto file = dbTester.components().insertComponent(newFileDto(module));
+ ComponentDto module = db.components().insertComponent(newModuleDto(project));
+ ComponentDto file = db.components().insertComponent(newFileDto(module));
- IssueDto oldClosed = dbTester.issues().insert(rule, project, file, issue -> {
+ IssueDto oldClosed = db.issues().insert(rule, project, file, issue -> {
issue.setStatus("CLOSED");
issue.setIssueCloseDate(DateUtils.addDays(new Date(), -31));
});
- IssueDto notOldEnoughClosed = dbTester.issues().insert(rule, project, file, issue -> {
+ IssueDto notOldEnoughClosed = db.issues().insert(rule, project, file, issue -> {
issue.setStatus("CLOSED");
issue.setIssueCloseDate(new Date());
});
- IssueDto notClosed = dbTester.issues().insert(rule, project, file);
+ IssueDto notClosed = db.issues().insert(rule, project, file);
when(system2.now()).thenReturn(new Date().getTime());
underTest.purge(dbSession, newConfigurationWith30Days(system2, project.uuid()), PurgeListener.EMPTY, new PurgeProfiler());
dbSession.commit();
// old closed got deleted
- assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, oldClosed.getKey())).isEmpty();
+ assertThat(db.getDbClient().issueDao().selectByKey(dbSession, oldClosed.getKey())).isEmpty();
// others remain
- assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(2);
- assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, notOldEnoughClosed.getKey())).isNotEmpty();
- assertThat(dbTester.getDbClient().issueDao().selectByKey(dbSession, notClosed.getKey())).isNotEmpty();
+ assertThat(db.countRowsOfTable("issues")).isEqualTo(2);
+ assertThat(db.getDbClient().issueDao().selectByKey(dbSession, notOldEnoughClosed.getKey())).isNotEmpty();
+ assertThat(db.getDbClient().issueDao().selectByKey(dbSession, notClosed.getKey())).isNotEmpty();
}
@Test
public void deleteProject_deletes_webhook_deliveries() {
- ComponentDto project = dbTester.components().insertPublicProject();
+ ComponentDto project = db.components().insertPublicProject();
dbClient.webhookDeliveryDao().insert(dbSession, newDto().setComponentUuid(project.uuid()).setUuid("D1").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
dbClient.webhookDeliveryDao().insert(dbSession, newDto().setComponentUuid("P2").setUuid("D2").setDurationMs(1000).setWebhookUuid("webhook-uuid"));
underTest.deleteProject(dbSession, project.uuid());
- assertThat(selectAllDeliveryUuids(dbTester, dbSession)).containsOnly("D2");
+ assertThat(selectAllDeliveryUuids(db, dbSession)).containsOnly("D2");
}
@Test
public void deleteProject_deletes_project_mappings() {
- ComponentDto project = dbTester.components().insertPublicProject();
+ ComponentDto project = db.components().insertPublicProject();
dbClient.projectMappingsDao().put(dbSession, "a.key.type", "a.key", project.uuid());
dbClient.projectMappingsDao().put(dbSession, "a.key.type", "another.key", "D2");
String repoId = "123";
String otherRepoId = repoId + "-foo";
- ComponentDto project = dbTester.components().insertPublicProject();
- ComponentDto otherProject = dbTester.components().insertPublicProject();
+ ComponentDto project = db.components().insertPublicProject();
+ ComponentDto otherProject = db.components().insertPublicProject();
dbClient.projectAlmBindingsDao().insertOrUpdate(dbSession, alm, repoId, project.uuid(), null, "foo");
dbClient.projectAlmBindingsDao().insertOrUpdate(dbSession, alm, otherRepoId, otherProject.uuid(), null, "bar");
@Test
public void deleteNonRootComponents_has_no_effect_when_parameter_contains_only_projects_and_or_views() {
- ComponentDbTester componentDbTester = dbTester.components();
+ ComponentDbTester componentDbTester = db.components();
verifyNoEffect(componentDbTester.insertPrivateProject());
verifyNoEffect(componentDbTester.insertPublicProject());
@Test
public void delete_live_measures_when_deleting_project() {
- MetricDto metric = dbTester.measures().insertMetric();
+ MetricDto metric = db.measures().insertMetric();
- ComponentDto project1 = dbTester.components().insertPublicProject();
- ComponentDto module1 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project1));
- dbTester.measures().insertLiveMeasure(project1, metric);
- dbTester.measures().insertLiveMeasure(module1, metric);
+ ComponentDto project1 = db.components().insertPublicProject();
+ ComponentDto module1 = db.components().insertComponent(ComponentTesting.newModuleDto(project1));
+ db.measures().insertLiveMeasure(project1, metric);
+ db.measures().insertLiveMeasure(module1, metric);
- ComponentDto project2 = dbTester.components().insertPublicProject();
- ComponentDto module2 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project2));
- dbTester.measures().insertLiveMeasure(project2, metric);
- dbTester.measures().insertLiveMeasure(module2, metric);
+ ComponentDto project2 = db.components().insertPublicProject();
+ ComponentDto module2 = db.components().insertComponent(ComponentTesting.newModuleDto(project2));
+ db.measures().insertLiveMeasure(project2, metric);
+ db.measures().insertLiveMeasure(module2, metric);
underTest.deleteProject(dbSession, project1.uuid());
@Test
public void deleteNonRootComponents_deletes_only_non_root_components_of_a_project_from_table_PROJECTS() {
- ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPublicProject() : dbTester.components().insertPrivateProject();
- ComponentDto module1 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project));
- ComponentDto module2 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(module1));
- ComponentDto dir1 = dbTester.components().insertComponent(newDirectory(module1, "A/B"));
+ 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));
+ ComponentDto dir1 = db.components().insertComponent(newDirectory(module1, "A/B"));
List<ComponentDto> components = asList(
project,
module1,
module2,
dir1,
- dbTester.components().insertComponent(newDirectory(module2, "A/C")),
- dbTester.components().insertComponent(newFileDto(dir1)),
- dbTester.components().insertComponent(newFileDto(module2)),
- dbTester.components().insertComponent(newFileDto(project)));
+ db.components().insertComponent(newDirectory(module2, "A/C")),
+ db.components().insertComponent(newFileDto(dir1)),
+ db.components().insertComponent(newFileDto(module2)),
+ db.components().insertComponent(newFileDto(project)));
Collections.shuffle(components);
underTest.deleteNonRootComponentsInView(dbSession, components);
@Test
public void deleteNonRootComponents_deletes_only_non_root_components_of_a_view_from_table_PROJECTS() {
ComponentDto[] projects = {
- dbTester.components().insertPrivateProject(),
- dbTester.components().insertPrivateProject(),
- dbTester.components().insertPrivateProject()
+ db.components().insertPrivateProject(),
+ db.components().insertPrivateProject(),
+ db.components().insertPrivateProject()
};
- ComponentDto view = dbTester.components().insertView();
- ComponentDto subview1 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
- ComponentDto subview2 = dbTester.components().insertComponent(ComponentTesting.newSubView(subview1));
+ ComponentDto view = db.components().insertView();
+ ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view));
+ ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1));
List<ComponentDto> components = asList(
view,
subview1,
subview2,
- dbTester.components().insertComponent(newProjectCopy("a", projects[0], view)),
- dbTester.components().insertComponent(newProjectCopy("b", projects[1], subview1)),
- dbTester.components().insertComponent(newProjectCopy("c", projects[2], subview2)));
+ db.components().insertComponent(newProjectCopy("a", projects[0], view)),
+ db.components().insertComponent(newProjectCopy("b", projects[1], subview1)),
+ db.components().insertComponent(newProjectCopy("c", projects[2], subview2)));
Collections.shuffle(components);
underTest.deleteNonRootComponentsInView(dbSession, components);
}
private Stream<String> getUuidsInTableProjects() {
- return dbTester.select("select uuid as \"UUID\" from projects").stream().map(row -> (String) row.get("UUID"));
+ return db.select("select uuid as \"UUID\" from projects").stream().map(row -> (String) row.get("UUID"));
}
@Test
public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_project_from_table_PROJECTS() {
- ComponentDto project = new Random().nextBoolean() ? dbTester.components().insertPublicProject() : dbTester.components().insertPrivateProject();
- ComponentDto module1 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(project));
- ComponentDto module2 = dbTester.components().insertComponent(ComponentTesting.newModuleDto(module1));
- ComponentDto dir1 = dbTester.components().insertComponent(newDirectory(module1, "A/B"));
- ComponentDto dir2 = dbTester.components().insertComponent(newDirectory(module2, "A/C"));
- ComponentDto file1 = dbTester.components().insertComponent(newFileDto(dir1));
- ComponentDto file2 = dbTester.components().insertComponent(newFileDto(module2));
- ComponentDto file3 = dbTester.components().insertComponent(newFileDto(project));
+ 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));
+ ComponentDto dir1 = db.components().insertComponent(newDirectory(module1, "A/B"));
+ ComponentDto dir2 = db.components().insertComponent(newDirectory(module2, "A/C"));
+ ComponentDto file1 = db.components().insertComponent(newFileDto(dir1));
+ ComponentDto file2 = db.components().insertComponent(newFileDto(module2));
+ ComponentDto file3 = db.components().insertComponent(newFileDto(project));
underTest.deleteNonRootComponentsInView(dbSession, singletonList(file3));
assertThat(getUuidsInTableProjects())
@Test
public void deleteNonRootComponents_deletes_only_specified_non_root_components_of_a_view_from_table_PROJECTS() {
ComponentDto[] projects = {
- dbTester.components().insertPrivateProject(),
- dbTester.components().insertPrivateProject(),
- dbTester.components().insertPrivateProject()
+ db.components().insertPrivateProject(),
+ db.components().insertPrivateProject(),
+ db.components().insertPrivateProject()
};
- ComponentDto view = dbTester.components().insertView();
- ComponentDto subview1 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
- ComponentDto subview2 = dbTester.components().insertComponent(ComponentTesting.newSubView(subview1));
- ComponentDto pc1 = dbTester.components().insertComponent(newProjectCopy("a", projects[0], view));
- ComponentDto pc2 = dbTester.components().insertComponent(newProjectCopy("b", projects[1], subview1));
- ComponentDto pc3 = dbTester.components().insertComponent(newProjectCopy("c", projects[2], subview2));
+ ComponentDto view = db.components().insertView();
+ ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view));
+ ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1));
+ ComponentDto pc1 = db.components().insertComponent(newProjectCopy("a", projects[0], view));
+ ComponentDto pc2 = db.components().insertComponent(newProjectCopy("b", projects[1], subview1));
+ ComponentDto pc3 = db.components().insertComponent(newProjectCopy("c", projects[2], subview2));
underTest.deleteNonRootComponentsInView(dbSession, singletonList(pc3));
assertThat(getUuidsInTableProjects())
@Test
public void deleteNonRootComponents_deletes_measures_of_any_non_root_component_of_a_view() {
- ComponentDto view = dbTester.components().insertView();
- ComponentDto subview = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
- ComponentDto pc = dbTester.components().insertComponent(newProjectCopy("a", dbTester.components().insertPrivateProject(), view));
+ ComponentDto view = db.components().insertView();
+ ComponentDto subview = db.components().insertComponent(ComponentTesting.newSubView(view));
+ ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view));
insertMeasureFor(view, subview, pc);
assertThat(getComponentUuidsOfMeasures()).containsOnly(view.uuid(), subview.uuid(), pc.uuid());
@Test
public void deleteNonRootComponents_deletes_properties_of_subviews_of_a_view() {
- ComponentDto view = dbTester.components().insertView();
- ComponentDto subview1 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
- ComponentDto subview2 = dbTester.components().insertComponent(ComponentTesting.newSubView(subview1));
- ComponentDto subview3 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
- ComponentDto pc = dbTester.components().insertComponent(newProjectCopy("a", dbTester.components().insertPrivateProject(), view));
+ ComponentDto view = db.components().insertView();
+ ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view));
+ ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1));
+ ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubView(view));
+ ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view));
insertPropertyFor(view, subview1, subview2, subview3, pc);
assertThat(getResourceIdOfProperties()).containsOnly(view.getId(), subview1.getId(), subview2.getId(), subview3.getId(), pc.getId());
@Test
public void deleteNonRootComponentsInView_deletes_manual_measures_of_subviews_of_a_view() {
- ComponentDto view = dbTester.components().insertView();
- ComponentDto subview1 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
- ComponentDto subview2 = dbTester.components().insertComponent(ComponentTesting.newSubView(subview1));
- ComponentDto subview3 = dbTester.components().insertComponent(ComponentTesting.newSubView(view));
- ComponentDto pc = dbTester.components().insertComponent(newProjectCopy("a", dbTester.components().insertPrivateProject(), view));
+ ComponentDto view = db.components().insertView();
+ ComponentDto subview1 = db.components().insertComponent(ComponentTesting.newSubView(view));
+ ComponentDto subview2 = db.components().insertComponent(ComponentTesting.newSubView(subview1));
+ ComponentDto subview3 = db.components().insertComponent(ComponentTesting.newSubView(view));
+ ComponentDto pc = db.components().insertComponent(newProjectCopy("a", db.components().insertPrivateProject(), view));
insertManualMeasureFor(view, subview1, subview2, subview3, pc);
assertThat(getComponentUuidsOfManualMeasures()).containsOnly(view.uuid(), subview1.uuid(), subview2.uuid(), subview3.uuid(), pc.uuid());
}
private Stream<String> getComponentUuidsOfManualMeasures() {
- return dbTester.select("select component_uuid as \"COMPONENT_UUID\" from manual_measures").stream()
+ return db.select("select component_uuid as \"COMPONENT_UUID\" from manual_measures").stream()
.map(row -> (String) row.get("COMPONENT_UUID"));
}
private Stream<Long> getResourceIdOfProperties() {
- return dbTester.select("select resource_id as \"ID\" from properties").stream()
+ return db.select("select resource_id as \"ID\" from properties").stream()
.map(row -> (Long) row.get("ID"));
}
private void insertPropertyFor(ComponentDto... components) {
- Stream.of(components).forEach(componentDto -> dbTester.properties().insertProperty(new PropertyDto()
+ Stream.of(components).forEach(componentDto -> db.properties().insertProperty(new PropertyDto()
.setKey(randomAlphabetic(3))
.setValue(randomAlphabetic(3))
.setResourceId(componentDto.getId())));
}
private Stream<String> getComponentUuidsOfMeasures() {
- return dbTester.select("select component_uuid as \"COMPONENT_UUID\" from project_measures").stream()
+ return db.select("select component_uuid as \"COMPONENT_UUID\" from project_measures").stream()
.map(row -> (String) row.get("COMPONENT_UUID"));
}
private void insertMeasureFor(ComponentDto... components) {
- Arrays.stream(components).forEach(componentDto -> dbTester.getDbClient().measureDao().insert(dbSession, new MeasureDto()
+ Arrays.stream(components).forEach(componentDto -> db.getDbClient().measureDao().insert(dbSession, new MeasureDto()
.setMetricId(new Random().nextInt())
.setComponentUuid(componentDto.uuid())
.setAnalysisUuid(randomAlphabetic(3))));
@Test
public void selectOrderedByComponentUuid_returns_empty_if_no_records() {
- underTest.insert(dbSession, WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByComponentUuid(dbSession, "ANOTHER_COMPONENT", 0, 10);
@Test
public void selectOrderedByComponentUuid_returns_records_ordered_by_date() {
- WebhookDeliveryDto dto1 = WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
- WebhookDeliveryDto dto2 = WebhookDbTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
- WebhookDeliveryDto dto3 = WebhookDbTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
+ WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
+ WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
+ WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
underTest.insert(dbSession, dto3);
underTest.insert(dbSession, dto2);
underTest.insert(dbSession, dto1);
@Test
public void selectOrderedByCeTaskUuid_returns_empty_if_no_records() {
- underTest.insert(dbSession, WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectOrderedByCeTaskUuid(dbSession, "ANOTHER_TASK", 0, 10);
@Test
public void selectOrderedByCeTaskUuid_returns_records_ordered_by_date() {
- WebhookDeliveryDto dto1 = WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
- WebhookDeliveryDto dto2 = WebhookDbTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
- WebhookDeliveryDto dto3 = WebhookDbTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_2").setCreatedAt(NOW);
+ WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
+ WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(NOW);
+ WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_2").setCreatedAt(NOW);
underTest.insert(dbSession, dto3);
underTest.insert(dbSession, dto2);
underTest.insert(dbSession, dto1);
@Test
public void selectByWebhookUuid_returns_empty_if_no_records() {
- underTest.insert(dbSession, WebhookDbTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1"));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, "a-webhook-uuid", 0, 10);
@Test
public void selectByWebhookUuid_returns_records_ordered_by_date() {
WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
- WebhookDeliveryDto dto1 = WebhookDbTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
- WebhookDeliveryDto dto2 = WebhookDbTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW);
- WebhookDeliveryDto dto3 = WebhookDbTesting.newDto("D3", "fake-webhook-uuid", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
+ WebhookDeliveryDto dto1 = WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE);
+ WebhookDeliveryDto dto2 = WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW);
+ WebhookDeliveryDto dto3 = WebhookDeliveryTesting.newDto("D3", "fake-webhook-uuid", "COMPONENT_2", "TASK_1").setCreatedAt(NOW);
underTest.insert(dbSession, dto3);
underTest.insert(dbSession, dto2);
underTest.insert(dbSession, dto1);
@Test
public void selectByWebhookUuid_returns_records_according_to_pagination() {
WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
- underTest.insert(dbSession, WebhookDbTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 5_000L));
- underTest.insert(dbSession, WebhookDbTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 4_000L));
- underTest.insert(dbSession, WebhookDbTesting.newDto("D3", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 3_000L));
- underTest.insert(dbSession, WebhookDbTesting.newDto("D4", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 2_000L));
- underTest.insert(dbSession, WebhookDbTesting.newDto("D5", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 1_000L));
- underTest.insert(dbSession, WebhookDbTesting.newDto("D6", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D1", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 5_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 4_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D3", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 3_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D4", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 2_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D5", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW - 1_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("D6", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
List<WebhookDeliveryLiteDto> deliveries = underTest.selectByWebhookUuid(dbSession, webhookDto.getUuid(), 2, 2);
@Test
public void selectLatestDelivery_of_a_webhook() {
WebhookDto webhook1 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
- underTest.insert(dbSession, WebhookDbTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
- underTest.insert(dbSession, WebhookDbTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-1-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH1-DELIVERY-2-UUID", webhook1.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
WebhookDto webhook2 = dbWebhooks.insert(newProjectWebhook("COMPONENT_1"));
- underTest.insert(dbSession, WebhookDbTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
- underTest.insert(dbSession, WebhookDbTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-1-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(BEFORE));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("WH2-DELIVERY-2-UUID", webhook2.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(NOW));
Map<String, WebhookDeliveryLiteDto> map = underTest.selectLatestDeliveries(dbSession, of(webhook1, webhook2));
@Test
public void insert_row_with_only_mandatory_columns() {
- WebhookDeliveryDto dto = WebhookDbTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1")
+ WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1")
.setDurationMs(1000)
.setHttpStatus(null)
.setErrorStacktrace(null);
@Test
public void insert_row_with_all_columns() {
- WebhookDeliveryDto dto = WebhookDbTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1");
+ WebhookDeliveryDto dto = WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1");
underTest.insert(dbSession, dto);
WebhookDto webhookDto = dbWebhooks.insert(WebhookTesting.newProjectWebhook("COMPONENT_1"));
- underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
- underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
- underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_3", "WONT BE DELETED WEBHOOK_UUID_2", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", webhookDto.getUuid(), "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", webhookDto.getUuid(), "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WONT BE DELETED WEBHOOK_UUID_2", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
underTest.deleteByWebhook(dbSession, webhookDto);
@Test
public void deleteComponentBeforeDate_deletes_rows_before_date() {
- underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
- underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
- underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_2", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_2").setCreatedAt(2_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_3", "WEBHOOK_UUID_1", "COMPONENT_2", "TASK_3").setCreatedAt(1_000_000L));
// should delete the old delivery on COMPONENT_1 and keep the one of COMPONENT_2
underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_1", 1_500_000L);
@Test
public void deleteComponentBeforeDate_does_nothing_on_invalid_uuid() {
- underTest.insert(dbSession, WebhookDbTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
+ underTest.insert(dbSession, WebhookDeliveryTesting.newDto("DELIVERY_1", "WEBHOOK_UUID_1", "COMPONENT_1", "TASK_1").setCreatedAt(1_000_000L));
underTest.deleteComponentBeforeDate(dbSession, "COMPONENT_2", 1_500_000L);