Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DefaultAssigneeTest.java 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 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.config.internal.MapSettings;
  26. import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository;
  27. import org.sonar.ce.task.projectanalysis.component.TestSettingsRepository;
  28. import org.sonar.db.DbTester;
  29. import org.sonar.db.organization.OrganizationDto;
  30. import org.sonar.db.user.UserDto;
  31. import static org.assertj.core.api.Assertions.assertThat;
  32. public class DefaultAssigneeTest {
  33. public static final String PROJECT_KEY = "PROJECT_KEY";
  34. public static final String ORGANIZATION_UUID = "ORGANIZATION_UUID";
  35. @Rule
  36. public DbTester db = DbTester.create();
  37. private MapSettings settings = new MapSettings();
  38. private ConfigurationRepository settingsRepository = new TestSettingsRepository(settings.asConfig());
  39. private OrganizationDto organizationDto;
  40. private DefaultAssignee underTest = new DefaultAssignee(db.getDbClient(), settingsRepository);
  41. @Before
  42. public void setUp() {
  43. organizationDto = db.organizations().insertForUuid(ORGANIZATION_UUID);
  44. }
  45. @Test
  46. public void no_default_assignee() {
  47. assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
  48. }
  49. @Test
  50. public void set_default_assignee() {
  51. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
  52. UserDto userDto = db.users().insertUser("erik");
  53. db.organizations().addMember(organizationDto, userDto);
  54. assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid());
  55. }
  56. @Test
  57. public void configured_login_does_not_exist() {
  58. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
  59. assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
  60. }
  61. @Test
  62. public void configured_login_is_disabled() {
  63. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
  64. db.users().insertUser(user -> user.setLogin("erik").setActive(false));
  65. assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
  66. }
  67. @Test
  68. public void default_assignee_is_cached() {
  69. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
  70. UserDto userDto = db.users().insertUser("erik");
  71. db.organizations().addMember(organizationDto, userDto);
  72. assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid());
  73. // The setting is updated but the assignee hasn't changed
  74. settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "other");
  75. assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid());
  76. }
  77. }