Search in sources :

Example 66 with DirectFieldAccessor

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");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Set(java.util.Set) MBeanExporter(org.springframework.jmx.export.MBeanExporter) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) BasicDataSource(org.apache.commons.dbcp2.BasicDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 67 with DirectFieldAccessor

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");
}
Also used : IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 68 with DirectFieldAccessor

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));
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) DefaultJmsListenerContainerFactory(org.springframework.jms.config.DefaultJmsListenerContainerFactory) JtaTransactionManager(org.springframework.transaction.jta.JtaTransactionManager) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 69 with DirectFieldAccessor

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();
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) JmsListenerEndpoint(org.springframework.jms.config.JmsListenerEndpoint) DefaultJmsListenerContainerFactory(org.springframework.jms.config.DefaultJmsListenerContainerFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 70 with DirectFieldAccessor

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