use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault.
@Test
public void handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault() {
BranchesList branchesList = new BranchesList();
Branch branch = new Branch("default", true);
branchesList.addBranch(branch);
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Project project = getGsonBBSProject();
Repository repo = getGsonBBSRepo(project);
when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(branchesList);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "projectKey").setParam("repositorySlug", "repo-slug").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
Collection<BranchDto> branchDtos = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get());
List<BranchDto> collect = branchDtos.stream().filter(BranchDto::isMain).collect(Collectors.toList());
String mainBranchName = collect.iterator().next().getKey();
assertThat(mainBranchName).isEqualTo("default");
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class ImportAzureProjectActionTest method import_project.
@Test
public void import_project() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertAzureAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setPersonalAccessToken(almSetting.getDecryptedPersonalAccessToken(encryption));
dto.setUserUuid(user.getUuid());
});
GsonAzureRepo repo = getGsonAzureRepo();
when(azureDevOpsHttpClient.getRepo(almSetting.getUrl(), almSetting.getDecryptedPersonalAccessToken(encryption), "project-name", "repo-name")).thenReturn(repo);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectName", "project-name").setParam("repositoryName", "repo-name").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
assertThat(result.getKey()).isEqualTo(repo.getProject().getName() + "_" + repo.getName());
assertThat(result.getName()).isEqualTo(repo.getName());
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
assertThat(projectDto).isPresent();
Optional<ProjectAlmSettingDto> projectAlmSettingDto = db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get());
assertThat(projectAlmSettingDto.get().getAlmRepo()).isEqualTo("repo-name");
assertThat(projectAlmSettingDto.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
assertThat(projectAlmSettingDto.get().getAlmSlug()).isEqualTo("project-name");
Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get()).stream().filter(BranchDto::isMain).findFirst();
assertThat(mainBranch).isPresent();
assertThat(mainBranch.get().getKey()).hasToString("repo-default-branch");
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class SetAutomaticDeletionProtectionActionTest method set_purge_exclusion.
@Test
public void set_purge_exclusion() {
userSession.logIn();
ComponentDto project = db.components().insertPublicProject();
ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch1").setExcludeFromPurge(false));
userSession.addProjectPermission(UserRole.ADMIN, project);
tester.newRequest().setParam("project", project.getKey()).setParam("branch", "branch1").setParam("value", "true").execute();
assertThat(db.countRowsOfTable("project_branches")).isEqualTo(2);
Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid());
assertThat(mainBranch.get().getKey()).isEqualTo("master");
assertThat(mainBranch.get().isExcludeFromPurge()).isTrue();
Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid());
assertThat(branchDto.get().getKey()).isEqualTo("branch1");
assertThat(branchDto.get().isExcludeFromPurge()).isTrue();
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class BranchReportSubmitterTest method submit_a_report_on_missing_branch_but_existing_project.
@Test
public void submit_a_report_on_missing_branch_but_existing_project() {
ComponentDto existingProject = db.components().insertPublicProject();
BranchDto exitingProjectMainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), existingProject.uuid()).get();
UserDto user = db.users().insertUser();
userSession.logIn(user).addProjectPermission(SCAN_EXECUTION, existingProject);
Map<String, String> randomCharacteristics = randomNonEmptyMap();
ComponentDto createdBranch = createButDoNotInsertBranch(existingProject);
BranchSupport.ComponentKey componentKey = createComponentKeyOfBranch(createdBranch);
when(branchSupportDelegate.createComponentKey(existingProject.getDbKey(), randomCharacteristics)).thenReturn(componentKey);
when(branchSupportDelegate.createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch))).thenReturn(createdBranch);
InputStream reportInput = IOUtils.toInputStream("{binary}", StandardCharsets.UTF_8);
String taskUuid = mockSuccessfulPrepareSubmitCall();
underTest.submit(existingProject.getDbKey(), existingProject.name(), randomCharacteristics, reportInput);
verifyNoInteractions(permissionTemplateService);
verifyNoInteractions(favoriteUpdater);
verify(branchSupport).createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch));
verify(branchSupportDelegate).createComponentKey(existingProject.getDbKey(), randomCharacteristics);
verify(branchSupportDelegate).createBranchComponent(any(DbSession.class), same(componentKey), eq(existingProject), eq(exitingProjectMainBranch));
verifyNoMoreInteractions(branchSupportDelegate);
verify(componentUpdater, times(0)).commitAndIndex(any(), any());
verifyQueueSubmit(existingProject, createdBranch, user, randomCharacteristics, taskUuid);
}
use of org.sonar.db.component.BranchDto in project sonarqube by SonarSource.
the class BranchReportSubmitterTest method createButDoNotInsertBranch.
private static ComponentDto createButDoNotInsertBranch(ComponentDto project) {
BranchType randomBranchType = BranchType.values()[new Random().nextInt(BranchType.values().length)];
BranchDto branchDto = newBranchDto(project.projectUuid(), randomBranchType);
return ComponentTesting.newBranchComponent(project, branchDto);
}
Aggregations