Search in sources :

Example 6 with ResponseCodeView

use of com.thoughtworks.go.server.web.ResponseCodeView in project gocd by gocd.

the class ArtifactsControllerTest method shouldReturnHttpErrorCodeWhenChecksumFileSaveFails.

@Test
public void shouldReturnHttpErrorCodeWhenChecksumFileSaveFails() throws Exception {
    File artifactFile = new File("junk");
    when(artifactService.findArtifact(any(JobIdentifier.class), eq("some-path"))).thenReturn(artifactFile);
    when(artifactService.saveFile(any(File.class), any(InputStream.class), eq(false), eq(1))).thenReturn(true);
    when(artifactService.saveOrAppendFile(any(File.class), any(InputStream.class))).thenReturn(false);
    MockMultipartHttpServletRequest mockMultipartHttpServletRequest = new MockMultipartHttpServletRequest();
    mockMultipartHttpServletRequest.addFile(new MockMultipartFile(REGULAR_MULTIPART_FILENAME, "content".getBytes()));
    mockMultipartHttpServletRequest.addFile(new MockMultipartFile(CHECKSUM_MULTIPART_FILENAME, "checksum-content".getBytes()));
    ModelAndView modelAndView = artifactsController.postArtifact("pipeline-1", "1", "stage-1", "2", "job-1", 122L, "some-path", 1, mockMultipartHttpServletRequest);
    ResponseCodeView view = (ResponseCodeView) modelAndView.getView();
    assertThat(view.getStatusCode(), is(SC_INTERNAL_SERVER_ERROR));
    assertThat(view.getContent(), is("Error saving checksum file for the artifact at path 'some-path'"));
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) InputStream(java.io.InputStream) ModelAndView(org.springframework.web.servlet.ModelAndView) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) File(java.io.File) Test(org.junit.Test)

Example 7 with ResponseCodeView

use of com.thoughtworks.go.server.web.ResponseCodeView in project gocd by gocd.

the class StageControllerIntegrationTest method shouldGiveFriendlyErrorMessageForRerun.

@Test
public void shouldGiveFriendlyErrorMessageForRerun() {
    ModelAndView modelAndView = controller.rerunStage("pipeline", "invalid-label", "stage", response, request);
    ResponseCodeView codeView = (ResponseCodeView) modelAndView.getView();
    assertThat(codeView.getStatusCode(), is(HttpServletResponse.SC_BAD_REQUEST));
    assertThat(codeView.getContent(), is("Stage [pipeline/invalid-label/stage] not found"));
}
Also used : ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) ModelAndView(org.springframework.web.servlet.ModelAndView) Test(org.junit.Test)

Example 8 with ResponseCodeView

use of com.thoughtworks.go.server.web.ResponseCodeView in project gocd by gocd.

the class ArtifactsControllerIntegrationTest method testConsoleOutShouldReturn404WhenJobIsNotFound.

@Test
public void testConsoleOutShouldReturn404WhenJobIsNotFound() throws Exception {
    prepareConsoleOut("");
    Stage firstStage = pipeline.getFirstStage();
    long startLineNumber = 0L;
    ModelAndView view = artifactsController.consoleout("snafu", "snafu", "snafu", "build", String.valueOf(firstStage.getCounter()), startLineNumber);
    assertThat(view.getView().getContentType(), is(RESPONSE_CHARSET));
    assertThat(view.getView(), is(instanceOf((ResponseCodeView.class))));
    assertThat(((ResponseCodeView) view.getView()).getContent(), containsString("Job snafu/snafu/snafu/1/build not found."));
}
Also used : ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) ModelAndView(org.springframework.web.servlet.ModelAndView) Stage(com.thoughtworks.go.domain.Stage) Test(org.junit.Test)

Aggregations

ResponseCodeView (com.thoughtworks.go.server.web.ResponseCodeView)8 Test (org.junit.Test)8 ModelAndView (org.springframework.web.servlet.ModelAndView)8 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)2 MockMultipartHttpServletRequest (org.springframework.mock.web.MockMultipartHttpServletRequest)2 Pipeline (com.thoughtworks.go.domain.Pipeline)1 Stage (com.thoughtworks.go.domain.Stage)1 File (java.io.File)1 InputStream (java.io.InputStream)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)1 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)1