Search in sources :

Example 1 with HttpSessionRequiredException

use of org.springframework.web.HttpSessionRequiredException in project spring-framework by spring-projects.

the class ModelFactoryTests method sessionAttributeNotPresent.

@Test
public void sessionAttributeNotPresent() throws Exception {
    ModelFactory modelFactory = new ModelFactory(null, null, this.attributeHandler);
    HandlerMethod handlerMethod = createHandlerMethod("handleSessionAttr", String.class);
    try {
        modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
        fail("Expected HttpSessionRequiredException");
    } catch (HttpSessionRequiredException e) {
    // expected
    }
    // Now add attribute and try again
    this.attributeStore.storeAttribute(this.webRequest, "sessionAttr", "sessionAttrValue");
    modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
    assertEquals("sessionAttrValue", this.mavContainer.getModel().get("sessionAttr"));
}
Also used : HttpSessionRequiredException(org.springframework.web.HttpSessionRequiredException) InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 HttpSessionRequiredException (org.springframework.web.HttpSessionRequiredException)1 HandlerMethod (org.springframework.web.method.HandlerMethod)1 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)1