Search in sources :

Example 71 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class SearchAzureReposActionTest method search_repos_with_project_name.

@Test
public void search_repos_with_project_name() {
    AlmSettingDto almSetting = insertAlmSetting();
    SearchAzureReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectName", "project-1").executeProtobuf(SearchAzureReposWsResponse.class);
    assertThat(response.getRepositoriesList()).extracting(AzureRepo::getName, AzureRepo::getProjectName).containsExactlyInAnyOrder(tuple("repoName-1", "project-1"), tuple("repoName-2", "project-2"));
}
Also used : SearchAzureReposWsResponse(org.sonarqube.ws.AlmIntegrations.SearchAzureReposWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 72 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class SearchBitbucketCloudReposActionTest method use_projectKey_to_disambiguate_when_multiple_projects_are_binded_on_one_bitbucket_repo.

@Test
public void use_projectKey_to_disambiguate_when_multiple_projects_are_binded_on_one_bitbucket_repo() {
    when(bitbucketCloudRestClient.searchRepos(any(), any(), any(), any(), any())).thenReturn(getRepositoryList());
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmSettingDto almSetting = db.almSettings().insertBitbucketCloudAlmSetting();
    db.almPats().insert(dto -> {
        dto.setAlmSettingUuid(almSetting.getUuid());
        dto.setUserUuid(user.getUuid());
    });
    ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("B"));
    ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("A"));
    db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project1, s -> s.setAlmRepo("repo-slug-2"));
    db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project2, s -> s.setAlmRepo("repo-slug-2"));
    SearchBitbucketcloudReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchBitbucketcloudReposWsResponse.class);
    assertThat(response.getRepositoriesList()).extracting(BBCRepo::getUuid, BBCRepo::getName, BBCRepo::getSlug, BBCRepo::getProjectKey, BBCRepo::getSqProjectKey).containsExactlyInAnyOrder(tuple("REPO-UUID-ONE", "repoName1", "repo-slug-1", "projectKey1", ""), tuple("REPO-UUID-TWO", "repoName2", "repo-slug-2", "projectKey2", "A"));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) SearchBitbucketcloudReposWsResponse(org.sonarqube.ws.AlmIntegrations.SearchBitbucketcloudReposWsResponse) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 73 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class SearchBitbucketCloudReposActionTest method list_repos.

@Test
public void list_repos() {
    when(bitbucketCloudRestClient.searchRepos(any(), any(), any(), any(), any())).thenReturn(getRepositoryList());
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmSettingDto almSetting = db.almSettings().insertBitbucketCloudAlmSetting();
    db.almPats().insert(dto -> {
        dto.setAlmSettingUuid(almSetting.getUuid());
        dto.setPersonalAccessToken("abc:xyz");
        dto.setUserUuid(user.getUuid());
    });
    ProjectDto projectDto = db.components().insertPrivateProjectDto();
    db.almSettings().insertBitbucketCloudProjectAlmSetting(almSetting, projectDto, s -> s.setAlmRepo("repo-slug-2"));
    SearchBitbucketcloudReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("p", "1").setParam("ps", "100").executeProtobuf(SearchBitbucketcloudReposWsResponse.class);
    assertThat(response.getIsLastPage()).isFalse();
    assertThat(response.getPaging().getPageIndex()).isOne();
    assertThat(response.getPaging().getPageSize()).isEqualTo(100);
    assertThat(response.getRepositoriesList()).extracting(BBCRepo::getUuid, BBCRepo::getName, BBCRepo::getSlug, BBCRepo::getProjectKey, BBCRepo::getSqProjectKey, BBCRepo::getWorkspace).containsExactlyInAnyOrder(tuple("REPO-UUID-ONE", "repoName1", "repo-slug-1", "projectKey1", "", almSetting.getAppId()), tuple("REPO-UUID-TWO", "repoName2", "repo-slug-2", "projectKey2", projectDto.getKey(), almSetting.getAppId()));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) SearchBitbucketcloudReposWsResponse(org.sonarqube.ws.AlmIntegrations.SearchBitbucketcloudReposWsResponse) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 74 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class ListBitbucketServerProjectsActionTest method list_projects.

@Test
public void list_projects() {
    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());
    });
    ListBitbucketserverProjectsWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(ListBitbucketserverProjectsWsResponse.class);
    assertThat(response.getProjectsCount()).isOne();
    assertThat(response.getProjectsList()).extracting(AlmIntegrations.AlmProject::getKey, AlmIntegrations.AlmProject::getName).containsExactly(tuple("key", "name"));
}
Also used : UserDto(org.sonar.db.user.UserDto) ListBitbucketserverProjectsWsResponse(org.sonarqube.ws.AlmIntegrations.ListBitbucketserverProjectsWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) AlmIntegrations(org.sonarqube.ws.AlmIntegrations) Test(org.junit.Test)

Example 75 with AlmSettingDto

use of org.sonar.db.alm.setting.AlmSettingDto in project sonarqube by SonarSource.

the class GetGithubClientIdActionTest method fail_when_client_id_does_not_exist.

@Test
public void fail_when_client_id_does_not_exist() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(GlobalPermission.PROVISION_PROJECTS);
    AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting(s -> s.setClientId(null));
    TestRequest request = ws.newRequest().setParam(GetGithubClientIdAction.PARAM_ALM_SETTING, githubAlmSetting.getKey());
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("No client ID for setting with key '%s'", githubAlmSetting.getKey());
}
Also used : UserDto(org.sonar.db.user.UserDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Aggregations

AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)217 Test (org.junit.Test)175 UserDto (org.sonar.db.user.UserDto)113 TestRequest (org.sonar.server.ws.TestRequest)48 ProjectDto (org.sonar.db.project.ProjectDto)40 NotFoundException (org.sonar.server.exceptions.NotFoundException)37 DbSession (org.sonar.db.DbSession)36 WebService (org.sonar.api.server.ws.WebService)31 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)28 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)28 Rule (org.junit.Rule)28 Mockito.mock (org.mockito.Mockito.mock)28 DbTester (org.sonar.db.DbTester)28 UserSessionRule (org.sonar.server.tester.UserSessionRule)28 WsActionTester (org.sonar.server.ws.WsActionTester)28 Encryption (org.sonar.api.config.internal.Encryption)27 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)27 ComponentFinder (org.sonar.server.component.ComponentFinder)26 Tuple.tuple (org.assertj.core.groups.Tuple.tuple)25 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)25