Refine search
@Test public void testWriteWithEncoding_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception { final File file = TestUtils.newFile(getTestDirectory(), "lines.txt"); FileUtils.writeStringToFile(file, "This line was there before you..."); FileUtils.write(file, "this is brand new data", (String) null, true); final String expected = "This line was there before you..." + "this is brand new data"; final String actual = FileUtils.readFileToString(file); assertEquals(expected, actual); }
@Test public void should_not_load_reference_hashes_when_status_same() throws Exception { final String source = "source"; String key = "foo:src/Foo.java"; FileUtils.write(ioFile, source, StandardCharsets.UTF_8); when(file.key()).thenReturn(key); when(file.status()).thenReturn(InputFile.Status.SAME); assertThat(sourceHashHolder.getHashedReference().getHash(1)).isEqualTo(md5Hex(source)); Mockito.verifyNoMoreInteractions(lastSnapshots); }
private File createAllLogsFiles() throws IOException { File dir = createLogsDir(); FileUtils.write(new File(dir, "sonar.log"), "{app}"); FileUtils.write(new File(dir, "ce.log"), "{ce}"); FileUtils.write(new File(dir, "es.log"), "{es}"); FileUtils.write(new File(dir, "web.log"), "{web}"); return dir; }
@Test public void testWriteWithEncoding_WithAppendOptionFalse_ShouldDeletePreviousFileLines() throws Exception { final File file = TestUtils.newFile(getTestDirectory(), "lines.txt"); FileUtils.writeStringToFile(file, "This line was there before you..."); FileUtils.write(file, "this is brand new data", (String) null, false); final String expected = "this is brand new data"; final String actual = FileUtils.readFileToString(file); assertEquals(expected, actual); }
@Test public void testScp() throws Exception { if (isRemote == false) return; SSHClient ssh = new SSHClient(this.hostname, this.port, this.username, this.password); File tmpFile = File.createTempFile("test_scp", "", new File("/tmp")); tmpFile.deleteOnExit(); FileUtils.write(tmpFile, "test_scp", Charset.defaultCharset()); ssh.scpFileToRemote(tmpFile.getAbsolutePath(), "/tmp"); } }
@Test public void no_reference_hashes_when_status_added() throws Exception { final String source = "source"; String key = "foo:src/Foo.java"; FileUtils.write(ioFile, source, StandardCharsets.UTF_8); when(file.key()).thenReturn(key); when(file.status()).thenReturn(InputFile.Status.ADDED); assertThat(sourceHashHolder.getHashedReference()).isNull(); Mockito.verifyNoMoreInteractions(lastSnapshots); }
@Test public void testWrite_WithAppendOptionTrue_ShouldNotDeletePreviousFileLines() throws Exception { final File file = TestUtils.newFile(getTestDirectory(), "lines.txt"); FileUtils.writeStringToFile(file, "This line was there before you..."); FileUtils.write(file, "this is brand new data", true); final String expected = "This line was there before you..." + "this is brand new data"; final String actual = FileUtils.readFileToString(file); assertEquals(expected, actual); }
@Test public void publishSourceWithLastEmptyLine() throws Exception { FileUtils.write(sourceFile, "1\n2\n3\n4\n", StandardCharsets.ISO_8859_1); publisher.publish(writer); File out = writer.getSourceFile(inputFile.scannerId()); assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n"); }
@Test public void testWrite_WithAppendOptionFalse_ShouldDeletePreviousFileLines() throws Exception { final File file = TestUtils.newFile(getTestDirectory(), "lines.txt"); FileUtils.writeStringToFile(file, "This line was there before you..."); FileUtils.write(file, "this is brand new data", false); final String expected = "this is brand new data"; final String actual = FileUtils.readFileToString(file); assertEquals(expected, actual); }
@Test public void warnWhenSavingFolderMeasure() throws IOException { File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\n\n\ncontent", StandardCharsets.UTF_8); File folderMeasures = new File(srcDir, "folder.measures"); FileUtils.write(folderMeasures, "tests:10", StandardCharsets.UTF_8); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) .put("sonar.projectKey", "com.foo.project") .put("sonar.sources", "src") .build()) .execute(); assertThat(logTester.logs(LoggerLevel.WARN)).contains("Storing measures on folders or modules is deprecated. Provided value of metric 'tests' is ignored."); }
private File prepareProject() throws IOException { File baseDir = temp.newFolder(); File module1Dir = new File(baseDir, "module1"); module1Dir.mkdir(); File srcDir = new File(module1Dir, "src"); srcDir.mkdir(); File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10"); return baseDir; }
@Test public void publishTestSource() throws Exception { FileUtils.write(sourceFile, "1\n2\n3\n4\n", StandardCharsets.ISO_8859_1); // sampleFile.setQualifier(Qualifiers.UNIT_TEST_FILE); publisher.publish(writer); File out = writer.getSourceFile(inputFile.scannerId()); assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n"); }
@Test public void testChangeLogForAnalysis() throws IOException, InterruptedException { File srcDir = new File(baseDir, "src"); srcDir.mkdir(); File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent"); tester.newAnalysis() .properties(builder .put("sonar.sources", "src") .put("sonar.verbose", "true") .build()) .execute(); for (LogEvent e : logOutput) { savedStdOut.println("[captured]" + e.level + " " + e.msg); } // only done in DEBUG during analysis assertThat(logOutputStr.toString()).contains("Post-jobs : "); }