Search in sources :

Example 31 with AlmPatDto

use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.

the class ListBitbucketServerProjectsActionTest method fail_check_alm_setting_not_found.

@Test
public void fail_check_alm_setting_not_found() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmPatDto almPatDto = newAlmPatDto();
    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
    TestRequest request = ws.newRequest().setParam("almSetting", "testKey");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("ALM Setting 'testKey' not found");
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmPatsTesting.newAlmPatDto(org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto) AlmPatDto(org.sonar.db.alm.pat.AlmPatDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 32 with AlmPatDto

use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.

the class SetPatActionTest method set_new_bitbucketserver_pat.

@Test
public void set_new_bitbucketserver_pat() {
    UserDto user = db.users().insertUser();
    AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("pat", "12345678987654321").execute();
    Optional<AlmPatDto> actualAlmPat = db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), user.getUuid(), almSetting);
    assertThat(actualAlmPat).isPresent();
    assertThat(actualAlmPat.get().getPersonalAccessToken()).isEqualTo("12345678987654321");
    assertThat(actualAlmPat.get().getUserUuid()).isEqualTo(user.getUuid());
    assertThat(actualAlmPat.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmPatDto(org.sonar.db.alm.pat.AlmPatDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) Test(org.junit.Test)

Example 33 with AlmPatDto

use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.

the class ListAzureProjectsActionTest method fail_check_alm_setting_not_found.

@Test
public void fail_check_alm_setting_not_found() {
    UserDto user = insertUser();
    AlmPatDto almPatDto = newAlmPatDto();
    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
    TestRequest request = ws.newRequest().setParam("almSetting", "testKey");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("ALM Setting 'testKey' not found");
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmPatsTesting.newAlmPatDto(org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto) AlmPatDto(org.sonar.db.alm.pat.AlmPatDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 34 with AlmPatDto

use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.

the class ImportBitbucketCloudRepoActionTest method fail_check_alm_setting_not_found.

@Test
public void fail_check_alm_setting_not_found() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmPatDto almPatDto = newAlmPatDto();
    db.getDbClient().almPatDao().insert(db.getSession(), almPatDto, user.getLogin(), null);
    TestRequest request = ws.newRequest().setParam("almSetting", "testKey").setParam("repositorySlug", "repo");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessageContaining("ALM Setting 'testKey' not found");
}
Also used : UserDto(org.sonar.db.user.UserDto) AlmPatsTesting.newAlmPatDto(org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto) AlmPatDto(org.sonar.db.alm.pat.AlmPatDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Aggregations

AlmPatDto (org.sonar.db.alm.pat.AlmPatDto)34 NotFoundException (org.sonar.server.exceptions.NotFoundException)24 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)23 Test (org.junit.Test)19 UserDto (org.sonar.db.user.UserDto)19 DbSession (org.sonar.db.DbSession)14 TestRequest (org.sonar.server.ws.TestRequest)11 AlmPatsTesting.newAlmPatDto (org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto)10 ProjectAlmSettingDto (org.sonar.db.alm.setting.ProjectAlmSettingDto)7 Collectors (java.util.stream.Collectors)5 GithubApplicationClient (org.sonar.alm.client.github.GithubApplicationClient)5 UserAccessToken (org.sonar.alm.client.github.security.UserAccessToken)5 List (java.util.List)4 Map (java.util.Map)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 Optional (java.util.Optional)4 Set (java.util.Set)4 BinaryOperator (java.util.function.BinaryOperator)4 Collectors.toList (java.util.stream.Collectors.toList)4 Collectors.toSet (java.util.stream.Collectors.toSet)4