use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.
the class CorsAbstractHandlerMappingTests method getCorsConfiguration.
private CorsConfiguration getCorsConfiguration(HandlerExecutionChain chain, boolean isPreFlightRequest) {
if (isPreFlightRequest) {
Object handler = chain.getHandler();
assertTrue(handler.getClass().getSimpleName().equals("PreFlightHandler"));
DirectFieldAccessor accessor = new DirectFieldAccessor(handler);
return (CorsConfiguration) accessor.getPropertyValue("config");
} else {
HandlerInterceptor[] interceptors = chain.getInterceptors();
if (interceptors != null) {
for (HandlerInterceptor interceptor : interceptors) {
if (interceptor.getClass().getSimpleName().equals("CorsInterceptor")) {
DirectFieldAccessor accessor = new DirectFieldAccessor(interceptor);
return (CorsConfiguration) accessor.getPropertyValue("config");
}
}
}
}
return null;
}
use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.
the class ViewResolverRegistryTests method checkPropertyValues.
private void checkPropertyValues(ViewResolver resolver, Object... nameValuePairs) {
DirectFieldAccessor accessor = new DirectFieldAccessor(resolver);
for (int i = 0; i < nameValuePairs.length; i++, i++) {
Object expected = nameValuePairs[i + 1];
Object actual = accessor.getPropertyValue((String) nameValuePairs[i]);
assertEquals(expected, actual);
}
}
use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.
the class DispatcherServletAutoConfigurationTests method dispatcherServletDefaultConfig.
@Test
public void dispatcherServletDefaultConfig() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(DispatcherServletAutoConfiguration.class);
this.context.refresh();
DispatcherServlet bean = this.context.getBean(DispatcherServlet.class);
assertThat(bean).extracting("throwExceptionIfNoHandlerFound").containsExactly(false);
assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(true);
assertThat(bean).extracting("dispatchTraceRequest").containsExactly(false);
assertThat(new DirectFieldAccessor(this.context.getBean("dispatcherServletRegistration")).getPropertyValue("loadOnStartup")).isEqualTo(-1);
}
use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.
the class DispatcherServletAutoConfigurationTests method dispatcherServletCustomConfig.
@Test
public void dispatcherServletCustomConfig() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(DispatcherServletAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.mvc.throw-exception-if-no-handler-found:true", "spring.mvc.dispatch-options-request:false", "spring.mvc.dispatch-trace-request:true", "spring.mvc.servlet.load-on-startup=5");
this.context.refresh();
DispatcherServlet bean = this.context.getBean(DispatcherServlet.class);
assertThat(bean).extracting("throwExceptionIfNoHandlerFound").containsExactly(true);
assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(false);
assertThat(bean).extracting("dispatchTraceRequest").containsExactly(true);
assertThat(new DirectFieldAccessor(this.context.getBean("dispatcherServletRegistration")).getPropertyValue("loadOnStartup")).isEqualTo(5);
}
use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.
the class WebMvcAutoConfigurationTests method validationJsr303ValidatorExposedAsSpringValidator.
@Test
public void validationJsr303ValidatorExposedAsSpringValidator() {
load(Jsr303Validator.class);
assertThat(this.context.getBeansOfType(ValidatorFactory.class)).isEmpty();
assertThat(this.context.getBeansOfType(javax.validation.Validator.class)).hasSize(1);
assertThat(this.context.getBeansOfType(Validator.class)).hasSize(1);
Validator validator = this.context.getBean(Validator.class);
assertThat(validator).isInstanceOf(SpringValidator.class);
SpringValidatorAdapter target = ((SpringValidator) validator).getTarget();
assertThat(new DirectFieldAccessor(target).getPropertyValue("targetValidator")).isSameAs(this.context.getBean(javax.validation.Validator.class));
}
Aggregations