Search in sources :

Example 1 with ResponseCodeView

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

the class ArtifactsControllerIntegrationTest method shouldReturn404WhenFileNotFound.

@Test
public void shouldReturn404WhenFileNotFound() throws Exception {
    ModelAndView mav = getFileAsHtml("/foo.xml");
    assertThat(mav.getView().getContentType(), is(RESPONSE_CHARSET));
    assertThat(mav.getView(), is(instanceOf((ResponseCodeView.class))));
    assertThat(((ResponseCodeView) mav.getView()).getContent(), containsString("Artifact '/foo.xml' is unavailable as it may have been purged by Go or deleted externally."));
}
Also used : ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) ModelAndView(org.springframework.web.servlet.ModelAndView) Test(org.junit.Test)

Example 2 with ResponseCodeView

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

the class ArtifactsControllerTest method shouldReturnBadRequestIfRequiredHeadersAreMissingOnACreateArtifactRequest.

@Test
public void shouldReturnBadRequestIfRequiredHeadersAreMissingOnACreateArtifactRequest() throws Exception {
    MultipartHttpServletRequest multipartHttpServletRequest = new MockMultipartHttpServletRequest();
    when(systemEnvironment.isApiSafeModeEnabled()).thenReturn(true);
    ModelAndView modelAndView = artifactsController.postArtifact("pipeline", "invalid-label", "stage", "stage-counter", "job-name", 3L, "file-path", 3, multipartHttpServletRequest);
    ResponseCodeView codeView = (ResponseCodeView) modelAndView.getView();
    assertThat(codeView.getStatusCode(), is(HttpServletResponse.SC_BAD_REQUEST));
    assertThat(codeView.getContent(), is("Missing required header 'Confirm'"));
}
Also used : MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) ModelAndView(org.springframework.web.servlet.ModelAndView) MockMultipartHttpServletRequest(org.springframework.mock.web.MockMultipartHttpServletRequest) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) Test(org.junit.Test)

Example 3 with ResponseCodeView

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

the class StageControllerIntegrationTest method shouldReturnBadRequestIfRequiredHeadersAreMissing.

@Test
public void shouldReturnBadRequestIfRequiredHeadersAreMissing() {
    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
    mockHttpServletRequest.addHeader("Confirm", "false");
    ModelAndView modelAndView = controller.rerunStage("pipeline", "invalid-label", "stage", response, mockHttpServletRequest);
    ResponseCodeView codeView = (ResponseCodeView) modelAndView.getView();
    assertThat(codeView.getStatusCode(), is(HttpServletResponse.SC_BAD_REQUEST));
    assertThat(codeView.getContent(), is("Missing required header 'Confirm'"));
}
Also used : ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) Test(org.junit.Test)

Example 4 with ResponseCodeView

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

the class StageControllerIntegrationTest method shouldReturn404WhenReRunningNonExistantStage.

@Test
public void shouldReturn404WhenReRunningNonExistantStage() throws Exception {
    Pipeline pipeline = fixture.createPipelineWithFirstStagePassedAndSecondStageHasNotStarted();
    ModelAndView mav = controller.rerunStage(fixture.pipelineName, pipeline.getLabel(), "doesNotExist", response, request);
    ResponseCodeView codeView = (ResponseCodeView) mav.getView();
    assertThat(codeView.getStatusCode(), is(HttpServletResponse.SC_NOT_FOUND));
    assertThat(codeView.getContent(), is("Stage 'doesNotExist' not found in pipeline '" + fixture.pipelineName + "'"));
}
Also used : ResponseCodeView(com.thoughtworks.go.server.web.ResponseCodeView) ModelAndView(org.springframework.web.servlet.ModelAndView) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Example 5 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();
    int startLineNumber = 0;
    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)7 Test (org.junit.Test)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 MockMultipartHttpServletRequest (org.springframework.mock.web.MockMultipartHttpServletRequest)2 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)1 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