3 * Copyright (C) 2009-2022 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 package org.sonar.server.ce.projectdump;
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.component.ComponentDto;
32 import org.sonar.server.platform.WebServer;
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;
39 public class ExportSubmitterImplTest {
41 private static final String SOME_SUBMITTER_UUID = "some submitter uuid";
43 private final System2 system2 = System2.INSTANCE;
45 public DbTester db = DbTester.create(system2);
47 private final DbClient dbClient = db.getDbClient();
48 private final CeQueue ceQueue = new CeQueueImpl(system2, db.getDbClient(), UuidFactoryFast.getInstance(), mock(WebServer.class));
50 private final ExportSubmitterImpl underTest = new ExportSubmitterImpl(ceQueue, dbClient);
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");
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");
67 public void submitProjectExport_submits_task_with_project_uuid_and_submitterLogin_if_present() {
68 ComponentDto projectDto = db.components().insertPrivateProject();
70 underTest.submitProjectExport(projectDto.getKey(), SOME_SUBMITTER_UUID);
72 assertThat(dbClient.ceQueueDao().selectAllInAscOrder(db.getSession()))
73 .extracting(CeQueueDto::getComponentUuid, CeQueueDto::getTaskType, CeQueueDto::getSubmitterUuid)
74 .containsExactlyInAnyOrder(tuple(projectDto.uuid(), "PROJECT_EXPORT", SOME_SUBMITTER_UUID));
78 public void submitProjectExport_submits_task_with_project_uuid_and_no_submitterLogin_if_null() {
79 ComponentDto projectDto = db.components().insertPrivateProject();
81 underTest.submitProjectExport(projectDto.getKey(), null);
83 assertThat(dbClient.ceQueueDao().selectAllInAscOrder(db.getSession()))
84 .extracting(CeQueueDto::getComponentUuid, CeQueueDto::getTaskType, CeQueueDto::getSubmitterUuid)
85 .containsExactlyInAnyOrder(tuple(projectDto.uuid(), "PROJECT_EXPORT", null));