Search in sources :

Example 1 with Project

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

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

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

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

the class ListBitbucketServerProjectsActionTest method before.

@Before
public void before() {
    ProjectList projectList = new ProjectList();
    List<Project> values = new ArrayList<>();
    Project project = new Project();
    project.setId(1);
    project.setKey("key");
    project.setName("name");
    values.add(project);
    projectList.setValues(values);
    when(bitbucketServerRestClient.getProjects(anyString(), anyString())).thenReturn(projectList);
}
Also used : Project(org.sonar.alm.client.bitbucketserver.Project) ProjectList(org.sonar.alm.client.bitbucketserver.ProjectList) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Example 5 with Project

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

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