public static BranchDto newBranchDto(ComponentDto project) { return newBranchDto(project.projectUuid(), BranchType.LONG); }
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 insertMainBranch(OrganizationDto organization, String mainBranchName, Consumer<ComponentDto>... dtoPopulators) { ComponentDto project = newPrivateProjectDto(organization); BranchDto branchDto = newBranchDto(project, LONG).setKey(mainBranchName); Arrays.stream(dtoPopulators).forEach(dtoPopulator -> dtoPopulator.accept(project)); insertComponent(project); dbClient.branchDao().insert(dbSession, branchDto); db.commit(); return project; }
@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 insertMainBranch(ComponentDto project) { BranchDto branchDto = newBranchDto(project, LONG); insertComponent(project); dbClient.branchDao().insert(dbSession, branchDto); db.commit(); return project; }
public ComponentAndBranch insertProjectBranch(ComponentDto project, BranchType type, String branchKey) { BranchDto branchDto = newBranchDto(project.projectUuid(), type).setKey(branchKey); ComponentDto newComponent = dbTester.components().insertProjectBranch(project, branchDto); return new ComponentAndBranch(newComponent, branchDto); }
@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 public void loadQualityGate_returns_hardcoded_gate_for_pull_requests() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization); BranchDto pullRequest = newBranchDto(project).setBranchType(BranchType.PULL_REQUEST); db.components().insertProjectBranch(project, pullRequest); QualityGate result = underTest.loadQualityGate(db.getSession(), organization, project, pullRequest); assertThat(result).isSameAs(ShortLivingBranchQualityGate.GATE); }
@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 public void loadQualityGate_returns_hardcoded_gate_for_short_living_branches() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization); BranchDto branch = newBranchDto(project).setBranchType(BranchType.SHORT); db.components().insertProjectBranch(project, branch); QualityGate result = underTest.loadQualityGate(db.getSession(), organization, project, branch); assertThat(result).isSameAs(ShortLivingBranchQualityGate.GATE); }
public ComponentAndBranch insertMainBranch(OrganizationDto organization) { ComponentDto project = newPrivateProjectDto(organization); BranchDto branch = newBranchDto(project, LONG).setKey("master"); dbTester.components().insertComponent(project); dbClient.branchDao().insert(dbTester.getSession(), branch); dbTester.commit(); return new ComponentAndBranch(project, branch); }
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()); }
@Test public void loadQualityGate_on_long_branch_returns_organization_default_gate() { OrganizationDto organization = db.organizations().insert(); ComponentDto project = db.components().insertPublicProject(organization); BranchDto branch = newBranchDto(project).setBranchType(BranchType.LONG); db.components().insertProjectBranch(project, branch); MetricDto metric = db.measures().insertMetric(); QGateWithOrgDto gate = db.qualityGates().insertQualityGate(organization); db.qualityGates().setDefaultQualityGate(organization, gate); QualityGateConditionDto condition = db.qualityGates().addCondition(gate, metric); QualityGate result = underTest.loadQualityGate(db.getSession(), organization, project, branch); assertThat(result.getId()).isEqualTo("" + gate.getId()); assertThat(result.getConditions()) .extracting(Condition::getMetricKey, Condition::getOperator, Condition::getErrorThreshold) .containsExactlyInAnyOrder( tuple(metric.getKey(), Condition.Operator.fromDbValue(condition.getOperator()), condition.getErrorThreshold())); }
@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_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_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"); }
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; }