Search in sources :

Example 1 with StubMultipartHttpServletRequest

use of com.thoughtworks.go.helper.StubMultipartHttpServletRequest in project gocd by gocd.

the class ArtifactsControllerIntegrationTest method shouldSaveChecksumFileInTheCruiseOutputFolder.

@Test
public void shouldSaveChecksumFileInTheCruiseOutputFolder() throws Exception {
    File fooFile = createFile(artifactsRoot, "/tmp/foobar.html");
    FileUtils.writeStringToFile(fooFile, "FooBarBaz...");
    File checksumFile = createFile(artifactsRoot, "/tmp/foobar.html.checksum");
    FileUtils.writeStringToFile(checksumFile, "baz/foobar.html:FooMD5\n");
    MockMultipartFile artifactMultipart = new MockMultipartFile("file", new FileInputStream(fooFile));
    MockMultipartFile checksumMultipart = new MockMultipartFile("file_checksum", new FileInputStream(checksumFile));
    request.addHeader("Confirm", "true");
    StubMultipartHttpServletRequest multipartRequest = new StubMultipartHttpServletRequest(request, artifactMultipart, checksumMultipart);
    postFileWithChecksum("baz/foobar.html", multipartRequest);
    assertThat(file(artifactsRoot, "baz/foobar.html"), exists());
    File uploadedChecksumFile = file(artifactsRoot, "cruise-output/md5.checksum");
    assertThat(uploadedChecksumFile, exists());
    assertThat(FileUtils.readLines(uploadedChecksumFile).get(0).toString(), is("baz/foobar.html:FooMD5"));
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) StubMultipartHttpServletRequest(com.thoughtworks.go.helper.StubMultipartHttpServletRequest) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Test(org.junit.Test)

Example 2 with StubMultipartHttpServletRequest

use of com.thoughtworks.go.helper.StubMultipartHttpServletRequest in project gocd by gocd.

the class ArtifactsControllerIntegrationTest method shouldAppendChecksumInTheCruiseOutputFolder.

@Test
public void shouldAppendChecksumInTheCruiseOutputFolder() throws Exception {
    File fooFile = createFileWithContent(artifactsRoot, "/tmp/foobar.html", "FooBarBaz...");
    createFileWithContent(artifactsRoot, "cruise-output/md5.checksum", "oldbaz/foobar.html:BazMD5\n");
    File checksumFile = createFileWithContent(artifactsRoot, "/tmp/foobar.html.checksum", "baz/foobar.html:FooMD5\n");
    MockMultipartFile artifactMultipart = new MockMultipartFile("file", new FileInputStream(fooFile));
    MockMultipartFile checksumMultipart = new MockMultipartFile("file_checksum", new FileInputStream(checksumFile));
    request.addHeader("Confirm", "true");
    StubMultipartHttpServletRequest multipartRequest = new StubMultipartHttpServletRequest(request, artifactMultipart, checksumMultipart);
    postFileWithChecksum("baz/foobar.html", multipartRequest);
    assertThat(file(artifactsRoot, "baz/foobar.html"), exists());
    File uploadedChecksumFile = file(artifactsRoot, "cruise-output/md5.checksum");
    assertThat(uploadedChecksumFile, exists());
    List list = FileUtils.readLines(uploadedChecksumFile);
    assertThat(list.size(), is(2));
    assertThat(list.get(0).toString(), is("oldbaz/foobar.html:BazMD5"));
    assertThat(list.get(1).toString(), is("baz/foobar.html:FooMD5"));
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) StubMultipartHttpServletRequest(com.thoughtworks.go.helper.StubMultipartHttpServletRequest) List(java.util.List) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Test(org.junit.Test)

Example 3 with StubMultipartHttpServletRequest

use of com.thoughtworks.go.helper.StubMultipartHttpServletRequest in project gocd by gocd.

the class ArtifactsControllerIntegrationTest method shouldReturn404WhenNoLatestBuildForPost.

@Test
public void shouldReturn404WhenNoLatestBuildForPost() throws Exception {
    request.addHeader("Confirm", "true");
    StubMultipartHttpServletRequest multipartRequest = new StubMultipartHttpServletRequest(request);
    ModelAndView mav = artifactsController.postArtifact(pipelineName, "latest", "stage", "1", "build2", null, "/foo.xml", 1, multipartRequest);
    assertValidContentAndStatus(mav, SC_NOT_FOUND, "Job " + pipelineName + "/latest/stage/1/build2 not found.");
}
Also used : StubMultipartHttpServletRequest(com.thoughtworks.go.helper.StubMultipartHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) Test(org.junit.Test)

Example 4 with StubMultipartHttpServletRequest

use of com.thoughtworks.go.helper.StubMultipartHttpServletRequest in project gocd by gocd.

the class ArtifactsControllerIntegrationTest method postFile.

private ModelAndView postFile(String requestFilename, String multipartFilename, InputStream stream, MockHttpServletResponse response) throws Exception {
    MockMultipartFile multipartFile = new MockMultipartFile(multipartFilename, stream);
    request.addHeader("Confirm", "true");
    StubMultipartHttpServletRequest multipartRequest = new StubMultipartHttpServletRequest(request, multipartFile);
    return artifactsController.postArtifact(pipelineName, pipeline.getLabel(), "stage", "LATEST", "build", buildId, requestFilename, null, multipartRequest);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) StubMultipartHttpServletRequest(com.thoughtworks.go.helper.StubMultipartHttpServletRequest)

Aggregations

StubMultipartHttpServletRequest (com.thoughtworks.go.helper.StubMultipartHttpServletRequest)4 Test (org.junit.Test)3 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)3 List (java.util.List)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1