12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- /*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
- package org.sonar.ce.task.projectanalysis.issue;
-
- import org.junit.Before;
- import org.junit.Rule;
- import org.junit.Test;
- import org.sonar.api.CoreProperties;
- import org.sonar.api.config.internal.MapSettings;
- import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository;
- import org.sonar.ce.task.projectanalysis.component.TestSettingsRepository;
- import org.sonar.db.DbTester;
- import org.sonar.db.organization.OrganizationDto;
- import org.sonar.db.user.UserDto;
-
- import static org.assertj.core.api.Assertions.assertThat;
-
- public class DefaultAssigneeTest {
-
- public static final String PROJECT_KEY = "PROJECT_KEY";
- public static final String ORGANIZATION_UUID = "ORGANIZATION_UUID";
-
- @Rule
- public DbTester db = DbTester.create();
-
- private MapSettings settings = new MapSettings();
- private ConfigurationRepository settingsRepository = new TestSettingsRepository(settings.asConfig());
- private OrganizationDto organizationDto;
-
- private DefaultAssignee underTest = new DefaultAssignee(db.getDbClient(), settingsRepository);
-
- @Before
- public void setUp() {
- organizationDto = db.organizations().insertForUuid(ORGANIZATION_UUID);
- }
-
- @Test
- public void no_default_assignee() {
- assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
- }
-
- @Test
- public void set_default_assignee() {
- settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
- UserDto userDto = db.users().insertUser("erik");
- db.organizations().addMember(organizationDto, userDto);
-
- assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid());
- }
-
- @Test
- public void configured_login_does_not_exist() {
- settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
-
- assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
- }
-
- @Test
- public void configured_login_is_disabled() {
- settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
- db.users().insertUser(user -> user.setLogin("erik").setActive(false));
-
- assertThat(underTest.loadDefaultAssigneeUuid()).isNull();
- }
-
- @Test
- public void default_assignee_is_cached() {
- settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
- UserDto userDto = db.users().insertUser("erik");
- db.organizations().addMember(organizationDto, userDto);
- assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid());
-
- // The setting is updated but the assignee hasn't changed
- settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "other");
- assertThat(underTest.loadDefaultAssigneeUuid()).isEqualTo(userDto.getUuid());
- }
- }
|