use of cn.taketoday.core.DefaultParameterNameDiscoverer in project today-framework by TAKETODAY.
the class HandlerMethodTests method testSimple.
@Test
public void testSimple() throws Throwable {
final Method method = HandlerMethodTests.class.getDeclaredMethod("method", String.class);
final HandlerMethod handlerMethod = HandlerMethod.from(method);
DefaultParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
handlerMethod.initParameterNameDiscovery(parameterNameDiscoverer);
assertThat(handlerMethod.getMethod()).isEqualTo(method);
assertThat(handlerMethod.getParameters()).hasSize(1);
assertThat(handlerMethod.getReturnType()).isEqualTo(method.getReturnType()).isEqualTo(void.class);
assertThat(handlerMethod.getContentType()).isNull();
// produce
final Method produce = HandlerMethodTests.class.getDeclaredMethod("produce", String.class);
final HandlerMethod produceMethod = HandlerMethod.from(produce);
assertThat(produceMethod.getContentType()).isEqualTo(MediaType.APPLICATION_JSON_VALUE);
produceMethod.initParameterNameDiscovery(parameterNameDiscoverer);
ApplicationContext applicationContext = getApplicationContext();
final ParameterResolvingRegistryResolvableParameterFactory methodParameterBuilder = new ParameterResolvingRegistryResolvableParameterFactory();
final ParameterResolvingRegistry resolversRegistry = methodParameterBuilder.getResolvingRegistry();
resolversRegistry.setApplicationContext(applicationContext);
resolversRegistry.registerDefaultStrategies();
setResultHandlers(produceMethod, applicationContext);
assertThat(produceMethod).isNotEqualTo(handlerMethod);
assertThat(produceMethod).hasToString("HandlerMethodTests#produce(String name)");
}
use of cn.taketoday.core.DefaultParameterNameDiscoverer in project today-framework by TAKETODAY.
the class ExpressionValueMethodArgumentResolverTests method setUp.
@BeforeEach
@SuppressWarnings("resource")
public void setUp() throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.refresh();
resolver = new ExpressionValueMethodArgumentResolver(context.getBeanFactory());
DefaultParameterNameDiscoverer discoverer = new DefaultParameterNameDiscoverer();
Method method = getClass().getMethod("params", int.class, String.class, String.class);
paramSystemProperty = new ResolvableMethodParameter(new MethodParameter(method, 0));
paramContextPath = new ResolvableMethodParameter(new MethodParameter(method, 1));
paramNotSupported = new ResolvableMethodParameter(new MethodParameter(method, 2));
paramSystemProperty.getParameter().initParameterNameDiscovery(discoverer);
paramContextPath.getParameter().initParameterNameDiscovery(discoverer);
paramNotSupported.getParameter().initParameterNameDiscovery(discoverer);
webRequest = new ServletRequestContext(null, request, new MockHttpServletResponse());
// Expose request to the current thread (for SpEL expressions)
RequestContextHolder.set(webRequest);
}
Aggregations