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 ProjectExportDumpFSImplTest {
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 ProjectExportDumpFSImpl underTest;
46 public void setUp() throws Exception {
47 this.dataDir = temp.newFolder();
48 settings.setProperty("sonar.path.data", dataDir.getAbsolutePath());
49 this.underTest = new ProjectExportDumpFSImpl(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 ProjectExportDumpFSImpl(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 exportDumpOf_is_located_in_governance_project_dump_out() {
74 assertThat(underTest.exportDumpOf(projectDescriptor)).isEqualTo(new File(dataDir, "governance/project_dumps/export/project_key.zip"));
78 public void exportDumpOf_slugifies_project_key() {
79 assertThat(underTest.exportDumpOf(descriptorWithUglyKey))
80 .isEqualTo(new File(dataDir, "governance/project_dumps/export/so-me-a9c-key.zip"));