Search in sources :

Example 76 with HandlerMethod

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

the class ModelFactoryTests method modelAttributeWithBindingDisabled.

@Test
public void modelAttributeWithBindingDisabled() throws Exception {
    ModelFactory modelFactory = createModelFactory("modelAttrWithBindingDisabled");
    HandlerMethod handlerMethod = createHandlerMethod("handle");
    modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
    assertTrue(this.mavContainer.containsAttribute("foo"));
    assertTrue(this.mavContainer.isBindingDisabled("foo"));
}
Also used : InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 77 with HandlerMethod

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

the class ModelFactoryTests method sessionAttribute.

@Test
public void sessionAttribute() throws Exception {
    this.attributeStore.storeAttribute(this.webRequest, "sessionAttr", "sessionAttrValue");
    ModelFactory modelFactory = createModelFactory("modelAttr", Model.class);
    HandlerMethod handlerMethod = createHandlerMethod("handle");
    modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
    assertEquals("sessionAttrValue", this.mavContainer.getModel().get("sessionAttr"));
}
Also used : InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 78 with HandlerMethod

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

the class ModelFactoryTests method modelAttributeFromSessionWithBindingDisabled.

@Test
public void modelAttributeFromSessionWithBindingDisabled() throws Exception {
    Foo foo = new Foo();
    this.attributeStore.storeAttribute(this.webRequest, "foo", foo);
    ModelFactory modelFactory = createModelFactory("modelAttrWithBindingDisabled");
    HandlerMethod handlerMethod = createHandlerMethod("handle");
    modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
    assertTrue(this.mavContainer.containsAttribute("foo"));
    assertSame(foo, this.mavContainer.getModel().get("foo"));
    assertTrue(this.mavContainer.isBindingDisabled("foo"));
}
Also used : InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 79 with HandlerMethod

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

the class ModelFactoryTests method modelAttributeMethodWithNameByConvention.

@Test
public void modelAttributeMethodWithNameByConvention() throws Exception {
    ModelFactory modelFactory = createModelFactory("modelAttrConvention");
    HandlerMethod handlerMethod = createHandlerMethod("handle");
    modelFactory.initModel(this.webRequest, this.mavContainer, handlerMethod);
    assertEquals(Boolean.TRUE, this.mavContainer.getModel().get("boolean"));
}
Also used : InvocableHandlerMethod(org.springframework.web.method.support.InvocableHandlerMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Example 80 with HandlerMethod

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

the class RequestMappingInfoHandlerMappingTests method getHandlerBestMatch.

@Test
public void getHandlerBestMatch() throws Exception {
    Method expected = on(TestController.class).annot(getMapping("/foo").params("p")).resolveMethod();
    ServerWebExchange exchange = get("/foo?p=anything").toExchange();
    HandlerMethod hm = (HandlerMethod) this.handlerMapping.getHandler(exchange).block();
    assertEquals(expected, hm.getMethod());
}
Also used : ServerWebExchange(org.springframework.web.server.ServerWebExchange) HandlerMethod(org.springframework.web.method.HandlerMethod) Method(java.lang.reflect.Method) HttpMethod(org.springframework.http.HttpMethod) HandlerMethod(org.springframework.web.method.HandlerMethod) Test(org.junit.Test)

Aggregations

HandlerMethod (org.springframework.web.method.HandlerMethod)131 Test (org.junit.Test)81 Method (java.lang.reflect.Method)42 InvocableHandlerMethod (org.springframework.web.method.support.InvocableHandlerMethod)34 ArrayList (java.util.ArrayList)26 ModelAndView (org.springframework.web.servlet.ModelAndView)24 MethodParameter (org.springframework.core.MethodParameter)20 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)19 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)19 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)18 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)18 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)16 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)16 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)16 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)13 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)8 HttpMethod (org.springframework.http.HttpMethod)7 ServerWebExchange (org.springframework.web.server.ServerWebExchange)7 Map (java.util.Map)6 List (java.util.List)5