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