use of org.sonarqube.ws.AlmSettings.ListWsResponse in project sonarqube by SonarSource.
the class ListActionTest method list_is_ordered_by_alm_key.
@Test
public void list_is_ordered_by_alm_key() {
UserDto user = db.users().insertUser();
db.components().insertPrivateProject();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
db.almSettings().insertGitHubAlmSetting(almSetting -> almSetting.setKey("GitHub1"));
db.almSettings().insertGitHubAlmSetting(almSetting -> almSetting.setKey("GitHub2"));
db.almSettings().insertAzureAlmSetting(almSetting -> almSetting.setKey("Azure"));
db.almSettings().insertGitlabAlmSetting(almSetting -> almSetting.setKey("Gitlab"));
db.almSettings().insertBitbucketAlmSetting(almSetting -> almSetting.setKey("Bitbucket"));
ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
assertThat(response.getAlmSettingsList()).extracting(AlmSetting::getKey).containsExactly("Azure", "Bitbucket", "GitHub1", "GitHub2", "Gitlab");
}
use of org.sonarqube.ws.AlmSettings.ListWsResponse in project sonarqube by SonarSource.
the class ListActionTest method list.
@Test
public void list() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto githubAlmSetting1 = db.almSettings().insertGitHubAlmSetting();
AlmSettingDto githubAlmSetting2 = db.almSettings().insertGitHubAlmSetting();
AlmSettingDto azureAlmSetting = db.almSettings().insertAzureAlmSetting();
AlmSettingDto azureAlmSettingWithoutUrl = db.almSettings().insertAzureAlmSetting(s -> s.setUrl(null));
AlmSettingDto gitlabAlmSetting = db.almSettings().insertGitlabAlmSetting();
AlmSettingDto gitlabAlmSettingWithoutUrl = db.almSettings().insertGitlabAlmSetting(s -> s.setUrl(null));
AlmSettingDto bitbucketAlmSetting = db.almSettings().insertBitbucketAlmSetting();
AlmSettingDto bitbucketCloudAlmSetting = db.almSettings().insertBitbucketCloudAlmSetting();
ListWsResponse response = ws.newRequest().executeProtobuf(ListWsResponse.class);
assertThat(response.getAlmSettingsList()).extracting(AlmSetting::getAlm, AlmSetting::getKey, AlmSetting::hasUrl, AlmSetting::getUrl).containsExactlyInAnyOrder(tuple(AlmSettings.Alm.github, githubAlmSetting1.getKey(), true, githubAlmSetting1.getUrl()), tuple(AlmSettings.Alm.github, githubAlmSetting2.getKey(), true, githubAlmSetting2.getUrl()), tuple(AlmSettings.Alm.azure, azureAlmSetting.getKey(), true, azureAlmSetting.getUrl()), tuple(AlmSettings.Alm.azure, azureAlmSettingWithoutUrl.getKey(), false, ""), tuple(AlmSettings.Alm.gitlab, gitlabAlmSetting.getKey(), true, gitlabAlmSetting.getUrl()), tuple(AlmSettings.Alm.gitlab, gitlabAlmSettingWithoutUrl.getKey(), false, ""), tuple(AlmSettings.Alm.bitbucket, bitbucketAlmSetting.getKey(), true, bitbucketAlmSetting.getUrl()), tuple(AlmSettings.Alm.bitbucketcloud, bitbucketCloudAlmSetting.getKey(), true, "https://bitbucket.org/" + bitbucketCloudAlmSetting.getAppId() + "/"));
}
use of org.sonarqube.ws.AlmSettings.ListWsResponse in project sonarqube by SonarSource.
the class ListAction method handle.
@Override
public void handle(Request request, Response response) {
ListWsResponse wsResponse = doHandle(request);
writeProtobuf(wsResponse, request, response);
}
use of org.sonarqube.ws.AlmSettings.ListWsResponse in project sonarqube by SonarSource.
the class ListAction method doHandle.
private ListWsResponse doHandle(Request request) {
try (DbSession dbSession = dbClient.openSession(false)) {
Request.StringParam projectKey = request.getParam(PARAM_PROJECT);
if (projectKey.isPresent()) {
ProjectDto project = componentFinder.getProjectByKey(dbSession, projectKey.getValue());
userSession.checkProjectPermission(ADMIN, project);
} else {
userSession.checkPermission(PROVISION_PROJECTS);
}
List<AlmSettingDto> settings = dbClient.almSettingDao().selectAll(dbSession);
List<AlmSetting> wsAlmSettings = settings.stream().sorted(Comparator.comparing(AlmSettingDto::getKey)).map(almSetting -> {
AlmSetting.Builder almSettingBuilder = AlmSetting.newBuilder().setKey(almSetting.getKey()).setAlm(AlmSettingsSupport.toAlmWs(almSetting.getAlm()));
if (almSetting.getAlm() == ALM.BITBUCKET_CLOUD) {
almSettingBuilder.setUrl(BITBUCKETCLOUD_ROOT_URL + almSetting.getAppId() + "/");
} else {
ofNullable(almSetting.getUrl()).ifPresent(almSettingBuilder::setUrl);
}
return almSettingBuilder.build();
}).collect(Collectors.toList());
return ListWsResponse.newBuilder().addAllAlmSettings(wsAlmSettings).build();
}
}
Aggregations