@Test public void shouldCreateDesEncryptorIfCipherFileIsPresent() throws IOException { resetCipher.setupDESCipherFile(); assertThat(desCipherFile).exists(); GoCipher goCipher = new GoCipher(systemEnvironment); assertThat(goCipher.aesEncrypter).isNotNull(); assertThat(goCipher.desEncrypter).isNotNull(); }
@Test public void shouldDefineProjectWithBuildDir() { ProjectDefinition rootProject = loadProjectDefinition("simple-project-with-build-dir"); File buildDir = rootProject.getBuildDir(); assertThat(buildDir).isDirectory().exists(); assertThat(new File(buildDir, "report.txt")).isFile().exists(); assertThat(buildDir.getName()).isEqualTo("build"); }
/** * Packing and unpacking a JAR generates a different file. */ private void verifySameContentAfterCompression(File file1, File file2) throws IOException { assertThat(file1).isFile().exists(); assertThat(file2).isFile().exists(); assertThat(packAndUnpackJar(file1)).hasSameContentAs(packAndUnpackJar(file2)); }
@Test public void copy_and_extract_libs() throws IOException { File jar = loadFile("sonar-checkstyle-plugin-2.8.jar"); ExplodedPlugin exploded = underTest.explode(PluginInfo.create(jar)); assertThat(exploded.getKey()).isEqualTo("checkstyle"); assertThat(exploded.getMain()).isFile().exists(); assertThat(exploded.getLibs()).extracting(File::getName).containsExactlyInAnyOrder("antlr-2.7.6.jar", "checkstyle-5.1.jar", "commons-cli-1.0.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/lib/checkstyle-5.1.jar")).exists(); }
@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()); }
@Test public void test_directories() throws Exception { assertThat(fs.baseDir()).isAbsolute().isDirectory().exists(); assertThat(fs.baseDir().getCanonicalPath()).isEqualTo(basedir.getCanonicalPath()); File workdir = temp.newFolder(); fs.setWorkDir(workdir.toPath()); assertThat(fs.workDir()).isAbsolute().isDirectory().exists(); assertThat(fs.workDir().getCanonicalPath()).isEqualTo(workdir.getCanonicalPath()); }
@Test public void test_generation_of_file() throws IOException { File yamlFile = temp.newFile(); new EsYmlSettings(new HashMap<>()).writeToYmlSettingsFile(yamlFile); assertThat(yamlFile).exists(); assertThat(yamlFile).hasContent("# This file has been automatically generated by SonarQube during startup.\n" + "\n" + "# DO NOT EDIT THIS FILE\n" + "\n" + "{\n" + " }"); }
@Test public void create_dir_and_configure_static_directory() throws Exception { File dir = temp.newFolder(); dir.delete(); underTest.addStaticDir(tomcat, "/deploy", dir); assertThat(dir).isDirectory().exists(); verify(tomcat).addWebapp("/deploy", dir.getAbsolutePath()); }
@Test public void cleanup_static_directory_if_already_exists() throws Exception { File dir = temp.newFolder(); FileUtils.touch(new File(dir, "foo.txt")); underTest.addStaticDir(tomcat, "/deploy", dir); assertThat(dir).isDirectory().exists(); assertThat(dir.listFiles()).isEmpty(); }
@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 ScannerProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath()))); tempFolder.newDir(); tempFolder.newFile(); assertThat(getCreatedTempDir(workingDir)).exists(); assertThat(getCreatedTempDir(workingDir).list()).hasSize(2); FileUtils.deleteQuietly(sonarHome); }
@Test public void createTempFolder() throws IOException { File defaultDir = new File(temp.getRoot(), AnalysisTempFolderProvider.TMP_NAME); TempFolder tempFolder = tempFolderProvider.provide(project); tempFolder.newDir(); tempFolder.newFile(); assertThat(defaultDir).exists(); assertThat(defaultDir.list()).hasSize(2); } }
@Test public void detectHomeDir_returns_existing_dir() { assertThat(new AppSettingsLoaderImpl(new String[0]).getHomeDir()).exists().isDirectory(); } }
@Test public void contextProperties_file() throws Exception { File dir = temp.newFolder(); File file = new File(dir, "context-props.pb"); FileUtils.write(file, "content"); FileStructure structure = new FileStructure(dir); assertThat(structure.contextProperties()).exists().isFile().isEqualTo(file); } }
@Test public void downloadToFile() throws URISyntaxException, IOException { File toDir = temporaryFolder.newFolder(); File toFile = new File(toDir, "downloadToFile.txt"); new DefaultHttpDownloader(new MapSettings().asConfig()).download(new URI(baseUrl), toFile); assertThat(toFile).exists(); assertThat(toFile.length()).isGreaterThan(10l); }
@Test public void explode_jar_to_temp_directory() { PluginInfo info = PluginInfo.create(plugin1Jar()); ExplodedPlugin exploded = underTest.explode(info); // all the files loaded by classloaders (JAR + META-INF/libs/*.jar) are copied to a dedicated temp directory File copiedJar = exploded.getMain(); assertThat(exploded.getKey()).isEqualTo("test"); assertThat(copiedJar).isFile().exists(); assertThat(copiedJar.getParentFile()).isDirectory().hasName("test"); assertThat(copiedJar.getParentFile().getParentFile()).isDirectory().hasName("ce-exploded-plugins"); }
@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(); }
@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 plugins_do_not_overlap() { PluginInfo info1 = PluginInfo.create(plugin1Jar()); PluginInfo info2 = PluginInfo.create(plugin2Jar()); ExplodedPlugin exploded1 = underTest.explode(info1); ExplodedPlugin exploded2 = underTest.explode(info2); assertThat(exploded1.getKey()).isEqualTo("test"); assertThat(exploded1.getMain()).isFile().exists().hasName("sonar-test-plugin-0.1-SNAPSHOT.jar"); assertThat(exploded2.getKey()).isEqualTo("test2"); assertThat(exploded2.getMain()).isFile().exists().hasName("sonar-test2-plugin-0.1-SNAPSHOT.jar"); }
@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(); }