Search in sources :

Example 1 with DirectFieldAccessor

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

the class WebMvcAutoConfigurationTests method testLogResolvedExceptionCustomization.

private void testLogResolvedExceptionCustomization(final boolean expected) {
    HandlerExceptionResolver exceptionResolver = this.context.getBean(HandlerExceptionResolver.class);
    assertThat(exceptionResolver).isInstanceOf(HandlerExceptionResolverComposite.class);
    List<HandlerExceptionResolver> delegates = ((HandlerExceptionResolverComposite) exceptionResolver).getExceptionResolvers();
    for (HandlerExceptionResolver delegate : delegates) {
        if (delegate instanceof AbstractHandlerMethodAdapter) {
            assertThat(new DirectFieldAccessor(delegate).getPropertyValue("warnLogger")).is(new Condition<Object>() {

                @Override
                public boolean matches(Object value) {
                    return (expected ? value != null : value == null);
                }
            });
        }
    }
}
Also used : HandlerExceptionResolver(org.springframework.web.servlet.HandlerExceptionResolver) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) HandlerExceptionResolverComposite(org.springframework.web.servlet.handler.HandlerExceptionResolverComposite) AbstractHandlerMethodAdapter(org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter)

Example 2 with DirectFieldAccessor

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

the class SessionAutoConfigurationJdbcTests method disableDatabaseInitializer.

@Test
public void disableDatabaseInitializer() {
    load(Arrays.asList(EmbeddedDataSourceConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class), "spring.session.store-type=jdbc", "spring.session.jdbc.initializer.enabled=false");
    JdbcOperationsSessionRepository repository = validateSessionRepository(JdbcOperationsSessionRepository.class);
    assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")).isEqualTo("SPRING_SESSION");
    assertThat(this.context.getBean(SessionProperties.class).getJdbc().getInitializer().isEnabled()).isFalse();
    this.thrown.expect(BadSqlGrammarException.class);
    assertThat(this.context.getBean(JdbcOperations.class).queryForList("select * from SPRING_SESSION")).isEmpty();
}
Also used : EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) JdbcOperationsSessionRepository(org.springframework.session.jdbc.JdbcOperationsSessionRepository) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) DataSourceTransactionManagerAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration) Test(org.junit.Test)

Example 3 with DirectFieldAccessor

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

the class SessionAutoConfigurationJdbcTests method defaultConfig.

@Test
public void defaultConfig() {
    load(Arrays.asList(EmbeddedDataSourceConfiguration.class, JdbcTemplateAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class), "spring.session.store-type=jdbc");
    JdbcOperationsSessionRepository repository = validateSessionRepository(JdbcOperationsSessionRepository.class);
    assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")).isEqualTo("SPRING_SESSION");
    assertThat(this.context.getBean(SessionProperties.class).getJdbc().getInitializer().isEnabled()).isTrue();
    assertThat(this.context.getBean(JdbcOperations.class).queryForList("select * from SPRING_SESSION")).isEmpty();
}
Also used : EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) JdbcOperationsSessionRepository(org.springframework.session.jdbc.JdbcOperationsSessionRepository) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JdbcTemplateAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration) JdbcOperations(org.springframework.jdbc.core.JdbcOperations) DataSourceTransactionManagerAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration) Test(org.junit.Test)

Example 4 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 5 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)

Aggregations

DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)480 Test (org.junit.Test)388 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)60 Test (org.junit.jupiter.api.Test)48 List (java.util.List)45 Log (org.apache.commons.logging.Log)35 BeanFactory (org.springframework.beans.factory.BeanFactory)32 Expression (org.springframework.expression.Expression)29 Method (java.lang.reflect.Method)28 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)27 QueueChannel (org.springframework.integration.channel.QueueChannel)24 AbstractMailReceiver (org.springframework.integration.mail.AbstractMailReceiver)23 Map (java.util.Map)22 MessageChannel (org.springframework.messaging.MessageChannel)21 ArrayList (java.util.ArrayList)20 CountDownLatch (java.util.concurrent.CountDownLatch)20 AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)20 IOException (java.io.IOException)19 File (java.io.File)18 Properties (java.util.Properties)18