Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarqube.ws.tester;
  21. import org.junit.rules.ExternalResource;
  22. import org.sonarqube.ws.AlmSettings;
  23. import org.sonarqube.ws.client.HttpException;
  24. import org.sonarqube.ws.client.almsettings.AlmSettingsService;
  25. import org.sonarqube.ws.client.almsettings.CreateGithubRequest;
  26. import org.sonarqube.ws.client.almsettings.DeleteRequest;
  27. public class AlmSettingsTester extends ExternalResource {
  28. private final TesterSession session;
  29. AlmSettingsTester(TesterSession session) {
  30. this.session = session;
  31. }
  32. public void addGitHubAlmSettings(String key) {
  33. session.wsClient().almSettings().createGithub(new CreateGithubRequest()
  34. .setClientId("id1")
  35. .setAppId("app1")
  36. .setClientSecret("shhh")
  37. .setKey(key).setPrivateKey("PRIV")
  38. .setUrl("http://example.org"));
  39. }
  40. void deleteAll() {
  41. AlmSettingsService almSettingsService = session.wsClient().almSettings();
  42. try {
  43. AlmSettings.ListDefinitionsWsResponse response = almSettingsService.listDefinitions();
  44. response.getGithubList().forEach(e -> almSettingsService.delete(new DeleteRequest(e.getKey())));
  45. response.getAzureList().forEach(e -> almSettingsService.delete(new DeleteRequest(e.getKey())));
  46. response.getBitbucketList().forEach(e -> almSettingsService.delete(new DeleteRequest(e.getKey())));
  47. response.getBitbucketcloudList().forEach(e -> almSettingsService.delete(new DeleteRequest(e.getKey())));
  48. response.getGitlabList().forEach(e -> almSettingsService.delete(new DeleteRequest(e.getKey())));
  49. } catch (HttpException e) {
  50. // If server is not at least a developer edition, the ws is not available, nothing to do
  51. if (e.code() == 404) {
  52. return;
  53. }
  54. throw new IllegalStateException(e);
  55. }
  56. }
  57. }