Search in sources :

Example 1 with FileUtils.readFileToString

use of org.apache.commons.io.FileUtils.readFileToString in project gocd by gocd.

the class ArtifactsControllerIntegrationTest method shouldPutConsoleOutput_withNoNewLineAtTheAtOfTheLog.

@Test
public void shouldPutConsoleOutput_withNoNewLineAtTheAtOfTheLog() throws Exception {
    String log = "junit report\nstart\n....";
    ModelAndView mav = putConsoleLogContent("cruise-output/console.log", log);
    String consoleLogContent = FileUtils.readFileToString(file(consoleLogFile), UTF_8);
    String[] lines = consoleLogContent.split("\n");
    assertThat(lines.length, is(3));
    assertThat(lines[0], is("junit report"));
    assertThat(lines[1], is("start"));
    assertThat(lines[2], is("...."));
    assertStatus(mav, SC_OK);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) Test(org.junit.jupiter.api.Test)

Example 2 with FileUtils.readFileToString

use of org.apache.commons.io.FileUtils.readFileToString in project gocd by gocd.

the class ArtifactsControllerIntegrationTest method shouldPutConsoleLogAsArtifact.

@Test
public void shouldPutConsoleLogAsArtifact() throws Exception {
    request.addHeader("Confirm", "true");
    String consoleLogContent = "Job output";
    request.setContent(consoleLogContent.getBytes());
    ModelAndView modelAndView = artifactsController.putArtifact(pipelineName.toUpperCase(), Integer.toString(pipeline.getCounter()), stage.getName().toUpperCase(), Integer.toString(stage.getCounter()), job.getName().toUpperCase(), buildId, "cruise-output/console.log", null, request);
    String md5Hex = DigestUtils.md5Hex(String.format("%s/1/stage/1/build", pipelineName));
    String path = new File("data/console/", String.format("%s.log", md5Hex)).getPath();
    assertValidContentAndStatus(modelAndView, SC_OK, String.format("File %s was appended successfully", path));
    JobIdentifier jobIdentifier = new JobIdentifier(pipelineName, pipeline.getCounter(), null, stage.getName(), Integer.toString(stage.getCounter()), job.getName(), job.getId());
    assertTrue(consoleService.doesLogExist(jobIdentifier));
    File consoleLogFile = consoleService.consoleLogFile(jobIdentifier);
    assertThat(FileUtils.readFileToString(consoleLogFile, "utf-8"), is(consoleLogContent));
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Test(org.junit.jupiter.api.Test)

Example 3 with FileUtils.readFileToString

use of org.apache.commons.io.FileUtils.readFileToString in project gocd by gocd.

the class ArtifactsControllerIntegrationTest method shouldPutArtifact.

@Test
public void shouldPutArtifact() throws Exception {
    request.addHeader("Confirm", "true");
    String artifactFileContent = "FooBarBaz...";
    request.setContent(artifactFileContent.getBytes());
    String filePath = "baz/foobar.html";
    ModelAndView modelAndView = artifactsController.putArtifact(pipelineName.toUpperCase(), Integer.toString(pipeline.getCounter()), stage.getName().toUpperCase(), Integer.toString(stage.getCounter()), job.getName().toUpperCase(), buildId, filePath, null, request);
    assertValidContentAndStatus(modelAndView, SC_OK, String.format("File %s was appended successfully", filePath));
    JobIdentifier jobIdentifier = new JobIdentifier(pipelineName, pipeline.getCounter(), null, stage.getName(), Integer.toString(stage.getCounter()), job.getName(), job.getId());
    File artifact = artifactService.findArtifact(jobIdentifier, filePath);
    assertThat(FileUtils.readFileToString(artifact, "utf-8"), is(artifactFileContent));
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Test(org.junit.jupiter.api.Test)

Example 4 with FileUtils.readFileToString

use of org.apache.commons.io.FileUtils.readFileToString in project gocd by gocd.

the class ArtifactsControllerIntegrationTest method shouldPutConsoleOutput_withHugeSingleLine.

@Test
public void shouldPutConsoleOutput_withHugeSingleLine() throws Exception {
    StringBuilder builder = new StringBuilder();
    String str = "a ";
    int numberOfChars = ConsoleService.DEFAULT_CONSOLE_LOG_LINE_BUFFER_SIZE * 4;
    StringBuilder longLine = new StringBuilder();
    for (int i = 0; i < numberOfChars; i++) {
        longLine.append(str);
    }
    String longLineStr = longLine.toString();
    builder.append(longLineStr);
    builder.append("\nTesting:\n");
    builder.append(longLineStr);
    ModelAndView mav = putConsoleLogContent("cruise-output/console.log", builder.toString());
    String consoleLogContent = FileUtils.readFileToString(file(consoleLogFile), UTF_8);
    String[] lines = consoleLogContent.split("\n");
    assertThat(lines.length, is(3));
    assertThat(lines[0], is(longLineStr));
    assertThat(lines[1] + "\n", is("Testing:\n"));
    assertThat(lines[2], is(longLineStr));
    assertStatus(mav, SC_OK);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) Test(org.junit.jupiter.api.Test)

Example 5 with FileUtils.readFileToString

use of org.apache.commons.io.FileUtils.readFileToString in project gocd by gocd.

the class GoFileConfigDataSourceIntegrationTest method shouldNotCorruptTheCruiseConfigXml.

@Test
public void shouldNotCorruptTheCruiseConfigXml() throws Exception {
    File file = dataSource.fileLocation();
    String originalCopy = FileUtils.readFileToString(file, UTF_8);
    try {
        dataSource.write("abc", false);
        fail("Should not allow us to write an invalid config");
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("Content is not allowed in prolog"));
    }
    assertThat(readFileToString(file, UTF_8), is(originalCopy));
}
Also used : FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) File(java.io.File) ConfigFileHasChangedException(com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException) GoConfigInvalidException(com.thoughtworks.go.config.exceptions.GoConfigInvalidException) ConfigMergeException(com.thoughtworks.go.config.exceptions.ConfigMergeException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

FileUtils.readFileToString (org.apache.commons.io.FileUtils.readFileToString)8 Test (org.junit.jupiter.api.Test)8 ModelAndView (org.springframework.web.servlet.ModelAndView)6 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)2 ConfigFileHasChangedException (com.thoughtworks.go.config.exceptions.ConfigFileHasChangedException)1 ConfigMergeException (com.thoughtworks.go.config.exceptions.ConfigMergeException)1 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)1 GoConfigRevision (com.thoughtworks.go.domain.GoConfigRevision)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1