Search in sources :

Example 1 with Repository

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

the class ImportBitbucketServerProjectActionTest method getGsonBBSRepo.

private Repository getGsonBBSRepo(Project project) {
    Repository bbsResult = new Repository();
    bbsResult.setProject(project);
    bbsResult.setSlug(randomAlphanumeric(5));
    bbsResult.setName(randomAlphanumeric(5));
    bbsResult.setId(nextLong(100));
    return bbsResult;
}
Also used : Repository(org.sonar.alm.client.bitbucketserver.Repository)

Example 2 with Repository

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

the class ImportBitbucketServerProjectActionTest method import_project_with_tilda.

@Test
public void import_project_with_tilda() {
    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();
    project.setKey("~" + project.getKey());
    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();
    String key = project.getKey() + "_" + repo.getSlug();
    assertThat(result.getKey()).isNotEqualTo(key);
    assertThat(result.getKey()).isEqualTo(key.substring(1));
}
Also used : 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)

Example 3 with Repository

use of org.sonar.alm.client.bitbucketserver.Repository 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 4 with Repository

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

the class ImportBitbucketServerProjectActionTest method fail_project_already_exist.

@Test
public void fail_project_already_exist() {
    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);
    String projectKey = project.getKey() + "_" + repo.getSlug();
    db.components().insertPublicProject(p -> p.setDbKey(projectKey));
    assertThatThrownBy(() -> {
        when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
        when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(defaultBranchesList);
        ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "projectKey").setParam("repositorySlug", "repo-slug").execute();
    }).isInstanceOf(BadRequestException.class).hasMessage("Could not create null, key already exists: " + projectKey);
}
Also used : Project(org.sonar.alm.client.bitbucketserver.Project) Repository(org.sonar.alm.client.bitbucketserver.Repository) UserDto(org.sonar.db.user.UserDto) BadRequestException(org.sonar.server.exceptions.BadRequestException) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 5 with Repository

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

the class SearchBitbucketServerReposActionTest method getGsonBBSRepo1.

private Repository getGsonBBSRepo1() {
    Repository gsonBBSRepo1 = new Repository();
    gsonBBSRepo1.setId(1L);
    gsonBBSRepo1.setName("repoName1");
    Project project1 = new Project();
    project1.setName("projectName1");
    project1.setKey("projectKey1");
    project1.setId(2L);
    gsonBBSRepo1.setProject(project1);
    gsonBBSRepo1.setSlug("repo-slug-1");
    return gsonBBSRepo1;
}
Also used : Project(org.sonar.alm.client.bitbucketserver.Project) Repository(org.sonar.alm.client.bitbucketserver.Repository)

Aggregations

Repository (org.sonar.alm.client.bitbucketserver.Repository)10 Project (org.sonar.alm.client.bitbucketserver.Project)7 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)6 Test (org.junit.Test)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 RepositoryList (org.sonar.alm.client.bitbucketserver.RepositoryList)1 DbSession (org.sonar.db.DbSession)1 AlmPatDto (org.sonar.db.alm.pat.AlmPatDto)1 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)1 ComponentDto (org.sonar.db.component.ComponentDto)1 BadRequestException (org.sonar.server.exceptions.BadRequestException)1