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));
}
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);
}
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);
}
Aggregations