You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AlmSettingsTesting.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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.sonar.db.almsettings;
  21. import org.sonar.db.alm.setting.ALM;
  22. import org.sonar.db.alm.setting.AlmSettingDto;
  23. import org.sonar.db.alm.setting.ProjectAlmSettingDto;
  24. import org.sonar.db.project.ProjectDto;
  25. import static org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric;
  26. import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
  27. public class AlmSettingsTesting {
  28. private AlmSettingsTesting() {
  29. }
  30. public static AlmSettingDto newGithubAlmSettingDto() {
  31. return new AlmSettingDto()
  32. .setKey(randomAlphanumeric(200))
  33. .setUrl(randomAlphanumeric(2000))
  34. .setAppId(randomNumeric(8))
  35. .setClientId(randomNumeric(8))
  36. .setClientSecret(randomAlphanumeric(80))
  37. .setPrivateKey(randomAlphanumeric(2000))
  38. .setAlm(ALM.GITHUB);
  39. }
  40. public static AlmSettingDto newAzureAlmSettingDto() {
  41. return new AlmSettingDto()
  42. .setKey(randomAlphanumeric(200))
  43. .setPersonalAccessToken(randomAlphanumeric(2000))
  44. .setUrl(randomAlphanumeric(2000))
  45. .setAlm(ALM.AZURE_DEVOPS);
  46. }
  47. public static AlmSettingDto newGitlabAlmSettingDto() {
  48. return new AlmSettingDto()
  49. .setKey(randomAlphanumeric(200))
  50. .setPersonalAccessToken(randomAlphanumeric(2000))
  51. .setUrl(randomAlphanumeric(2000))
  52. .setAlm(ALM.GITLAB);
  53. }
  54. public static AlmSettingDto newBitbucketAlmSettingDto() {
  55. return new AlmSettingDto()
  56. .setKey(randomAlphanumeric(200))
  57. .setUrl(randomAlphanumeric(2000))
  58. .setPersonalAccessToken(randomAlphanumeric(2000))
  59. .setAlm(ALM.BITBUCKET);
  60. }
  61. public static AlmSettingDto newBitbucketCloudAlmSettingDto() {
  62. return new AlmSettingDto()
  63. .setKey(randomAlphanumeric(200))
  64. .setClientId(randomAlphanumeric(50))
  65. .setAppId(randomAlphanumeric(80))
  66. .setClientSecret(randomAlphanumeric(50))
  67. .setAlm(ALM.BITBUCKET_CLOUD);
  68. }
  69. public static ProjectAlmSettingDto newGithubProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ProjectDto project) {
  70. return newGithubProjectAlmSettingDto(githubAlmSetting, project, false);
  71. }
  72. public static ProjectAlmSettingDto newGithubProjectAlmSettingDto(AlmSettingDto githubAlmSetting, ProjectDto project, boolean monorepo) {
  73. return new ProjectAlmSettingDto()
  74. .setAlmSettingUuid(githubAlmSetting.getUuid())
  75. .setProjectUuid(project.getUuid())
  76. .setAlmRepo(randomAlphanumeric(256))
  77. .setSummaryCommentEnabled(true)
  78. .setMonorepo(monorepo);
  79. }
  80. public static ProjectAlmSettingDto newGitlabProjectAlmSettingDto(AlmSettingDto gitlabAlmSetting, ProjectDto project) {
  81. return newGitlabProjectAlmSettingDto(gitlabAlmSetting, project, false);
  82. }
  83. public static ProjectAlmSettingDto newGitlabProjectAlmSettingDto(AlmSettingDto gitlabAlmSetting, ProjectDto project, boolean monorepo) {
  84. return new ProjectAlmSettingDto()
  85. .setAlmSettingUuid(gitlabAlmSetting.getUuid())
  86. .setProjectUuid(project.getUuid())
  87. .setMonorepo(monorepo);
  88. }
  89. static ProjectAlmSettingDto newAzureProjectAlmSettingDto(AlmSettingDto azureAlmSetting, ProjectDto project) {
  90. return new ProjectAlmSettingDto()
  91. .setAlmSettingUuid(azureAlmSetting.getUuid())
  92. .setProjectUuid(project.getUuid())
  93. .setAlmSlug(randomAlphanumeric(256))
  94. .setAlmRepo(randomAlphanumeric(256))
  95. .setMonorepo(false);
  96. }
  97. public static ProjectAlmSettingDto newBitbucketProjectAlmSettingDto(AlmSettingDto bitbucketAlmSetting, ProjectDto project) {
  98. return new ProjectAlmSettingDto()
  99. .setAlmSettingUuid(bitbucketAlmSetting.getUuid())
  100. .setProjectUuid(project.getUuid())
  101. .setAlmRepo(randomAlphanumeric(256))
  102. .setAlmSlug(randomAlphanumeric(256))
  103. .setMonorepo(false);
  104. }
  105. public static ProjectAlmSettingDto newBitbucketCloudProjectAlmSettingDto(AlmSettingDto bitbucketCloudAlmSetting, ProjectDto project) {
  106. return new ProjectAlmSettingDto()
  107. .setAlmSettingUuid(bitbucketCloudAlmSetting.getUuid())
  108. .setProjectUuid(project.getUuid())
  109. .setAlmRepo(randomAlphanumeric(256))
  110. .setMonorepo(false);
  111. }
  112. }