Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DefaultAssigneeTest.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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.ce.task.projectanalysis.issue;
  21. import org.junit.Before;
  22. import org.junit.Rule;
  23. import org.junit.Test;
  24. import org.sonar.api.CoreProperties;
  25. import org.sonar.api.impl.config.MapSettings;
  26. import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderImpl;
  27. import org.sonar.ce.task.projectanalysis.analysis.Organization;
  28. import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository;
  29. import org.sonar.ce.task.projectanalysis.component.TestSettingsRepository;
  30. import org.sonar.core.platform.PlatformEditionProvider;
  31. import org.sonar.db.DbTester;
  32. import org.sonar.db.organization.OrganizationDto;
  33. import org.sonar.db.user.UserDto;
  34. import static org.assertj.core.api.Assertions.assertThat;
  35. import static org.mockito.Mockito.mock;
  36. public class DefaultAssigneeTest {
  37. public static final String PROJECT_KEY = "PROJECT_KEY";
  38. public static final String ORGANIZATION_UUID = "ORGANIZATION_UUID";
  39. public static final String QUALITY_GATE_UUID = "QUALITY_GATE_UUID";
  40. @Rule
  41. public DbTester db = DbTester.create();
  42. private MapSettings settings = new MapSettings();
  43. private ConfigurationRepository settingsRepository = new TestSettingsRepository(settings.asConfig());
  44. private AnalysisMetadataHolderImpl analysisMetadataHolder = new AnalysisMetadataHolderImpl(mock(PlatformEditionProvider.class));
  45. private OrganizationDto organizationDto;
  46. private DefaultAssignee underTest = new DefaultAssignee(db.getDbClient(), settingsRepository, analysisMetadataHolder);
  47. @Before
  48. public void setUp() throws Exception {
  49. organizationDto = db.organizations().insertForUuid(ORGANIZATION_UUID);
  50. analysisMetadataHolder.setOrganization(Organization.from(
  51. new OrganizationDto().setUuid(ORGANIZATION_UUID).setKey("Organization key").setName("Organization name").setDefaultQualityGateUuid(QUALITY_GATE_UUID)));
  52. }
  53. @Test
  54. public void no_default_assignee() {
  55. assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
  56. }
  57. @Test
  58. public void set_default_assignee() {
  59. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
  60. UserDto userDto = db.users().insertUser("erik");
  61. db.organizations().addMember(organizationDto, userDto);
  62. assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid());
  63. }
  64. @Test
  65. public void configured_login_does_not_exist() {
  66. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
  67. assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
  68. }
  69. @Test
  70. public void configured_login_is_disabled() {
  71. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
  72. db.users().insertUser(user -> user.setLogin("erik").setActive(false));
  73. assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
  74. }
  75. @Test
  76. public void configured_login_is_not_member_of_organization() {
  77. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
  78. OrganizationDto otherOrganization = db.organizations().insert();
  79. UserDto userDto = db.users().insertUser("erik");
  80. db.organizations().addMember(otherOrganization, userDto);
  81. assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
  82. }
  83. @Test
  84. public void default_assignee_is_cached() {
  85. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
  86. UserDto userDto = db.users().insertUser("erik");
  87. db.organizations().addMember(organizationDto, userDto);
  88. assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid());
  89. // The setting is updated but the assignee hasn't changed
  90. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "other");
  91. assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid());
  92. }
  93. }