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