@Test public void reset_deletes_content_of_temp_dir_but_not_temp_dir_itself_if_it_already_exists() throws Exception { assertThat(tempDir.mkdir()).isTrue(); Object tempDirKey = getFileKey(tempDir); File fileInTempDir = new File(tempDir, "someFile.txt"); assertThat(fileInTempDir.createNewFile()).isTrue(); File subDirInTempDir = new File(tempDir, "subDir"); assertThat(subDirInTempDir.mkdir()).isTrue(); underTest.reset(); assertThat(tempDir).exists(); assertThat(fileInTempDir).doesNotExist(); assertThat(subDirInTempDir).doesNotExist(); assertThat(getFileKey(tempDir)).isEqualTo(tempDirKey); }
@Test public void extract_only_libs() throws IOException { File jar = loadFile("sonar-checkstyle-plugin-2.8.jar"); underTest.explode(PluginInfo.create(jar)); assertThat(new File(jar.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists(); assertThat(new File(jar.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/MANIFEST.MF")).doesNotExist(); assertThat(new File(jar.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/org/sonar/plugins/checkstyle/CheckstyleVersion.class")).doesNotExist(); }
@Test public void shouldNotCreateDesCipherIfCipherFileMissing() { assertThat(desCipherFile).doesNotExist(); GoCipher goCipher = new GoCipher(systemEnvironment); assertThat(goCipher.aesEncrypter).isNotNull(); assertThat(goCipher.desEncrypter).isNull(); }
@Test public void testWithFile() { final File file = Converters.create(File.class, "foo/hello.txt"); assertThat(file).hasName("hello.txt") .doesNotExist(); }
@Test public void deleteQuietly_does_not_fail_if_file_does_not_exist() throws IOException { File file = new File(temporaryFolder.newFolder(), "blablabl"); assertThat(file).doesNotExist(); FileUtils.deleteQuietly(file); }
@Test public void deleteQuietly_does_not_fail_if_file_does_not_exist() throws IOException { File file = new File(temporaryFolder.newFolder(), "blablabl"); assertThat(file).doesNotExist(); FileUtils2.deleteQuietly(file); }
@Test public void uninstall_dependents() throws Exception { File base = copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); File extension = copyTestPluginTo("test-require-plugin", fs.getInstalledPluginsDir()); File uninstallDir = temp.newFolder("uninstallDir"); underTest.start(); assertThat(underTest.getPluginInfos()).hasSize(2); underTest.uninstall("testbase", uninstallDir); assertThat(base).doesNotExist(); assertThat(extension).doesNotExist(); assertThat(uninstallDir.list()).containsOnly(base.getName(), extension.getName()); }
@Test public void shouldNotCreateFileIfFailToDownload() throws Exception { File toDir = temporaryFolder.newFolder(); File toFile = new File(toDir, "downloadToFile.txt"); try { int port = new InetSocketAddress("localhost", 0).getPort(); new DefaultHttpDownloader(new MapSettings().asConfig()).download(new URI("http://localhost:" + port), toFile); } catch (SonarException e) { assertThat(toFile).doesNotExist(); } }
@Test public void downloaded_file_overrides_existing_installed_file_on_startup() throws Exception { File installedV1 = copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); File downloadedV2 = copyTestPluginTo("test-base-plugin-v2", fs.getDownloadedPluginsDir()); underTest.start(); // plugin is moved to extensions/plugins and replaces v1 assertThat(downloadedV2).doesNotExist(); assertThat(installedV1).doesNotExist(); assertThat(new File(fs.getInstalledPluginsDir(), downloadedV2.getName())).exists(); assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); assertThat(underTest.getPluginInfo("testbase").getVersion()).isEqualTo(Version.create("0.2-SNAPSHOT")); }
@Test public void clean_deletes_non_empty_directory() throws Exception { File dir = temp.newFolder(); FileUtils.touch(new File(dir, "foo.txt")); DefaultTempFolder underTest = new DefaultTempFolder(dir); underTest.clean(); assertThat(dir).doesNotExist(); }
@Test public void clean_does_not_fail_if_directory_has_already_been_deleted() throws Exception { File dir = temp.newFolder(); DefaultTempFolder underTest = new DefaultTempFolder(dir); underTest.clean(); assertThat(dir).doesNotExist(); // second call does not fail, nor log ERROR logs underTest.clean(); assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty(); } }
@Test public void install_downloaded_plugins_on_startup() throws Exception { File downloadedJar = copyTestPluginTo("test-base-plugin", fs.getDownloadedPluginsDir()); underTest.start(); // plugin is moved to extensions/plugins then loaded assertThat(downloadedJar).doesNotExist(); assertThat(new File(fs.getInstalledPluginsDir(), downloadedJar.getName())).isFile().exists(); assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); }
@Test public void should_stop_and_clean_temp_dir() { File tempDir = cachesManager.tempDir(); assertThat(tempDir).isDirectory().exists(); assertThat(cachesManager.persistit()).isNotNull(); assertThat(cachesManager.persistit().isInitialized()).isTrue(); cachesManager.stop(); assertThat(tempDir).doesNotExist(); assertThat(cachesManager.tempDir()).isNull(); assertThat(cachesManager.persistit()).isNull(); } }
@Test public void dont_uninstall_non_existing_files() throws IOException { File base = copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); File extension = copyTestPluginTo("test-require-plugin", fs.getInstalledPluginsDir()); File uninstallDir = temp.newFolder("uninstallDir"); underTest.start(); assertThat(underTest.getPluginInfos()).hasSize(2); underTest.uninstall("testbase", uninstallDir); assertThat(underTest.getPluginInfos()).hasSize(2); underTest.uninstall("testbase", uninstallDir); assertThat(base).doesNotExist(); assertThat(extension).doesNotExist(); assertThat(uninstallDir.list()).containsOnly(base.getName(), extension.getName()); }
@Test public void do_not_write_warnings_report_when_empty() throws IOException { File outputDir = temp.newFolder(); ScannerReportWriter writer = new ScannerReportWriter(outputDir); underTest.publish(writer); assertThat(writer.getFileStructure().analysisWarnings()).doesNotExist(); ScannerReportReader reader = new ScannerReportReader(outputDir); List<ScannerReport.AnalysisWarning> warnings = Lists.newArrayList(reader.readAnalysisWarnings()); assertThat(warnings).isEmpty(); } }
@Test public void shouldNotDumpInIssuesMode() throws Exception { when(analysisMode.isIssues()).thenReturn(true); ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder()); publisher.init(writer); assertThat(writer.getFileStructure().analysisLog()).doesNotExist(); }
@Test public void blacklisted_plugin_is_automatically_uninstalled_on_startup() throws Exception { underTest.setBlacklistedPluginKeys(ImmutableSet.of("testbase", "issuesreport")); File jar = copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); underTest.start(); // plugin is not installed and file is deleted assertThat(underTest.getPluginInfos()).isEmpty(); assertThat(jar).doesNotExist(); }
@Test public void uninstall() throws Exception { File installedJar = copyTestPluginTo("test-base-plugin", fs.getInstalledPluginsDir()); File uninstallDir = temp.newFolder("uninstallDir"); underTest.start(); assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); underTest.uninstall("testbase", uninstallDir); assertThat(installedJar).doesNotExist(); // still up. Will be dropped after next startup assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase"); assertThat(uninstallDir.list()).containsOnly(installedJar.getName()); }
@Test public void createTempFolderWithName() throws Exception { File rootTempFolder = temp.newFolder(); DefaultTempFolder underTest = new DefaultTempFolder(rootTempFolder); File dir = underTest.newDir("sample"); assertThat(dir).exists().isDirectory(); assertThat(new File(rootTempFolder, "sample")).isEqualTo(dir); new TempFolderCleaner(underTest).stop(); assertThat(rootTempFolder).doesNotExist(); }
@Test public void createTempFolderAndFile() throws Exception { File rootTempFolder = temp.newFolder(); DefaultTempFolder underTest = new DefaultTempFolder(rootTempFolder); File dir = underTest.newDir(); assertThat(dir).exists().isDirectory(); File file = underTest.newFile(); assertThat(file).exists().isFile(); new TempFolderCleaner(underTest).stop(); assertThat(rootTempFolder).doesNotExist(); }