private static ComponentDto createButDoNotInsertBranch(ComponentDto project) { BranchType randomBranchType = BranchType.values()[new Random().nextInt(BranchType.values().length)]; BranchDto branchDto = newBranchDto(project.projectUuid(), randomBranchType); return ComponentTesting.newProjectBranch(project, branchDto); }
@SafeVarargs public final ComponentDto insertProjectBranch(ComponentDto project, Consumer<BranchDto>... dtoPopulators) { // MainBranchProjectUuid will be null if it's a main branch BranchDto branchDto = newBranchDto(firstNonNull(project.getMainBranchProjectUuid(), project.projectUuid()), LONG); Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(branchDto)); ComponentDto branch = newProjectBranch(project, branchDto); insertComponent(branch); dbClient.branchDao().insert(dbSession, branchDto); db.commit(); return branch; }
public final ComponentDto insertProjectBranch(ComponentDto project, BranchDto branchDto) { // MainBranchProjectUuid will be null if it's a main branch checkArgument(branchDto.getProjectUuid().equals(firstNonNull(project.getMainBranchProjectUuid(), project.projectUuid()))); ComponentDto branch = newProjectBranch(project, branchDto); insertComponent(branch); dbClient.branchDao().insert(dbSession, branchDto); db.commit(); return branch; }
@Test public void execute_changes_private_flag_of_specified_project_and_all_children_to_specified_new_visibility() { ComponentDto project = randomPublicOrPrivateProject(); boolean initiallyPrivate = project.isPrivate(); BranchDto branchDto = ComponentTesting.newBranchDto(project); dbClient.branchDao().insert(dbSession, branchDto); ComponentDto branch = ComponentTesting.newProjectBranch(project, branchDto); ComponentDto module = ComponentTesting.newModuleDto(project); ComponentDto dir = ComponentTesting.newDirectory(project, "path"); ComponentDto file = ComponentTesting.newFileDto(project); dbTester.components().insertComponents(branch, module, dir, file); userSessionRule.addProjectPermission(UserRole.ADMIN, project); request.setParam(PARAM_PROJECT, project.getDbKey()) .setParam(PARAM_VISIBILITY, initiallyPrivate ? PUBLIC : PRIVATE) .execute(); assertThat(isPrivateInDb(project)).isEqualTo(!initiallyPrivate); assertThat(isPrivateInDb(branch)).isEqualTo(!initiallyPrivate); assertThat(isPrivateInDb(module)).isEqualTo(!initiallyPrivate); assertThat(isPrivateInDb(dir)).isEqualTo(!initiallyPrivate); assertThat(isPrivateInDb(file)).isEqualTo(!initiallyPrivate); }
@Test @UseDataProvider("nullOrNotNullString") public void persist_creates_row_in_PROJECTS_BRANCHES_for_long_branch(@Nullable String mergeBranchUuid) { String branchName = "branch"; // add project and branch in table PROJECTS ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getKey()); ComponentDto component = ComponentTesting.newProjectBranch(mainComponent, new BranchDto().setUuid(BRANCH.getUuid()).setKey(BRANCH.getKey()).setBranchType(LONG)); dbTester.getDbClient().componentDao().insert(dbTester.getSession(), mainComponent, component); dbTester.commit(); // set project in metadata treeRootHolder.setRoot(BRANCH); analysisMetadataHolder.setBranch(createBranch(LONG, false, branchName, mergeBranchUuid)); analysisMetadataHolder.setProject(Project.from(mainComponent)); underTest.persist(dbTester.getSession()); dbTester.getSession().commit(); assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(2); Optional<BranchDto> branchDto = dbTester.getDbClient().branchDao().selectByUuid(dbTester.getSession(), BRANCH.getUuid()); assertThat(branchDto).isPresent(); assertThat(branchDto.get().getBranchType()).isEqualTo(LONG); assertThat(branchDto.get().getKey()).isEqualTo(branchName); assertThat(branchDto.get().getMergeBranchUuid()).isEqualTo(mergeBranchUuid); assertThat(branchDto.get().getProjectUuid()).isEqualTo(MAIN.getUuid()); assertThat(branchDto.get().getPullRequestData()).isNull(); }
@Test public void execute_has_no_effect_if_specified_project_already_has_specified_visibility() { ComponentDto project = randomPublicOrPrivateProject(); boolean initiallyPrivate = project.isPrivate(); BranchDto branchDto = ComponentTesting.newBranchDto(project); dbClient.branchDao().insert(dbSession, branchDto); ComponentDto branch = ComponentTesting.newProjectBranch(project, branchDto) .setPrivate(initiallyPrivate); ComponentDto module = ComponentTesting.newModuleDto(project) .setPrivate(initiallyPrivate); ComponentDto dir = ComponentTesting.newDirectory(project, "path") // child is inconsistent with root (should not occur) and won't be fixed .setPrivate(!initiallyPrivate); ComponentDto file = ComponentTesting.newFileDto(project) .setPrivate(initiallyPrivate); dbTester.components().insertComponents(branch, module, dir, file); userSessionRule.addProjectPermission(UserRole.ADMIN, project); request.setParam(PARAM_PROJECT, project.getDbKey()) .setParam(PARAM_VISIBILITY, initiallyPrivate ? PRIVATE : PUBLIC) .execute(); assertThat(isPrivateInDb(project)).isEqualTo(initiallyPrivate); assertThat(isPrivateInDb(branch)).isEqualTo(initiallyPrivate); assertThat(isPrivateInDb(module)).isEqualTo(initiallyPrivate); assertThat(isPrivateInDb(dir)).isEqualTo(!initiallyPrivate); assertThat(isPrivateInDb(file)).isEqualTo(initiallyPrivate); }
@Test @UseDataProvider("nullOrNotNullString") public void persist_creates_row_in_PROJECTS_BRANCHES_for_pull_request(@Nullable String mergeBranchUuid) { String pullRequestId = "pr-123"; // add project and branch in table PROJECTS ComponentDto mainComponent = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getKey()); ComponentDto component = ComponentTesting.newProjectBranch(mainComponent, new BranchDto().setUuid(BRANCH.getUuid()).setKey(BRANCH.getKey()).setBranchType(PULL_REQUEST)); dbTester.getDbClient().componentDao().insert(dbTester.getSession(), mainComponent, component); dbTester.commit(); // set project in metadata treeRootHolder.setRoot(BRANCH); analysisMetadataHolder.setBranch(createBranch(PULL_REQUEST, false, pullRequestId, mergeBranchUuid)); analysisMetadataHolder.setProject(Project.from(mainComponent)); analysisMetadataHolder.setPullRequestKey(pullRequestId); underTest.persist(dbTester.getSession()); dbTester.getSession().commit(); assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(2); Optional<BranchDto> branchDto = dbTester.getDbClient().branchDao().selectByUuid(dbTester.getSession(), BRANCH.getUuid()); assertThat(branchDto).isPresent(); assertThat(branchDto.get().getBranchType()).isEqualTo(PULL_REQUEST); assertThat(branchDto.get().getKey()).isEqualTo(pullRequestId); assertThat(branchDto.get().getMergeBranchUuid()).isEqualTo(mergeBranchUuid); assertThat(branchDto.get().getProjectUuid()).isEqualTo(MAIN.getUuid()); assertThat(branchDto.get().getPullRequestData()).isEqualTo(DbProjectBranches.PullRequestData.newBuilder() .setBranch(pullRequestId) .setTitle(pullRequestId) .build()); }
private void sendIssueChangeNotificationOnBranch(long issueCreatedAt) { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto branch = newProjectBranch(project, newBranchDto(project).setKey(BRANCH_NAME)); ComponentDto file = newFileDto(branch); treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build()); RuleDefinitionDto ruleDefinitionDto = newRule(); RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)]; DefaultIssue issue = newIssue(ruleDefinitionDto, branch, file).setType(randomTypeExceptHotspot).toDefaultIssue() .setNew(false) .setChanged(true) .setSendNotifications(true) .setCreationDate(new Date(issueCreatedAt)); ruleRepository.add(ruleDefinitionDto.getKey()).setName(ruleDefinitionDto.getName()); issueCache.newAppender().append(issue).close(); when(notificationService.hasProjectSubscribersForTypes(branch.uuid(), NOTIF_TYPES)).thenReturn(true); analysisMetadataHolder.setBranch(newBranch()); underTest.execute(new TestComputationStepContext()); ArgumentCaptor<IssueChangeNotification> issueChangeNotificationCaptor = forClass(IssueChangeNotification.class); verify(notificationService).deliver(issueChangeNotificationCaptor.capture()); IssueChangeNotification issueChangeNotification = issueChangeNotificationCaptor.getValue(); assertThat(issueChangeNotification.getFieldValue("projectName")).isEqualTo(branch.longName()); assertThat(issueChangeNotification.getFieldValue("projectKey")).isEqualTo(branch.getKey()); assertThat(issueChangeNotification.getFieldValue("branch")).isEqualTo(BRANCH_NAME); assertThat(issueChangeNotification.getFieldValue("componentKey")).isEqualTo(file.getKey()); assertThat(issueChangeNotification.getFieldValue("componentName")).isEqualTo(file.longName()); }
db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectB, null); BranchDto branchProjectA = newBranchDto(referencedProjectA); ComponentDto cptBranchProjectA = ComponentTesting.newProjectBranch(referencedProjectA, branchProjectA); db.events().insertEventComponentChanges(projectEvent2, projectAnalysis2, randomChangeCategory(), cptBranchProjectA, branchProjectA);
@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 anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeQueueDto projectTask = insertCeQueue(project); insertCeTaskInput(projectTask.getUuid()); CeQueueDto branchTask = insertCeQueue(branch); insertCeTaskInput(branchTask.getUuid()); CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); insertCeTaskInput(anotherBranchTask.getUuid()); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeTaskInput(anotherProjectTask.getUuid()); insertCeTaskInput("non existing task"); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_input")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_input")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@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 anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeQueueDto projectTask = insertCeQueue(project); insertCeTaskMessages(projectTask.getUuid(), 3); CeQueueDto branchTask = insertCeQueue(branch); insertCeTaskMessages(branchTask.getUuid(), 1); CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); insertCeTaskMessages(anotherBranchTask.getUuid(), 5); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeTaskMessages(anotherProjectTask.getUuid(), 2); insertCeTaskMessages("non existing task", 5); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_message")) .containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_message")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@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 anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeActivityDto projectTask = insertCeActivity(project); insertCeTaskCharacteristics(projectTask.getUuid(), 3); CeActivityDto branchTask = insertCeActivity(branch); insertCeTaskCharacteristics(branchTask.getUuid(), 2); CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); insertCeTaskCharacteristics(anotherBranchTask.getUuid(), 6); CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); insertCeTaskCharacteristics(anotherProjectTask.getUuid(), 2); insertCeTaskCharacteristics("non existing task", 5); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_characteristics")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_characteristics")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@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 anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeActivityDto projectTask = insertCeActivity(project); insertCeTaskMessages(projectTask.getUuid(), 3); CeActivityDto branchTask = insertCeActivity(branch); insertCeTaskMessages(branchTask.getUuid(), 2); CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); insertCeTaskMessages(anotherBranchTask.getUuid(), 6); CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); insertCeTaskMessages(anotherProjectTask.getUuid(), 2); insertCeTaskMessages("non existing task", 5); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_message")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_message")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@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 anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeActivityDto projectTask = insertCeActivity(project); insertCeTaskInput(projectTask.getUuid()); CeActivityDto branchTask = insertCeActivity(branch); insertCeTaskInput(branchTask.getUuid()); CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); insertCeTaskInput(anotherBranchTask.getUuid()); CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); insertCeTaskInput(anotherProjectTask.getUuid()); insertCeTaskInput("non existing task"); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_input")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_input")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@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 anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeActivityDto projectTask = insertCeActivity(project); insertCeScannerContext(projectTask.getUuid()); CeActivityDto branchTask = insertCeActivity(branch); insertCeScannerContext(branchTask.getUuid()); CeActivityDto anotherBranchTask = insertCeActivity(anotherBranch); insertCeScannerContext(anotherBranchTask.getUuid()); CeActivityDto anotherProjectTask = insertCeActivity(anotherProject); insertCeScannerContext(anotherProjectTask.getUuid()); insertCeScannerContext("non existing task"); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_scanner_context")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_activity")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_scanner_context")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@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 anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeQueueDto projectTask = insertCeQueue(project); insertCeTaskCharacteristics(projectTask.getUuid(), 3); CeQueueDto branchTask = insertCeQueue(branch); insertCeTaskCharacteristics(branchTask.getUuid(), 1); CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); insertCeTaskCharacteristics(anotherBranchTask.getUuid(), 5); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeTaskCharacteristics(anotherProjectTask.getUuid(), 2); insertCeTaskCharacteristics("non existing task", 5); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_characteristics")) .containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_task_characteristics")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@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 anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); CeQueueDto projectTask = insertCeQueue(project); insertCeScannerContext(projectTask.getUuid()); CeQueueDto branchTask = insertCeQueue(branch); insertCeScannerContext(branchTask.getUuid()); CeQueueDto anotherBranchTask = insertCeQueue(anotherBranch); insertCeScannerContext(anotherBranchTask.getUuid()); CeQueueDto anotherProjectTask = insertCeQueue(anotherProject); insertCeScannerContext(anotherProjectTask.getUuid()); insertCeScannerContext("non existing task"); dbSession.commit(); underTest.deleteProject(dbSession, branch.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_scanner_context")) .containsOnly(projectTask.getUuid(), anotherBranchTask.getUuid(), anotherProjectTask.getUuid(), "non existing task"); underTest.deleteProject(dbSession, project.uuid()); dbSession.commit(); assertThat(uuidsIn("ce_queue")).containsOnly(anotherProjectTask.getUuid()); assertThat(taskUuidsIn("ce_scanner_context")).containsOnly(anotherProjectTask.getUuid(), "non existing task"); }
@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 anotherProject = ComponentTesting.newPrivateProjectDto(db.getDefaultOrganization()); dbClient.componentDao().insert(dbSession, project, branch, anotherBranch, anotherProject); db.events().insertEventComponentChanges(projectEvent1, projectAnalysis1, randomChangeCategory(), referencedProjectB, null); BranchDto branchProjectA = newBranchDto(referencedProjectA); ComponentDto cptBranchProjectA = ComponentTesting.newProjectBranch(referencedProjectA, branchProjectA); db.events().insertEventComponentChanges(projectEvent2, projectAnalysis2, randomChangeCategory(), cptBranchProjectA, branchProjectA);
private ComponentDto setUpProjectWithBranch() { ComponentDto project = newPrivateProjectDto(newOrganizationDto()); ComponentDto branch = newProjectBranch(project, newBranchDto(project).setKey(BRANCH_NAME)); ComponentDto file = newFileDto(branch); treeRootHolder.setRoot(builder(Type.PROJECT, 2).setKey(branch.getDbKey()).setPublicKey(branch.getKey()).setName(branch.longName()).setUuid(branch.uuid()).addChildren( builder(Type.FILE, 11).setKey(file.getDbKey()).setPublicKey(file.getKey()).setName(file.longName()).build()).build()); return branch; }