Search in sources :

Example 81 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 82 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 83 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)

Example 84 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

the class DefaultLifecycleProcessorTests method customLifecycleProcessorInstance.

@Test
public void customLifecycleProcessorInstance() {
    BeanDefinition beanDefinition = new RootBeanDefinition(DefaultLifecycleProcessor.class);
    beanDefinition.getPropertyValues().addPropertyValue("timeoutPerShutdownPhase", 1000);
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerBeanDefinition("lifecycleProcessor", beanDefinition);
    context.refresh();
    LifecycleProcessor bean = context.getBean("lifecycleProcessor", LifecycleProcessor.class);
    Object contextLifecycleProcessor = new DirectFieldAccessor(context).getPropertyValue("lifecycleProcessor");
    assertNotNull(contextLifecycleProcessor);
    assertSame(bean, contextLifecycleProcessor);
    assertEquals(1000L, new DirectFieldAccessor(contextLifecycleProcessor).getPropertyValue("timeoutPerShutdownPhase"));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) LifecycleProcessor(org.springframework.context.LifecycleProcessor) Test(org.junit.Test)

Example 85 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.

the class JmsListenerContainerFactoryTests method backOffOverridesRecoveryInterval.

@Test
public void backOffOverridesRecoveryInterval() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    BackOff backOff = new FixedBackOff();
    factory.setBackOff(backOff);
    factory.setRecoveryInterval(2000L);
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    MessageListener messageListener = new MessageListenerAdapter();
    endpoint.setMessageListener(messageListener);
    endpoint.setDestination("myQueue");
    DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);
    assertSame(backOff, new DirectFieldAccessor(container).getPropertyValue("backOff"));
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MessageListener(javax.jms.MessageListener) FixedBackOff(org.springframework.util.backoff.FixedBackOff) BackOff(org.springframework.util.backoff.BackOff) FixedBackOff(org.springframework.util.backoff.FixedBackOff) 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