use of org.sonar.api.utils.TempFolder in project sonarqube by SonarSource.
the class GlobalTempFolderProviderTest method createTempFolderDefault.
@Test
public void createTempFolderDefault() throws Exception {
System2 system = mock(System2.class);
tempFolderProvider = new GlobalTempFolderProvider(system);
File userHome = temp.newFolder();
when(system.envVariable("SONAR_USER_HOME")).thenReturn(null);
when(system.property("user.home")).thenReturn(userHome.getAbsolutePath().toString());
// if nothing is defined, it will be in {user.home}/.sonar/.sonartmp
File defaultSonarHome = new File(userHome.getAbsolutePath(), ".sonar");
File workingDir = new File(defaultSonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
try {
TempFolder tempFolder = tempFolderProvider.provide(new GlobalProperties(Collections.<String, String>emptyMap()));
tempFolder.newDir();
tempFolder.newFile();
assertThat(getCreatedTempDir(workingDir)).exists();
assertThat(getCreatedTempDir(workingDir).list()).hasSize(2);
} finally {
FileUtils.deleteQuietly(workingDir);
}
}
use of org.sonar.api.utils.TempFolder in project sonarqube by SonarSource.
the class GlobalTempFolderProviderTest method createTempFolderSonarHome.
@Test
public void createTempFolderSonarHome() throws Exception {
// with sonar home, it will be in {sonar.home}/.sonartmp
File sonarHome = temp.newFolder();
File workingDir = new File(sonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
TempFolder tempFolder = tempFolderProvider.provide(new GlobalProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath())));
tempFolder.newDir();
tempFolder.newFile();
assertThat(getCreatedTempDir(workingDir)).exists();
assertThat(getCreatedTempDir(workingDir).list()).hasSize(2);
FileUtils.deleteQuietly(sonarHome);
}
use of org.sonar.api.utils.TempFolder in project sonarqube by SonarSource.
the class AnalysisTempFolderProviderTest method createTempFolder.
@Test
public void createTempFolder() throws IOException {
File defaultDir = new File(temp.getRoot(), AnalysisTempFolderProvider.TMP_NAME);
TempFolder tempFolder = tempFolderProvider.provide(projectReactor);
tempFolder.newDir();
tempFolder.newFile();
assertThat(defaultDir).exists();
assertThat(defaultDir.list()).hasSize(2);
}
use of org.sonar.api.utils.TempFolder in project sonarqube by SonarSource.
the class TempFolderProviderTest method create_temp_dir_if_missing.
@Test
public void create_temp_dir_if_missing() throws Exception {
ServerFileSystem fs = mock(ServerFileSystem.class);
File tmpDir = temp.newFolder();
when(fs.getTempDir()).thenReturn(tmpDir);
FileUtils.forceDelete(tmpDir);
TempFolder folder = underTest.provide(fs);
assertThat(folder).isNotNull();
File newDir = folder.newDir();
assertThat(newDir).exists().isDirectory();
assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath());
}
use of org.sonar.api.utils.TempFolder in project sonarqube by SonarSource.
the class TempFolderProviderTest method existing_temp_dir.
@Test
public void existing_temp_dir() throws Exception {
ServerFileSystem fs = mock(ServerFileSystem.class);
File tmpDir = temp.newFolder();
when(fs.getTempDir()).thenReturn(tmpDir);
TempFolder folder = underTest.provide(fs);
assertThat(folder).isNotNull();
File newDir = folder.newDir();
assertThat(newDir).exists().isDirectory();
assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath());
}
Aggregations