Search in sources :

Example 6 with FileUtils.readFileToString

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

the class GoFileConfigDataSourceIntegrationTest method shouldLoadAsUser_Filesystem_WithMd5Sum.

@Test
public void shouldLoadAsUser_Filesystem_WithMd5Sum() throws Exception {
    GoConfigHolder configHolder = goConfigDao.loadConfigHolder();
    String md5 = DigestUtils.md5Hex(FileUtils.readFileToString(dataSource.fileLocation(), UTF_8));
    assertThat(configHolder.configForEdit.getMd5(), is(md5));
    assertThat(configHolder.config.getMd5(), is(md5));
    CruiseConfig forEdit = configHolder.configForEdit;
    forEdit.addPipeline("my-awesome-group", PipelineConfigMother.createPipelineConfig("pipeline-foo", "stage-bar", "job-baz"));
    FileOutputStream fos = new FileOutputStream(dataSource.fileLocation());
    new MagicalGoConfigXmlWriter(configCache, ConfigElementImplementationRegistryMother.withNoPlugins()).write(forEdit, fos, false);
    configHolder = dataSource.load();
    String xmlText = FileUtils.readFileToString(dataSource.fileLocation(), UTF_8);
    String secondMd5 = DigestUtils.md5Hex(xmlText);
    assertThat(configHolder.configForEdit.getMd5(), is(secondMd5));
    assertThat(configHolder.config.getMd5(), is(secondMd5));
    assertThat(configHolder.configForEdit.getMd5(), is(not(md5)));
    GoConfigRevision commitedVersion = configRepository.getRevision(secondMd5);
    assertThat(commitedVersion.getContent(), is(xmlText));
    assertThat(commitedVersion.getUsername(), is(GoFileConfigDataSource.FILESYSTEM));
}
Also used : FileOutputStream(java.io.FileOutputStream) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) GoConfigRevision(com.thoughtworks.go.domain.GoConfigRevision) Test(org.junit.jupiter.api.Test)

Example 7 with FileUtils.readFileToString

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

the class ArtifactsControllerIntegrationTest method shouldPutConsoleOutput_withoutNewLineChar.

@Test
public void shouldPutConsoleOutput_withoutNewLineChar() throws Exception {
    String log = "....";
    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(1));
    assertThat(lines[0], 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 8 with FileUtils.readFileToString

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

the class ArtifactsControllerIntegrationTest method shouldPutConsoleOutput_whenContentMoreThanBufferSizeUsed.

@Test
public void shouldPutConsoleOutput_whenContentMoreThanBufferSizeUsed() throws Exception {
    StringBuilder builder = new StringBuilder();
    String str = "This is one full line of text. With 2 sentences without newline separating them.\n";
    int numberOfLines = ConsoleService.DEFAULT_CONSOLE_LOG_LINE_BUFFER_SIZE / 10;
    for (int i = 0; i < numberOfLines; i++) {
        builder.append(str);
    }
    for (int i = 0; i < numberOfLines; i++) {
        builder.append(str);
    }
    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(2 * numberOfLines));
    String hundredThLine = null;
    for (int i = 0; i < lines.length; i++) {
        String line = lines[i];
        if (i == numberOfLines) {
            hundredThLine = line;
        } else {
            assertThat("Line " + i + " doesn't have desired content.", line + "\n", is(str));
        }
    }
    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)

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