Example usage for org.springframework.web.servlet.view AbstractView setBeanName

List of usage examples for org.springframework.web.servlet.view AbstractView setBeanName

Introduction

In this page you can find the example usage for org.springframework.web.servlet.view AbstractView setBeanName.

Prototype

@Override
public void setBeanName(@Nullable String beanName) 

Source Link

Document

Set the view's name.

Usage

From source file:ar.com.zauber.commons.spring.exceptions.HeaderBasedStatusSimpleMappingExceptionHandlerTest.java

/** test */
public final void testFoo() {
    final Properties views = new Properties();
    views.put(NotOwnerException.class.getName(), "notowner");
    views.put(IllegalArgumentException.class.getName(), "arguments");
    views.put(DataAccessResourceFailureException.class.getName(), "data");

    final Properties status = new Properties();
    status.put("arguments", "400");
    status.put("notowner", "403");
    status.put("data", "500");

    AbstractView view = new AbstractView() {
        @Override//from  w w  w . j a va 2  s  . co  m
        protected void renderMergedOutputModel(final Map<String, Object> model,
                final HttpServletRequest request, final HttpServletResponse response) throws Exception {
        }
    };
    view.setBeanName("test");
    final HeaderBasedStatusSimpleMappingExceptionHandler h = new HeaderBasedStatusSimpleMappingExceptionHandler(
            view, "application/json");

    h.setDefaultStatusCode(200);
    h.setExceptionMappings(views);
    h.setStatusMappings(status);
    h.setDefaultErrorView("default");

    MockHttpServletResponse response;
    ModelAndView v;

    response = new MockHttpServletResponse();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("Accept", "application/json");

    v = h.resolveException(request, response, null, new IllegalArgumentException("io!io!"));
    assertEquals(view, v.getView());
    assertEquals(400, response.getStatus());
}