Search in sources :

Example 6 with Project

use of org.sonar.alm.client.bitbucketserver.Project in project sonarqube by SonarSource.

the class SearchBitbucketServerReposActionTest method getGsonBBSRepo2.

private Repository getGsonBBSRepo2() {
    Repository gsonBBSRepo = new Repository();
    gsonBBSRepo.setId(3L);
    gsonBBSRepo.setName("repoName2");
    Project project = new Project();
    project.setName("projectName2");
    project.setKey("projectKey2");
    project.setId(4L);
    gsonBBSRepo.setProject(project);
    gsonBBSRepo.setSlug("repo-slug-2");
    return gsonBBSRepo;
}
Also used : Project(org.sonar.alm.client.bitbucketserver.Project) Repository(org.sonar.alm.client.bitbucketserver.Repository)

Example 7 with Project

use of org.sonar.alm.client.bitbucketserver.Project in project sonarqube by SonarSource.

the class ImportBitbucketServerProjectActionTest method handle_givenNoDefaultBranchFound_doNotUpdateDefaultBranchName.

@Test
public void handle_givenNoDefaultBranchFound_doNotUpdateDefaultBranchName() {
    BranchesList branchesList = new BranchesList();
    Branch branch = new Branch("not_a_master", false);
    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("master");
}
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 8 with Project

use of org.sonar.alm.client.bitbucketserver.Project in project sonarqube by SonarSource.

the class ImportBitbucketServerProjectActionTest method import_project.

@Test
public void import_project() {
    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(defaultBranchesList);
    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();
    assertThat(result.getKey()).isEqualTo(project.getKey() + "_" + repo.getSlug());
    assertThat(result.getName()).isEqualTo(repo.getName());
    Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
    assertThat(projectDto).isPresent();
    assertThat(db.getDbClient().projectAlmSettingDao().selectByProject(db.getSession(), projectDto.get())).isPresent();
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) Project(org.sonar.alm.client.bitbucketserver.Project) Repository(org.sonar.alm.client.bitbucketserver.Repository) UserDto(org.sonar.db.user.UserDto) Projects(org.sonarqube.ws.Projects) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Aggregations

Project (org.sonar.alm.client.bitbucketserver.Project)8 Repository (org.sonar.alm.client.bitbucketserver.Repository)7 Test (org.junit.Test)5 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)5 UserDto (org.sonar.db.user.UserDto)5 Projects (org.sonarqube.ws.Projects)4 ProjectDto (org.sonar.db.project.ProjectDto)3 Branch (org.sonar.alm.client.bitbucketserver.Branch)2 BranchesList (org.sonar.alm.client.bitbucketserver.BranchesList)2 BranchDto (org.sonar.db.component.BranchDto)2 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 ProjectList (org.sonar.alm.client.bitbucketserver.ProjectList)1 BadRequestException (org.sonar.server.exceptions.BadRequestException)1