]> source.dussan.org Git - sonarqube.git/blob
a67966441418beea2256358eea6e0641ed2dd640
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 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.ce.projectdump;
21
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.sonar.api.utils.System2;
25 import org.sonar.ce.queue.CeQueue;
26 import org.sonar.ce.queue.CeQueueImpl;
27 import org.sonar.core.util.UuidFactoryFast;
28 import org.sonar.db.DbClient;
29 import org.sonar.db.DbTester;
30 import org.sonar.db.ce.CeQueueDto;
31 import org.sonar.db.project.ProjectDto;
32 import org.sonar.server.platform.NodeInformation;
33
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.assertj.core.api.Assertions.assertThatThrownBy;
36 import static org.assertj.core.api.Assertions.tuple;
37 import static org.mockito.Mockito.mock;
38
39 public class ExportSubmitterImplIT {
40
41   private static final String SOME_SUBMITTER_UUID = "some submitter uuid";
42
43   private final System2 system2 = System2.INSTANCE;
44   @Rule
45   public DbTester db = DbTester.create(system2);
46
47   private final DbClient dbClient = db.getDbClient();
48   private final CeQueue ceQueue = new CeQueueImpl(system2, db.getDbClient(), UuidFactoryFast.getInstance(), mock(NodeInformation.class));
49
50   private final ExportSubmitterImpl underTest = new ExportSubmitterImpl(ceQueue, dbClient);
51
52   @Test
53   public void submitProjectExport_fails_with_NPE_if_project_key_is_null() {
54     assertThatThrownBy(() -> underTest.submitProjectExport(null, SOME_SUBMITTER_UUID))
55       .isInstanceOf(NullPointerException.class)
56       .hasMessage("Project key can not be null");
57   }
58
59   @Test
60   public void submitProjectExport_fails_with_IAE_if_project_with_specified_key_does_not_exist() {
61     assertThatThrownBy(() -> underTest.submitProjectExport("blabalble", SOME_SUBMITTER_UUID))
62       .isInstanceOf(IllegalArgumentException.class)
63       .hasMessage("Project with key [blabalble] does not exist");
64   }
65
66   @Test
67   public void submitProjectExport_submits_task_with_project_uuid_and_submitterLogin_if_present() {
68     ProjectDto projectDto = db.components().insertPrivateProject().getProjectDto();
69
70     underTest.submitProjectExport(projectDto.getKey(), SOME_SUBMITTER_UUID);
71
72     assertThat(dbClient.ceQueueDao().selectAllInAscOrder(db.getSession()))
73       .extracting(CeQueueDto::getComponentUuid, CeQueueDto::getTaskType, CeQueueDto::getSubmitterUuid)
74       .containsExactlyInAnyOrder(tuple(projectDto.getUuid(), "PROJECT_EXPORT", SOME_SUBMITTER_UUID));
75   }
76
77   @Test
78   public void submitProjectExport_submits_task_with_project_uuid_and_no_submitterLogin_if_null() {
79     ProjectDto projectDto = db.components().insertPrivateProject().getProjectDto();
80
81     underTest.submitProjectExport(projectDto.getKey(), null);
82
83     assertThat(dbClient.ceQueueDao().selectAllInAscOrder(db.getSession()))
84       .extracting(CeQueueDto::getComponentUuid, CeQueueDto::getTaskType, CeQueueDto::getSubmitterUuid)
85       .containsExactlyInAnyOrder(tuple(projectDto.getUuid(), "PROJECT_EXPORT", null));
86   }
87
88 }