Example usage for org.springframework.web.servlet ModelAndView getView

List of usage examples for org.springframework.web.servlet ModelAndView getView

Introduction

In this page you can find the example usage for org.springframework.web.servlet ModelAndView getView.

Prototype

@Nullable
public View getView() 

Source Link

Document

Return the View object, or null if we are using a view name to be resolved by the DispatcherServlet via a ViewResolver.

Usage

From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java

@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."));
}

From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java

@Test
public void shouldReturnFolderInJsonView() throws Exception {
    createFile(artifactsRoot, "foo/bar.xml");

    ModelAndView mav = getFolderAsJson("/foo");
    assertEquals(RESPONSE_CHARSET_JSON, mav.getView().getContentType());
}

From source file:org.jasig.cas.web.NoSuchFlowExecutionExceptionResolverTests.java

public void testNoSuchFlowExecutionException() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    ModelAndView model = (this.resolver.resolveException(request, new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey() {

                private static final long serialVersionUID = 1443616250214416520L;

                public String toString() {
                    return "test";
                }/*w  w w .  j a  va 2s  . c  o  m*/

                @Override
                public boolean equals(Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException())));

    assertEquals(request.getRequestURI(), ((RedirectView) model.getView()).getUrl());
}

From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java

private void assertValidContentAndStatus(ModelAndView mav, int responseCode, String content) {
    assertStatus(mav, responseCode);/* w ww . ja  va2 s .c o m*/
    assertThat(((ResponseCodeView) mav.getView()).getContent(), is(content));
}

From source file:org.jasig.cas.web.FlowExecutionExceptionResolverTests.java

@Test
public void testNoSuchFlowExecutionException() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    ModelAndView model = this.resolver.resolveException(request, new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey() {

                private static final long serialVersionUID = 1443616250214416520L;

                @Override//from  w  w  w .j a va  2  s .c  om
                public String toString() {
                    return "test";
                }

                @Override
                public boolean equals(final Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException()));

    assertEquals(request.getRequestURI(), ((RedirectView) model.getView()).getUrl());
}

From source file:org.jasig.cas.web.NoSuchFlowExecutionExceptionResolverTests.java

public void testNoSuchFlowExecutionExeptionWithQueryString() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    request.setQueryString("test=test");
    ModelAndView model = (this.resolver.resolveException(request, new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey() {

                private static final long serialVersionUID = -4750073902540974152L;

                public String toString() {
                    return "test";
                }/*from w  ww .  j a va  2  s .  c  om*/

                @Override
                public boolean equals(Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException())));

    assertEquals(request.getRequestURI() + "?" + request.getQueryString(),
            ((RedirectView) model.getView()).getUrl());
}

From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java

@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."));
}

From source file:org.jasig.cas.web.FlowExecutionExceptionResolverTests.java

@Test
public void testNoSuchFlowExecutionExeptionWithQueryString() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRequestURI("test");
    request.setQueryString("test=test");
    ModelAndView model = this.resolver.resolveException(request, new MockHttpServletResponse(), null,
            new NoSuchFlowExecutionException(new FlowExecutionKey() {

                private static final long serialVersionUID = -4750073902540974152L;

                @Override//from  w  w  w .  j a  v  a 2 s.  c o m
                public String toString() {
                    return "test";
                }

                @Override
                public boolean equals(final Object o) {
                    return true;
                }

                @Override
                public int hashCode() {
                    return 0;
                }
            }, new RuntimeException()));

    assertEquals(request.getRequestURI() + "?" + request.getQueryString(),
            ((RedirectView) model.getView()).getUrl());
}

From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java

@Test
public void shouldStartAtBeginningWhenNoStartParameterIsGiven() throws Exception {
    String firstLine = "Chris sucks.";
    String secondLine = "Build succeeded.";
    prepareConsoleOut(firstLine + "\n" + secondLine + "\n");
    Stage firstStage = pipeline.getFirstStage();
    ModelAndView view = artifactsController.consoleout(pipeline.getName(), pipeline.getLabel(),
            firstStage.getName(), "build", String.valueOf(firstStage.getCounter()), null);

    assertThat(view.getView(), is(instanceOf(ConsoleOutView.class)));

    HttpServletResponse response = mock(HttpServletResponse.class);
    ResponseOutput output = new ResponseOutput();
    when(response.getWriter()).thenReturn(output.getWriter());
    ConsoleOutView consoleOutView = (ConsoleOutView) view.getView();
    consoleOutView.render(mock(Map.class), mock(HttpServletRequest.class), response);

    assertEquals("Chris sucks.\nBuild succeeded.\n", output.getOutput());
}

From source file:com.thoughtworks.go.server.controller.ArtifactsControllerIntegrationTest.java

@Test
public void shouldReturnBuildOutputAsPlainText() throws Exception {
    String firstLine = "Chris sucks.\n";
    String secondLine = "Build succeeded.";
    prepareConsoleOut(firstLine + secondLine + "\n");
    Stage firstStage = pipeline.getFirstStage();
    long startLineNumber = 1L;
    ModelAndView view = artifactsController.consoleout(pipeline.getName(), pipeline.getLabel(),
            firstStage.getName(), "build", String.valueOf(firstStage.getCounter()), startLineNumber);

    assertThat(view.getView(), is(instanceOf(ConsoleOutView.class)));

    HttpServletResponse response = mock(HttpServletResponse.class);
    ResponseOutput output = new ResponseOutput();
    when(response.getWriter()).thenReturn(output.getWriter());
    ConsoleOutView consoleOutView = (ConsoleOutView) view.getView();
    consoleOutView.render(mock(Map.class), mock(HttpServletRequest.class), response);

    assertEquals("Build succeeded.\n", output.getOutput());
}