]> source.dussan.org Git - sonarqube.git/blob
cd12341368ef3c5a57b7c9fa331a4fe3f790dcea
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2021 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.projectexport.util;
21
22 import java.io.File;
23 import java.io.IOException;
24 import org.junit.Before;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.TemporaryFolder;
28 import org.sonar.api.config.internal.MapSettings;
29 import org.sonar.ce.task.projectexport.taskprocessor.ProjectDescriptor;
30
31 import static org.assertj.core.api.Assertions.assertThat;
32
33 public class ProjectImportDumpFSImplTest {
34
35   @Rule
36   public TemporaryFolder temp = new TemporaryFolder();
37
38   private final MapSettings settings = new MapSettings();
39   private final ProjectDescriptor projectDescriptor = new ProjectDescriptor("uuid", "project_key", "name");
40   private final ProjectDescriptor descriptorWithUglyKey = new ProjectDescriptor("uuid", "  so:me à9ç& Key ", "name");
41
42   private File dataDir;
43   private ProjectImportDumpFSImpl underTest;
44
45   @Before
46   public void setUp() throws Exception {
47     this.dataDir = temp.newFolder();
48     settings.setProperty("sonar.path.data", dataDir.getAbsolutePath());
49     this.underTest = new ProjectImportDumpFSImpl(settings.asConfig());
50   }
51
52   @Test
53   public void start_creates_import_and_export_directories_including_missing_parents() throws IOException {
54     dataDir = new File(temp.newFolder(), "data");
55     File importDir = new File(dataDir, "governance/project_dumps/import");
56     File exportDir = new File(dataDir, "governance/project_dumps/export");
57
58     settings.setProperty("sonar.path.data", dataDir.getAbsolutePath());
59     this.underTest = new ProjectImportDumpFSImpl(settings.asConfig());
60
61     assertThat(dataDir).doesNotExist();
62     assertThat(importDir).doesNotExist();
63     assertThat(exportDir).doesNotExist();
64
65     underTest.start();
66
67     assertThat(dataDir).exists().isDirectory();
68     assertThat(importDir).exists().isDirectory();
69     assertThat(exportDir).exists().isDirectory();
70   }
71
72   @Test
73   public void importDumpOf_is_located_in_governance_project_dump_in() {
74     assertThat(underTest.importDumpOf(projectDescriptor)).isEqualTo(new File(dataDir, "governance/project_dumps/import/project_key.zip"));
75   }
76
77   @Test
78   public void importDumpOf_slugifies_project_key() {
79     assertThat(underTest.importDumpOf(descriptorWithUglyKey))
80       .isEqualTo(new File(dataDir, "governance/project_dumps/import/so-me-a9c-key.zip"));
81   }
82
83 }