use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.
the class JndiDataSourceAutoConfigurationTests method mbeanDataSourceIsExcludedFromExport.
@SuppressWarnings("unchecked")
@Test
public void mbeanDataSourceIsExcludedFromExport() throws IllegalStateException, NamingException {
DataSource dataSource = new BasicDataSource();
configureJndi("foo", dataSource);
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.jndi-name:foo");
this.context.register(JndiDataSourceAutoConfiguration.class, MBeanExporterConfiguration.class);
this.context.refresh();
assertThat(this.context.getBean(DataSource.class)).isEqualTo(dataSource);
MBeanExporter exporter = this.context.getBean(MBeanExporter.class);
Set<String> excludedBeans = (Set<String>) new DirectFieldAccessor(exporter).getPropertyValue("excludedBeans");
assertThat(excludedBeans).containsExactly("dataSource");
}
use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.
the class JmxAutoConfigurationTests method customJmxDomain.
@Test
public void customJmxDomain() {
this.context = new AnnotationConfigApplicationContext();
this.context.register(CustomJmxDomainConfiguration.class, JmxAutoConfiguration.class, IntegrationAutoConfiguration.class);
this.context.refresh();
IntegrationMBeanExporter mbeanExporter = this.context.getBean(IntegrationMBeanExporter.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(mbeanExporter);
assertThat(dfa.getPropertyValue("domain")).isEqualTo("foo.my");
}
use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.
the class JmsAutoConfigurationTests method testDefaultContainerFactoryWithJtaTransactionManager.
@Test
public void testDefaultContainerFactoryWithJtaTransactionManager() {
this.context = createContext(TestConfiguration7.class, EnableJmsConfiguration.class);
JmsListenerContainerFactory<?> jmsListenerContainerFactory = this.context.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
assertThat(jmsListenerContainerFactory.getClass()).isEqualTo(DefaultJmsListenerContainerFactory.class);
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
assertThat(listenerContainer.isSessionTransacted()).isFalse();
assertThat(new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager")).isSameAs(this.context.getBean(JtaTransactionManager.class));
}
use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.
the class JmsAutoConfigurationTests method testDefaultContainerFactoryNoTransactionManager.
@Test
public void testDefaultContainerFactoryNoTransactionManager() {
this.context = createContext(EnableJmsConfiguration.class);
JmsListenerContainerFactory<?> jmsListenerContainerFactory = this.context.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
assertThat(jmsListenerContainerFactory.getClass()).isEqualTo(DefaultJmsListenerContainerFactory.class);
DefaultMessageListenerContainer listenerContainer = ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory).createListenerContainer(mock(JmsListenerEndpoint.class));
assertThat(listenerContainer.isSessionTransacted()).isTrue();
assertThat(new DirectFieldAccessor(listenerContainer).getPropertyValue("transactionManager")).isNull();
}
use of org.springframework.beans.DirectFieldAccessor in project spring-framework by spring-projects.
the class ScriptTemplateViewTests method detectScriptTemplateConfigWithEngineName.
@Test
public void detectScriptTemplateConfigWithEngineName() {
this.configurer.setEngineName("nashorn");
this.configurer.setRenderObject("Template");
this.configurer.setRenderFunction("render");
DirectFieldAccessor accessor = new DirectFieldAccessor(this.view);
this.view.setApplicationContext(this.context);
assertEquals("nashorn", accessor.getPropertyValue("engineName"));
assertNotNull(accessor.getPropertyValue("engine"));
assertEquals("Template", accessor.getPropertyValue("renderObject"));
assertEquals("render", accessor.getPropertyValue("renderFunction"));
assertEquals(StandardCharsets.UTF_8, accessor.getPropertyValue("defaultCharset"));
}
Aggregations