use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class SearchBitbucketServerReposActionTest method fail_check_pat_alm_setting_not_found.
@Test
public void fail_check_pat_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);
assertThatThrownBy(() -> {
ws.newRequest().setParam("almSetting", "testKey").execute();
}).isInstanceOf(NotFoundException.class).hasMessage("ALM Setting 'testKey' not found");
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class ListGithubRepositoriesActionTest method return_repositories_using_existing_personal_access_token.
@Test
public void return_repositories_using_existing_personal_access_token() {
AlmSettingDto githubAlmSettings = setupAlm();
AlmPatDto pat = db.almPats().insert(p -> p.setAlmSettingUuid(githubAlmSettings.getUuid()).setUserUuid(userSession.getUuid()));
when(appClient.listRepositories(eq(githubAlmSettings.getUrl()), argThat(token -> token.getValue().equals(pat.getPersonalAccessToken())), eq("github"), isNull(), eq(1), eq(100))).thenReturn(new GithubApplicationClient.Repositories().setTotal(2).setRepositories(Stream.of("HelloWorld", "HelloUniverse").map(name -> new GithubApplicationClient.Repository(name.length(), name, false, "github/" + name, "https://github-enterprise.sonarqube.com/api/v3/github/HelloWorld", "main")).collect(Collectors.toList())));
ProjectDto project = db.components().insertPrivateProjectDto(componentDto -> componentDto.setDbKey("github_HelloWorld"));
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSettings, project, projectAlmSettingDto -> projectAlmSettingDto.setAlmRepo("github/HelloWorld"));
ProjectDto project2 = db.components().insertPrivateProjectDto(componentDto -> componentDto.setDbKey("github_HelloWorld2"));
db.almSettings().insertGitHubProjectAlmSetting(githubAlmSettings, project2, projectAlmSettingDto -> projectAlmSettingDto.setAlmRepo("github/HelloWorld"));
ListGithubRepositoriesWsResponse response = ws.newRequest().setParam(ListGithubRepositoriesAction.PARAM_ALM_SETTING, githubAlmSettings.getKey()).setParam(ListGithubRepositoriesAction.PARAM_ORGANIZATION, "github").executeProtobuf(ListGithubRepositoriesWsResponse.class);
assertThat(response.getPaging()).extracting(Common.Paging::getPageIndex, Common.Paging::getPageSize, Common.Paging::getTotal).containsOnly(1, 100, 2);
assertThat(response.getRepositoriesCount()).isEqualTo(2);
assertThat(response.getRepositoriesList()).extracting(GithubRepository::getKey, GithubRepository::getName, GithubRepository::getSqProjectKey).containsOnly(tuple("github/HelloWorld", "HelloWorld", project.getKey()), tuple("github/HelloUniverse", "HelloUniverse", ""));
verify(appClient).listRepositories(eq(githubAlmSettings.getUrl()), argThat(token -> token.getValue().equals(pat.getPersonalAccessToken())), eq("github"), isNull(), eq(1), eq(100));
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class SearchGitlabReposActionTest method fail_when_alm_setting_not_found.
@Test
public void fail_when_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");
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class SetPatActionTest method set_existing_pat.
@Test
public void set_existing_pat() {
UserDto user = db.users().insertUser();
AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
db.almPats().insert(p -> p.setUserUuid(user.getUuid()), p -> p.setAlmSettingUuid(almSetting.getUuid()));
ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("pat", "newtoken").execute();
Optional<AlmPatDto> actualAlmPat = db.getDbClient().almPatDao().selectByUserAndAlmSetting(db.getSession(), user.getUuid(), almSetting);
assertThat(actualAlmPat).isPresent();
assertThat(actualAlmPat.get().getPersonalAccessToken()).isEqualTo("newtoken");
assertThat(actualAlmPat.get().getUserUuid()).isEqualTo(user.getUuid());
assertThat(actualAlmPat.get().getAlmSettingUuid()).isEqualTo(almSetting.getUuid());
}
use of org.sonar.db.alm.pat.AlmPatDto in project sonarqube by SonarSource.
the class ImportAzureProjectActionTest 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");
}
Aggregations