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));
}
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"));
}
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"));
}
Aggregations