Search in sources :

Example 46 with BranchDto

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");
}
Also used : BranchesList(org.sonar.alm.client.bitbucketserver.BranchesList) ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) UserDto(org.sonar.db.user.UserDto) Projects(org.sonarqube.ws.Projects) Project(org.sonar.alm.client.bitbucketserver.Project) Repository(org.sonar.alm.client.bitbucketserver.Repository) Branch(org.sonar.alm.client.bitbucketserver.Branch) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 47 with BranchDto

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");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) UserDto(org.sonar.db.user.UserDto) Projects(org.sonarqube.ws.Projects) GsonAzureRepo(org.sonar.alm.client.azure.GsonAzureRepo) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) ProjectAlmSettingDto(org.sonar.db.alm.setting.ProjectAlmSettingDto) Test(org.junit.Test)

Example 48 with BranchDto

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();
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 49 with BranchDto

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);
}
Also used : DbSession(org.sonar.db.DbSession) BranchDto(org.sonar.db.component.BranchDto) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) InputStream(java.io.InputStream) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 50 with BranchDto

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);
}
Also used : BranchDto(org.sonar.db.component.BranchDto) ComponentTesting.newBranchDto(org.sonar.db.component.ComponentTesting.newBranchDto) Random(java.util.Random) BranchType(org.sonar.db.component.BranchType)

Aggregations

BranchDto (org.sonar.db.component.BranchDto)111 Test (org.junit.Test)62 ComponentDto (org.sonar.db.component.ComponentDto)52 ProjectDto (org.sonar.db.project.ProjectDto)42 DbSession (org.sonar.db.DbSession)31 SnapshotDto (org.sonar.db.component.SnapshotDto)22 List (java.util.List)15 ComponentTesting.newBranchDto (org.sonar.db.component.ComponentTesting.newBranchDto)13 DbClient (org.sonar.db.DbClient)12 MetricDto (org.sonar.db.metric.MetricDto)12 Map (java.util.Map)9 Optional (java.util.Optional)9 Nullable (javax.annotation.Nullable)9 WebService (org.sonar.api.server.ws.WebService)9 System2 (org.sonar.api.utils.System2)9 NotFoundException (org.sonar.server.exceptions.NotFoundException)9 Collection (java.util.Collection)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 Rule (org.junit.Rule)8 Request (org.sonar.api.server.ws.Request)8