3 * Copyright (C) 2009-2021 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.ce.task.projectexport.util;
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;
31 import static org.assertj.core.api.Assertions.assertThat;
33 public class ProjectImportDumpFSImplTest {
36 public TemporaryFolder temp = new TemporaryFolder();
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");
43 private ProjectImportDumpFSImpl underTest;
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());
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");
58 settings.setProperty("sonar.path.data", dataDir.getAbsolutePath());
59 this.underTest = new ProjectImportDumpFSImpl(settings.asConfig());
61 assertThat(dataDir).doesNotExist();
62 assertThat(importDir).doesNotExist();
63 assertThat(exportDir).doesNotExist();
67 assertThat(dataDir).exists().isDirectory();
68 assertThat(importDir).exists().isDirectory();
69 assertThat(exportDir).exists().isDirectory();
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"));
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"));