Search in sources :

Example 1 with MockResolvableMethodParameter

use of cn.taketoday.web.handler.MockResolvableMethodParameter in project today-framework by TAKETODAY.

the class ParameterResolvingRegistryTests method lookupStrategy.

@Test
void lookupStrategy() throws NoSuchMethodException {
    Method q = getClass().getDeclaredMethod("p", String.class);
    MethodParameter parameter = MethodParameter.forExecutable(q, 0);
    ParameterResolvingStrategy data = registry.findStrategy(new MockResolvableMethodParameter(parameter, "data"));
    assertThat(data).isNull();
    assertThatThrownBy(() -> registry.obtainStrategy(new MockResolvableMethodParameter(parameter, "data"))).isInstanceOf(ParameterResolverNotFoundException.class).hasMessageStartingWith("There isn't have a parameter resolver to resolve parameter");
    AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext(Object.class);
    context.setServletContext(new MockServletContext());
    registry.setApplicationContext(context);
    registry.registerDefaultStrategies();
    registry.trimToSize();
    registry.setRedirectModelManager(null);
    assertThat(registry.getRedirectModelManager()).isNull();
    data = registry.findStrategy(new MockResolvableMethodParameter(parameter, "data"));
    assertThat(data).isNotNull().isEqualTo(registry.obtainStrategy(new MockResolvableMethodParameter(parameter, "data"))).isInstanceOf(ConverterAwareParameterResolver.class);
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext) Method(java.lang.reflect.Method) MockResolvableMethodParameter(cn.taketoday.web.handler.MockResolvableMethodParameter) MethodParameter(cn.taketoday.core.MethodParameter) MockResolvableMethodParameter(cn.taketoday.web.handler.MockResolvableMethodParameter) MockServletContext(cn.taketoday.web.testfixture.servlet.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 2 with MockResolvableMethodParameter

use of cn.taketoday.web.handler.MockResolvableMethodParameter in project today-infrastructure by TAKETODAY.

the class ParameterResolvingRegistryTests method lookupStrategy.

@Test
void lookupStrategy() throws NoSuchMethodException {
    Method q = getClass().getDeclaredMethod("p", String.class);
    MethodParameter parameter = MethodParameter.forExecutable(q, 0);
    ParameterResolvingStrategy data = registry.findStrategy(new MockResolvableMethodParameter(parameter, "data"));
    assertThat(data).isNull();
    assertThatThrownBy(() -> registry.obtainStrategy(new MockResolvableMethodParameter(parameter, "data"))).isInstanceOf(ParameterResolverNotFoundException.class).hasMessageStartingWith("There isn't have a parameter resolver to resolve parameter");
    AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext(Object.class);
    context.setServletContext(new MockServletContext());
    registry.setApplicationContext(context);
    registry.registerDefaultStrategies();
    registry.trimToSize();
    registry.setRedirectModelManager(null);
    assertThat(registry.getRedirectModelManager()).isNull();
    data = registry.findStrategy(new MockResolvableMethodParameter(parameter, "data"));
    assertThat(data).isNotNull().isEqualTo(registry.obtainStrategy(new MockResolvableMethodParameter(parameter, "data"))).isInstanceOf(ConverterAwareParameterResolver.class);
}
Also used : AnnotationConfigServletWebApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext) Method(java.lang.reflect.Method) MockResolvableMethodParameter(cn.taketoday.web.handler.MockResolvableMethodParameter) MethodParameter(cn.taketoday.core.MethodParameter) MockResolvableMethodParameter(cn.taketoday.web.handler.MockResolvableMethodParameter) MockServletContext(cn.taketoday.web.mock.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

MethodParameter (cn.taketoday.core.MethodParameter)2 AnnotationConfigServletWebApplicationContext (cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebApplicationContext)2 MockResolvableMethodParameter (cn.taketoday.web.handler.MockResolvableMethodParameter)2 Method (java.lang.reflect.Method)2 Test (org.junit.jupiter.api.Test)2 MockServletContext (cn.taketoday.web.mock.MockServletContext)1 MockServletContext (cn.taketoday.web.testfixture.servlet.MockServletContext)1