@Test public void filesToBytesAndThenBytesToFiles() throws IOException { File file1 = new File(temporaryFolder.getRoot(), "file1.txt"); File file2 = new File(temporaryFolder.getRoot(), "file2.txt"); FileUtils.write(file1, "file1-content", "UTF-8"); FileUtils.write(file2, "file2-content", "UTF-8"); List<String> fileNames = Arrays.asList(file1.getAbsolutePath(), file2.getAbsolutePath()); Byte[][] bytes = CliUtil.filesToBytes(fileNames); File dir = temporaryFolder.newFolder("temp"); List<String> filePaths = CliUtil.bytesToFiles(bytes, dir.getAbsolutePath()); assertThat(filePaths).hasSize(2); assertThat(new File(filePaths.get(0))).hasContent("file1-content"); assertThat(new File(filePaths.get(1))).hasContent("file2-content"); } }
@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 dumpAsCsv_creates_csv_dump_of_score_matrix_if_property_is_true() throws IOException { String taskUuid = "acme"; when(ceTask.getUuid()).thenReturn(taskUuid); settings.setProperty("sonar.filemove.dumpCsv", "true"); underTest.dumpAsCsv(A_SCORE_MATRIX); Collection<File> files = listDumpFilesForTaskUuid(taskUuid); assertThat(files).hasSize(1); assertThat(files.iterator().next()).hasContent(A_SCORE_MATRIX.toCsv(';')); }
@Test public void unzip_report() throws Exception { logTester.setLevel(LoggerLevel.DEBUG); File reportFile = generateReport(); try (InputStream input = FileUtils.openInputStream(reportFile)) { dbTester.getDbClient().ceTaskInputDao().insert(dbTester.getSession(), TASK_UUID, input); } dbTester.getSession().commit(); dbTester.getSession().close(); underTest.execute(new TestComputationStepContext()); // directory contains the uncompressed report (which contains only metadata.pb in this test) File unzippedDir = reportDirectoryHolder.getDirectory(); assertThat(unzippedDir).isDirectory().exists(); assertThat(unzippedDir.listFiles()).hasSize(1); assertThat(new File(unzippedDir, "metadata.pb")).hasContent("{metadata}"); assertThat(logTester.logs(LoggerLevel.DEBUG)).anyMatch(log -> log.matches("Analysis report is \\d+ bytes uncompressed")); }
assertThat(file).hasContent( "# This file has been automatically generated by SonarQube during startup.\n" + "# Please use sonar.search.javaOpts and/or sonar.search.javaAdditionalOpts in sonar.properties to specify jvm options for Elasticsearch\n" +
public void hasContent(String expected, Charset charset) { Assertions.assertThat(file).usingCharset(charset).hasContent(expected); }
@Test public void itAbsorbsFileAlreadyExistsExceptionsWhenCopyingDuplicateFiles() { List<String> lines = Arrays.asList("Testing", "1", "2", "3"); Path originalPath = write("original.txt", lines); assertThat(originalPath.toFile()).hasContent(String.join(System.lineSeparator(), lines)); Path copyPath = Paths.get(cacheDir.getRoot().toString() + "/copy.txt"); assertThat(copyPath).doesNotExist(); artifactManager.copy(originalPath, cacheDir.getRoot().toPath(), "copy.txt"); assertThat(copyPath).exists(); // A redundant copy operation should not throw. artifactManager.copy(originalPath, cacheDir.getRoot().toPath(), "copy.txt"); }
@Test public void customSnippetTemplate() throws Exception { ClassLoader classLoader = new URLClassLoader(new URL[] { new File("src/test/resources/custom-snippet-templates").toURI().toURL() }, getClass().getClassLoader()); ClassLoader previous = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); try { given().port(tomcat.getPort()).accept("application/json") .filter(documentationConfiguration(this.restDocumentation)) .filter(document("custom-snippet-template")).get("/").then() .statusCode(200); } finally { Thread.currentThread().setContextClassLoader(previous); } assertThat(new File( "build/generated-snippets/custom-snippet-template/curl-request.adoc")) .hasContent("Custom curl request"); }
@Test public void customSnippetTemplate() throws Exception { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context) .apply(documentationConfiguration(this.restDocumentation)).build(); ClassLoader classLoader = new URLClassLoader(new URL[] { new File("src/test/resources/custom-snippet-templates").toURI().toURL() }, getClass().getClassLoader()); ClassLoader previous = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); try { mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(document("custom-snippet-template")); } finally { Thread.currentThread().setContextClassLoader(previous); } assertThat(new File( "build/generated-snippets/custom-snippet-template/curl-request.adoc")) .hasContent("Custom curl request"); }
@Test public void testConfProtocolSouldReturnConfFile() throws Exception { File file = fileSystem.getFile("file://conf/conf.txt"); assertThat(file).hasContent("confcontent"); }
private static void assertGenerated(File basedir, String name) throws IOException { URL expected = getResource(format("basic/%s.txt", name)); name += META_SUFFIX; assertThat(new File(basedir, format("target/classes/its/%s.class", name))).isFile(); assertThat(new File(basedir, format("target/generated-sources/annotations/its/%s.java", name))) .usingCharset(UTF_8).hasContent(asCharSource(expected, UTF_8).read()); } }
@Test public void testConfProtocolSouldReturnConfFile() throws Exception { File file = fileSystem.getFile("file://conf/conf.txt"); assertThat(file).hasContent("confcontent"); }
@Test public void testVarProtocolSouldReturnVarFile() throws Exception { File file = fileSystem.getFile("file://var/var.txt"); assertThat(file).hasContent("varcontent"); }
@Test public void testVarProtocolSouldReturnVarFile() throws Exception { File file = fileSystem.getFile("file://var/var.txt"); assertThat(file).hasContent("varcontent"); }
@Test public void writesContentToFile() throws IOException { // arrange File output = temporaryFolder.newFolder("reports") .toPath() .resolve("output.txt") .toFile(); // act fileWriter.writeTo(output.getPath(), "test"); // assert assertThat(output) .hasContent("test") .hasExtension("txt") .hasParent(resolvePath("reports")); }
@Test public void should_move_recording_video() throws IOException, NoSuchMethodException { final File destination = temporaryFolder.newFolder("destination"); final File video = temporaryFolder.newFile("file.flv"); Files.write(video.toPath(), "Hello".getBytes()); when(seleniumContainers.getVideoRecordingFile()).thenReturn(video.toPath()); when(after.getTestClass()).thenReturn(new TestClass(VncRecorderLifecycleManagerTest.class)); when(after.getTestMethod()).thenReturn( VncRecorderLifecycleManagerTest.class.getMethod("should_move_recording_video")); Map<String, String> conf = new HashMap<>(); conf.put("videoOutput", destination.getAbsolutePath()); TestResult testResult = TestResult.passed(); VncRecorderLifecycleManager vncRecorderLifecycleManager = new VncRecorderLifecycleManager(); vncRecorderLifecycleManager.vnc = cube; vncRecorderLifecycleManager.afterVideoRecordedEvent = event; vncRecorderLifecycleManager.stopRecording(after, testResult, CubeDroneConfiguration.fromMap(conf), seleniumContainers ); assertThat(new File(destination, "org_arquillian_cube_docker_drone_VncRecorderLifecycleManagerTest_should_move_recording_video.flv")) .exists() .hasContent("Hello"); }