@Test public void testCWD() throws CLIException { CLI cli = CLIConfigurator.define(command.getClass()); CommandLine evaluatedCLI = parse(cli, "--name=vert.x"); CLIConfigurator.inject(evaluatedCLI, command); assertThat(command.getCwd()).isEqualTo(new File(".")); evaluatedCLI = parse(cli, "--cwd=target", "--name=vert.x"); CLIConfigurator.inject(evaluatedCLI, command); assertThat(command.getCwd()).isEqualTo(new File("target")); }
@Test public void relative_path_from_not_normalized_dirs() throws IOException { PathResolver resolver = new PathResolver(); File rootDir = new File(temp.newFolder(), "foo/.."); File org = new File(rootDir, "org"); File hello = new File(org, "hello"); File world = new File(hello, "World.java"); PathResolver.RelativePath relativePath = resolver.relativePath(Arrays.asList(rootDir), world); assertThat(relativePath).isNotNull(); assertThat(relativePath.dir()).isEqualTo(rootDir); assertThat(relativePath.path()).isEqualTo("org/hello/World.java"); }
@Test public void shouldInitRootWorkDir() { ProjectReactorBuilder builder = new ProjectReactorBuilder(new ScannerProperties(Maps.<String, String>newHashMap()), mock(AnalysisWarnings.class)); File baseDir = new File("target/tmp/baseDir"); File workDir = builder.initRootProjectWorkDir(baseDir, Maps.<String, String>newHashMap()); assertThat(workDir).isEqualTo(new File(baseDir, ".sonar")); }
@Test public void test_file_system_information() throws IOException { File home = temp.newFolder(); when(fs.getHomeDir()).thenReturn(home); assertThat(underTest.getRootDir()).isEqualTo(home); }
@Test public void shouldGetRelativeFile() { assertThat(ProjectReactorBuilder.resolvePath(getResource(this.getClass(), "/"), "shouldGetFile/foo.properties")) .isEqualTo(getResource(this.getClass(), "shouldGetFile/foo.properties")); }
@Test public void get_file() { BatchIndex batchIndex = new BatchIndex(fs); batchIndex.start(); File file = batchIndex.getFile("sonar-batch.jar"); assertThat(file).isEqualTo(jar); }
@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 working_directory() { Command command = Command.create("java"); assertThat(command.getDirectory()).isNull(); File working = new File("working"); command = Command.create("java").setDirectory(working); assertThat(command.getDirectory()).isEqualTo(working); }
@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 checkAndComplete_sets_driver_path_for_oracle() throws Exception { File driverFile = new File(homeDir, "extensions/jdbc-driver/oracle/ojdbc6.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:oracle:thin:@localhost/XE"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void getElasticsearchYml_is_in_es_conf_directory() throws IOException { File tempDir = temp.newFolder(); Props props = new Props(new Properties()); props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); assertThat(underTest.getElasticsearchYml()).isEqualTo(new File(tempDir, "conf/es/elasticsearch.yml")); }
@Test public void filesWithDefaultPredicate() { DefaultInputFile file1 = new TestInputFileBuilder("foo", "src/Foo.php").setLanguage("php").build(); fs.add(file1); fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build()); fs.add(new TestInputFileBuilder("foo", "src/Baz.java").setLanguage("java").build()); fs.setDefaultPredicate(p -> f -> f.relativePath().endsWith("Foo.php")); Iterator<File> iterator = fs.files(fs.predicates().all()).iterator(); assertThat(iterator.hasNext()).isTrue(); assertThat(iterator.next()).isEqualTo(file1.file()); assertThat(iterator.hasNext()).isFalse(); }
@Test public void sets_driver_path_for_h2() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/h2/h2.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:h2:tcp://localhost:9092/sonar"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void checkAndComplete_sets_driver_path_for_postgresql() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/postgresql/pg.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:postgresql://localhost/sonar"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void getLog4j2Properties_is_in_es_conf_directory() throws IOException { File tempDir = temp.newFolder(); Props props = new Props(new Properties()); props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); assertThat(underTest.getLog4j2PropertiesLocation()).isEqualTo(new File(tempDir, "conf/es/log4j2.properties")); }
@Test public void getJvmOptions_is_in_es_conf_directory() throws IOException { File tempDir = temp.newFolder(); Props props = new Props(new Properties()); props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); assertThat(underTest.getJvmOptions()).isEqualTo(new File(tempDir, "conf/es/jvm.options")); } }
@Test public void checkAndComplete_sets_driver_path_for_mssql() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/mssql/sqljdbc4.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:sqlserver://localhost/sonar;SelectMethod=Cursor"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void getHomeDirectory_is_elasticsearch_subdirectory_of_sq_home_directory() throws IOException { File sqHomeDir = temp.newFolder(); Props props = new Props(new Properties()); props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath()); props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); assertThat(underTest.getHomeDirectory()).isEqualTo(new File(sqHomeDir, "elasticsearch")); }
@Test public void conf_directory_is_conf_es_subdirectory_of_sq_temp_directory() throws IOException { File tempDir = temp.newFolder(); Props props = new Props(new Properties()); props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_HOME.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_TEMP.getKey(), tempDir.getAbsolutePath()); props.set(PATH_LOGS.getKey(), temp.newFolder().getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); assertThat(underTest.getConfDirectory()).isEqualTo(new File(tempDir, "conf/es")); }
@Test public void getLogDirectory_is_configured_with_non_nullable_PATH_LOG_variable() throws IOException { File sqHomeDir = temp.newFolder(); File logDir = temp.newFolder(); Props props = new Props(new Properties()); props.set(PATH_DATA.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_HOME.getKey(), sqHomeDir.getAbsolutePath()); props.set(PATH_TEMP.getKey(), temp.newFolder().getAbsolutePath()); props.set(PATH_LOGS.getKey(), logDir.getAbsolutePath()); EsInstallation underTest = new EsInstallation(props); assertThat(underTest.getLogDirectory()).isEqualTo(logDir); }