Search in sources :

Example 86 with DirectFieldAccessor

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;
}
Also used : CorsConfiguration(org.springframework.web.cors.CorsConfiguration) HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor)

Example 87 with DirectFieldAccessor

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);
    }
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor)

Example 88 with DirectFieldAccessor

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);
}
Also used : DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 89 with DirectFieldAccessor

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);
}
Also used : DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 90 with DirectFieldAccessor

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));
}
Also used : SpringValidatorAdapter(org.springframework.validation.beanvalidation.SpringValidatorAdapter) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) SpringValidator(org.springframework.boot.autoconfigure.validation.SpringValidator) Validator(org.springframework.validation.Validator) Test(org.junit.Test)

Aggregations

DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)95 Test (org.junit.Test)79 List (java.util.List)25 Method (java.lang.reflect.Method)16 ScheduledMethodRunnable (org.springframework.scheduling.support.ScheduledMethodRunnable)16 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)15 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)15 ScheduledTaskRegistrar (org.springframework.scheduling.config.ScheduledTaskRegistrar)15 IntervalTask (org.springframework.scheduling.config.IntervalTask)8 CronTask (org.springframework.scheduling.config.CronTask)7 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)5 CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)4 DataSourceTransactionManagerAutoConfiguration (org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration)4 EmbeddedDataSourceConfiguration (org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration)4 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)4 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)4 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)4 JdbcOperationsSessionRepository (org.springframework.session.jdbc.JdbcOperationsSessionRepository)4 ViewResolver (org.springframework.web.servlet.ViewResolver)4