Search in sources :

Example 91 with AlmSettingDto

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

the class SearchBitbucketServerReposActionTest method use_projectKey_to_disambiguate_when_multiple_projects_are_binded_on_one_bitbucketserver_repo.

@Test
public void use_projectKey_to_disambiguate_when_multiple_projects_are_binded_on_one_bitbucketserver_repo() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
    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("projectKey2"), s -> s.setAlmSlug("repo-slug-2"));
    db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project2, s -> s.setAlmRepo("projectKey2"), s -> s.setAlmSlug("repo-slug-2"));
    AlmIntegrations.SearchBitbucketserverReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchBitbucketserverReposWsResponse.class);
    assertThat(response.getIsLastPage()).isTrue();
    assertThat(response.getRepositoriesList()).extracting(AlmIntegrations.BBSRepo::getId, AlmIntegrations.BBSRepo::getName, AlmIntegrations.BBSRepo::getSlug, AlmIntegrations.BBSRepo::getSqProjectKey, AlmIntegrations.BBSRepo::getProjectKey).containsExactlyInAnyOrder(tuple(1L, "repoName1", "repo-slug-1", "", "projectKey1"), tuple(3L, "repoName2", "repo-slug-2", "A", "projectKey2"));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) SearchBitbucketserverReposWsResponse(org.sonarqube.ws.AlmIntegrations.SearchBitbucketserverReposWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) AlmIntegrations(org.sonarqube.ws.AlmIntegrations) Test(org.junit.Test)

Example 92 with AlmSettingDto

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

the class ImportGithubProjectActionTest method fail_when_personal_access_token_doesnt_exist.

@Test
public void fail_when_personal_access_token_doesnt_exist() {
    AlmSettingDto githubAlmSetting = setupAlm();
    TestRequest request = ws.newRequest().setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()).setParam(PARAM_ORGANIZATION, "test").setParam(PARAM_REPOSITORY_KEY, "test/repo");
    assertThatThrownBy(request::execute).isInstanceOf(IllegalArgumentException.class).hasMessage("No personal access token found");
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 93 with AlmSettingDto

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

the class ImportGithubProjectActionTest method fail_project_already_exist.

@Test
public void fail_project_already_exist() {
    AlmSettingDto githubAlmSetting = setupAlm();
    db.almPats().insert(p -> p.setAlmSettingUuid(githubAlmSetting.getUuid()).setUserUuid(userSession.getUuid()));
    db.components().insertPublicProject(p -> p.setDbKey("octocat_Hello-World"));
    GithubApplicationClient.Repository repository = new GithubApplicationClient.Repository(1L, "Hello-World", false, "octocat/Hello-World", "https://github.sonarsource.com/api/v3/repos/octocat/Hello-World", "main");
    when(appClient.getRepository(any(), any(), any(), any())).thenReturn(Optional.of(repository));
    TestRequest request = ws.newRequest().setParam(PARAM_ALM_SETTING, githubAlmSetting.getKey()).setParam(PARAM_ORGANIZATION, "octocat").setParam(PARAM_REPOSITORY_KEY, "octocat/Hello-World");
    assertThatThrownBy(request::execute).isInstanceOf(BadRequestException.class).hasMessage("Could not create null, key already exists: octocat_Hello-World");
}
Also used : GithubApplicationClient(org.sonar.alm.client.github.GithubApplicationClient) BadRequestException(org.sonar.server.exceptions.BadRequestException) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 94 with AlmSettingDto

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

the class CreateGitlabActionTest method create_with_url.

@Test
public void create_with_url() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setSystemAdministrator();
    ws.newRequest().setParam("key", "Gitlab - Dev Team").setParam("url", GITLAB_URL).setParam("personalAccessToken", "98765432100").execute();
    assertThat(db.getDbClient().almSettingDao().selectAll(db.getSession())).extracting(AlmSettingDto::getKey, AlmSettingDto::getUrl, s -> s.getDecryptedPersonalAccessToken(encryption)).containsOnly(tuple("Gitlab - Dev Team", GITLAB_URL, "98765432100"));
}
Also used : AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) UserSessionRule(org.sonar.server.tester.UserSessionRule) DbTester(org.sonar.db.DbTester) ComponentFinder(org.sonar.server.component.ComponentFinder) UserDto(org.sonar.db.user.UserDto) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MultipleAlmFeatureProvider(org.sonar.server.almsettings.MultipleAlmFeatureProvider) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) BadRequestException(org.sonar.server.exceptions.BadRequestException) Rule(org.junit.Rule) WebService(org.sonar.api.server.ws.WebService) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Encryption(org.sonar.api.config.internal.Encryption) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) Assertions(org.assertj.core.api.Assertions) Tuple.tuple(org.assertj.core.groups.Tuple.tuple) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) UserDto(org.sonar.db.user.UserDto) Test(org.junit.Test)

Example 95 with AlmSettingDto

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

the class DeleteActionTest method fail_when_missing_administer_system_permission.

@Test
public void fail_when_missing_administer_system_permission() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user);
    AlmSettingDto almSettingDto = db.almSettings().insertGitHubAlmSetting();
    assertThatThrownBy(() -> ws.newRequest().setParam("key", almSettingDto.getKey()).execute()).isInstanceOf(ForbiddenException.class);
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) 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