@Test public void insert_branch_with_all_fields_and_max_length_values() { BranchDto dto = new BranchDto(); dto.setProjectUuid(repeat("a", 50)); dto.setUuid(repeat("b", 50)); dto.setBranchType(BranchType.SHORT); dto.setKey(repeat("c", 255)); dto.setMergeBranchUuid(repeat("d", 50)); underTest.insert(dbSession, dto); Map<String, Object> map = db.selectFirst(dbSession, SELECT_FROM + " where uuid='" + dto.getUuid() + "'"); assertThat((String) map.get("projectUuid")).contains("a").isEqualTo(dto.getProjectUuid()); assertThat((String) map.get("uuid")).contains("b").isEqualTo(dto.getUuid()); assertThat((String) map.get("kee")).contains("c").isEqualTo(dto.getKey()); assertThat((String) map.get("mergeBranchUuid")).contains("d").isEqualTo(dto.getMergeBranchUuid()); }
@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 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 insert_pull_request_branch_with_only_non_null_fields() { String projectUuid = "U1"; String uuid = "U2"; BranchType branchType = BranchType.PULL_REQUEST; String kee = "123"; BranchDto dto = new BranchDto(); dto.setProjectUuid(projectUuid); dto.setUuid(uuid); dto.setBranchType(branchType); dto.setKey(kee); underTest.insert(dbSession, dto); BranchDto loaded = underTest.selectByUuid(dbSession, dto.getUuid()).get(); assertThat(loaded.getProjectUuid()).isEqualTo(projectUuid); assertThat(loaded.getUuid()).isEqualTo(uuid); assertThat(loaded.getBranchType()).isEqualTo(branchType); assertThat(loaded.getKey()).isEqualTo(kee); assertThat(loaded.getMergeBranchUuid()).isNull(); assertThat(loaded.getPullRequestData()).isNull(); }
@Test public void upsert_branch() { BranchDto dto = new BranchDto(); dto.setProjectUuid("U1"); dto.setUuid("U2"); dto.setBranchType(BranchType.LONG); dto.setKey("foo"); underTest.insert(dbSession, dto); // the fields that can be updated dto.setMergeBranchUuid("U3"); // the fields that can't be updated. New values are ignored. dto.setProjectUuid("ignored"); dto.setBranchType(BranchType.SHORT); underTest.upsert(dbSession, dto); BranchDto loaded = underTest.selectByBranchKey(dbSession, "U1", "foo").get(); assertThat(loaded.getMergeBranchUuid()).isEqualTo("U3"); assertThat(loaded.getProjectUuid()).isEqualTo("U1"); assertThat(loaded.getBranchType()).isEqualTo(BranchType.LONG); }
dto.setPullRequestData(pullRequestData); underTest.insert(dbSession, dto);
@Test public void update_main_branch_name() { BranchDto dto = new BranchDto(); dto.setProjectUuid("U1"); dto.setUuid("U1"); dto.setBranchType(BranchType.LONG); dto.setKey("feature"); underTest.insert(dbSession, dto); BranchDto dto2 = new BranchDto(); dto2.setProjectUuid("U2"); dto2.setUuid("U2"); dto2.setBranchType(BranchType.LONG); dto2.setKey("branch"); underTest.insert(dbSession, dto2); underTest.updateMainBranchName(dbSession, "U1", "master"); BranchDto loaded = underTest.selectByBranchKey(dbSession, "U1", "master").get(); assertThat(loaded.getMergeBranchUuid()).isNull(); assertThat(loaded.getProjectUuid()).isEqualTo("U1"); assertThat(loaded.getBranchType()).isEqualTo(BranchType.LONG); }
@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 selectByBranchKey() { BranchDto mainBranch = new BranchDto(); mainBranch.setProjectUuid("U1"); mainBranch.setUuid("U1"); mainBranch.setBranchType(BranchType.LONG); mainBranch.setKey("master"); underTest.insert(dbSession, mainBranch); BranchDto featureBranch = new BranchDto(); featureBranch.setProjectUuid("U1"); featureBranch.setUuid("U2"); featureBranch.setBranchType(BranchType.SHORT); featureBranch.setKey("feature/foo"); featureBranch.setMergeBranchUuid("U3"); underTest.insert(dbSession, featureBranch); // select the feature branch BranchDto loaded = underTest.selectByBranchKey(dbSession, "U1", "feature/foo").get(); assertThat(loaded.getUuid()).isEqualTo(featureBranch.getUuid()); assertThat(loaded.getKey()).isEqualTo(featureBranch.getKey()); assertThat(loaded.getProjectUuid()).isEqualTo(featureBranch.getProjectUuid()); assertThat(loaded.getBranchType()).isEqualTo(featureBranch.getBranchType()); assertThat(loaded.getMergeBranchUuid()).isEqualTo(featureBranch.getMergeBranchUuid()); // select a branch on another project with same branch name assertThat(underTest.selectByBranchKey(dbSession, "U3", "feature/foo")).isEmpty(); }
@Test public void selectByPullRequestKey() { BranchDto mainBranch = new BranchDto(); mainBranch.setProjectUuid("U1"); mainBranch.setUuid("U1"); mainBranch.setBranchType(BranchType.LONG); mainBranch.setKey("master"); underTest.insert(dbSession, mainBranch); String pullRequestId = "123"; BranchDto pullRequest = new BranchDto(); pullRequest.setProjectUuid("U1"); pullRequest.setUuid("U2"); pullRequest.setBranchType(BranchType.PULL_REQUEST); pullRequest.setKey(pullRequestId); pullRequest.setMergeBranchUuid("U3"); underTest.insert(dbSession, pullRequest); // select the feature branch BranchDto loaded = underTest.selectByPullRequestKey(dbSession, "U1", pullRequestId).get(); assertThat(loaded.getUuid()).isEqualTo(pullRequest.getUuid()); assertThat(loaded.getKey()).isEqualTo(pullRequest.getKey()); assertThat(loaded.getProjectUuid()).isEqualTo(pullRequest.getProjectUuid()); assertThat(loaded.getBranchType()).isEqualTo(pullRequest.getBranchType()); assertThat(loaded.getMergeBranchUuid()).isEqualTo(pullRequest.getMergeBranchUuid()); // select a branch on another project with same branch name assertThat(underTest.selectByPullRequestKey(dbSession, "U3", pullRequestId)).isEmpty(); }
dto.setBranchType(BranchType.PULL_REQUEST); dto.setKey("foo"); underTest.insert(dbSession, dto);
dto.setPullRequestData(pullRequestData); underTest.insert(dbSession, dto);
@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); }
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); }