Search in sources :

Example 21 with DirectFieldAccessor

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

the class SessionAutoConfigurationRedisTests method redisSessionStoreWithCustomizations.

@Test
public void redisSessionStoreWithCustomizations() {
    load(Collections.<Class<?>>singletonList(RedisAutoConfiguration.class), "spring.session.store-type=redis", "spring.session.redis.namespace=foo", "spring.session.redis.flush-mode=immediate");
    RedisOperationsSessionRepository repository = validateSessionRepository(RedisOperationsSessionRepository.class);
    assertThat(repository.getSessionCreatedChannelPrefix()).isEqualTo("spring:session:foo:event:created:");
    assertThat(new DirectFieldAccessor(repository).getPropertyValue("redisFlushMode")).isEqualTo(RedisFlushMode.IMMEDIATE);
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RedisOperationsSessionRepository(org.springframework.session.data.redis.RedisOperationsSessionRepository) RedisAutoConfiguration(org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration) Test(org.junit.Test)

Example 22 with DirectFieldAccessor

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

the class SessionAutoConfigurationTests method mongoSessionStoreWithCustomizations.

@Test
public void mongoSessionStoreWithCustomizations() {
    load(Arrays.asList(EmbeddedMongoAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class), "spring.session.store-type=mongo", "spring.session.mongo.collection-name=foobar");
    MongoOperationsSessionRepository repository = validateSessionRepository(MongoOperationsSessionRepository.class);
    assertThat(new DirectFieldAccessor(repository).getPropertyValue("collectionName")).isEqualTo("foobar");
}
Also used : MongoOperationsSessionRepository(org.springframework.session.data.mongo.MongoOperationsSessionRepository) MongoDataAutoConfiguration(org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) EmbeddedMongoAutoConfiguration(org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration) MongoAutoConfiguration(org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration) EmbeddedMongoAutoConfiguration(org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration) Test(org.junit.Test)

Example 23 with DirectFieldAccessor

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

the class RabbitAutoConfigurationTests method testRabbitTemplateRetry.

@Test
public void testRabbitTemplateRetry() {
    load(TestConfiguration.class, "spring.rabbitmq.template.retry.enabled:true", "spring.rabbitmq.template.retry.maxAttempts:4", "spring.rabbitmq.template.retry.initialInterval:2000", "spring.rabbitmq.template.retry.multiplier:1.5", "spring.rabbitmq.template.retry.maxInterval:5000", "spring.rabbitmq.template.receiveTimeout:123", "spring.rabbitmq.template.replyTimeout:456");
    RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
    DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitTemplate);
    assertThat(dfa.getPropertyValue("receiveTimeout")).isEqualTo(123L);
    assertThat(dfa.getPropertyValue("replyTimeout")).isEqualTo(456L);
    RetryTemplate retryTemplate = (RetryTemplate) dfa.getPropertyValue("retryTemplate");
    assertThat(retryTemplate).isNotNull();
    dfa = new DirectFieldAccessor(retryTemplate);
    SimpleRetryPolicy retryPolicy = (SimpleRetryPolicy) dfa.getPropertyValue("retryPolicy");
    ExponentialBackOffPolicy backOffPolicy = (ExponentialBackOffPolicy) dfa.getPropertyValue("backOffPolicy");
    assertThat(retryPolicy.getMaxAttempts()).isEqualTo(4);
    assertThat(backOffPolicy.getInitialInterval()).isEqualTo(2000);
    assertThat(backOffPolicy.getMultiplier()).isEqualTo(1.5);
    assertThat(backOffPolicy.getMaxInterval()).isEqualTo(5000);
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) RetryTemplate(org.springframework.retry.support.RetryTemplate) ExponentialBackOffPolicy(org.springframework.retry.backoff.ExponentialBackOffPolicy) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SimpleRetryPolicy(org.springframework.retry.policy.SimpleRetryPolicy) Test(org.junit.Test)

Example 24 with DirectFieldAccessor

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

the class RabbitAutoConfigurationTests method testConnectionFactoryCacheSettings.

@Test
public void testConnectionFactoryCacheSettings() {
    load(TestConfiguration.class, "spring.rabbitmq.cache.channel.size=23", "spring.rabbitmq.cache.channel.checkoutTimeout=1000", "spring.rabbitmq.cache.connection.mode=CONNECTION", "spring.rabbitmq.cache.connection.size=2");
    CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
    DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
    assertThat(dfa.getPropertyValue("channelCacheSize")).isEqualTo(23);
    assertThat(dfa.getPropertyValue("cacheMode")).isEqualTo(CacheMode.CONNECTION);
    assertThat(dfa.getPropertyValue("connectionCacheSize")).isEqualTo(2);
    assertThat(dfa.getPropertyValue("channelCheckoutTimeout")).isEqualTo(1000L);
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) Test(org.junit.Test)

Example 25 with DirectFieldAccessor

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

the class RabbitAutoConfigurationTests method testConnectionFactoryWithOverrides.

@Test
public void testConnectionFactoryWithOverrides() {
    load(TestConfiguration.class, "spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice", "spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost", "spring.rabbitmq.connection-timeout:123");
    CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
    assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
    assertThat(connectionFactory.getPort()).isEqualTo(9000);
    assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
    DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
    com.rabbitmq.client.ConnectionFactory rcf = (com.rabbitmq.client.ConnectionFactory) dfa.getPropertyValue("rabbitConnectionFactory");
    assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
    assertThat((Address[]) dfa.getPropertyValue("addresses")).hasSize(1);
}
Also used : ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) 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