Start building against Spring Data 2022.0.0-M5 snapshots

See gh-31582
pull/31663/head
Mark Paluch 2 years ago committed by Andy Wilkinson
parent 96ade2d07a
commit 0067611396

@ -33,6 +33,7 @@ import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.data.cassandra.CassandraManagedTypes;
import org.springframework.data.cassandra.SessionFactory;
import org.springframework.data.cassandra.config.CassandraEntityClassScanner;
import org.springframework.data.cassandra.config.SchemaAction;
@ -68,16 +69,23 @@ public class CassandraDataAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public CassandraMappingContext cassandraMapping(BeanFactory beanFactory, CassandraCustomConversions conversions)
throws ClassNotFoundException {
CassandraMappingContext context = new CassandraMappingContext();
public CassandraManagedTypes cassandraManagedTypes(BeanFactory beanFactory) throws ClassNotFoundException {
List<String> packages = EntityScanPackages.get(beanFactory).getPackageNames();
if (packages.isEmpty() && AutoConfigurationPackages.has(beanFactory)) {
packages = AutoConfigurationPackages.get(beanFactory);
}
if (!packages.isEmpty()) {
context.setInitialEntitySet(CassandraEntityClassScanner.scan(packages));
return CassandraManagedTypes.fromIterable(CassandraEntityClassScanner.scan(packages));
}
return CassandraManagedTypes.empty();
}
@Bean
@ConditionalOnMissingBean
public CassandraMappingContext cassandraMappingContext(CassandraManagedTypes cassandraManagedTypes,
CassandraCustomConversions conversions) {
CassandraMappingContext context = new CassandraMappingContext();
context.setManagedTypes(cassandraManagedTypes);
context.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
return context;
}

@ -22,7 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration;
import org.springframework.boot.autoconfigure.elasticsearch.ReactiveElasticsearchClientAutoConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.client.erhlc.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
@ -43,6 +43,7 @@ import org.springframework.data.elasticsearch.repository.config.EnableReactiveEl
@Import({ ElasticsearchDataConfiguration.BaseConfiguration.class,
ElasticsearchDataConfiguration.RestClientConfiguration.class,
ElasticsearchDataConfiguration.ReactiveRestClientConfiguration.class })
@SuppressWarnings("deprecation")
public class ElasticsearchDataAutoConfiguration {
}

@ -26,11 +26,11 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.erhlc.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchCustomConversions;
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
@ -87,6 +87,7 @@ abstract class ElasticsearchDataConfiguration {
@Bean
@ConditionalOnMissingBean(value = ElasticsearchOperations.class, name = "elasticsearchTemplate")
@ConditionalOnBean(org.elasticsearch.client.RestHighLevelClient.class)
@SuppressWarnings("deprecation")
ElasticsearchRestTemplate elasticsearchTemplate(org.elasticsearch.client.RestHighLevelClient client,
ElasticsearchConverter converter) {
return new ElasticsearchRestTemplate(client, converter);
@ -101,6 +102,7 @@ abstract class ElasticsearchDataConfiguration {
@Bean
@ConditionalOnMissingBean(value = ReactiveElasticsearchOperations.class, name = "reactiveElasticsearchTemplate")
@ConditionalOnBean(ReactiveElasticsearchClient.class)
@SuppressWarnings("deprecation")
ReactiveElasticsearchTemplate reactiveElasticsearchTemplate(ReactiveElasticsearchClient client,
ElasticsearchConverter converter) {
return new ReactiveElasticsearchTemplate(client, converter);

@ -22,7 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Import;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
import org.springframework.data.elasticsearch.repository.support.ReactiveElasticsearchRepositoryFactoryBean;
@ -41,6 +41,7 @@ import org.springframework.data.elasticsearch.repository.support.ReactiveElastic
matchIfMissing = true)
@ConditionalOnMissingBean(ReactiveElasticsearchRepositoryFactoryBean.class)
@Import(ReactiveElasticsearchRepositoriesRegistrar.class)
@SuppressWarnings("deprecation")
public class ReactiveElasticsearchRepositoriesAutoConfiguration {
}

@ -16,19 +16,24 @@
package org.springframework.boot.autoconfigure.data.jdbc;
import java.util.Set;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.domain.EntityScanner;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import org.springframework.data.jdbc.repository.config.JdbcRepositoryConfigExtension;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.transaction.PlatformTransactionManager;
@ -41,6 +46,7 @@ import org.springframework.transaction.PlatformTransactionManager;
*
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Mark Paluch
* @since 2.1.0
* @see EnableJdbcRepositories
*/
@ -62,6 +68,17 @@ public class JdbcRepositoriesAutoConfiguration {
@ConditionalOnMissingBean(AbstractJdbcConfiguration.class)
static class SpringBootJdbcConfiguration extends AbstractJdbcConfiguration {
private final ApplicationContext applicationContext;
SpringBootJdbcConfiguration(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
@Override
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {
return new EntityScanner(this.applicationContext).scan(Table.class);
}
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -27,6 +27,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mapping.model.FieldNamingStrategy;
import org.springframework.data.mongodb.MongoManagedTypes;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
@ -43,12 +44,18 @@ class MongoDataConfiguration {
@Bean
@ConditionalOnMissingBean
MongoMappingContext mongoMappingContext(ApplicationContext applicationContext, MongoProperties properties,
MongoCustomConversions conversions) throws ClassNotFoundException {
MongoManagedTypes mongoManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException {
return MongoManagedTypes.fromIterable(new EntityScanner(applicationContext).scan(Document.class));
}
@Bean
@ConditionalOnMissingBean
MongoMappingContext mongoMappingContext(MongoProperties properties, MongoCustomConversions conversions,
MongoManagedTypes managedTypes) {
PropertyMapper mapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
MongoMappingContext context = new MongoMappingContext();
mapper.from(properties.isAutoIndexCreation()).to(context::setAutoIndexCreation);
context.setInitialEntitySet(new EntityScanner(applicationContext).scan(Document.class));
context.setManagedTypes(managedTypes);
Class<?> strategyClass = properties.getFieldNamingStrategy();
if (strategyClass != null) {
context.setFieldNamingStrategy((FieldNamingStrategy) BeanUtils.instantiateClass(strategyClass));

@ -26,7 +26,9 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.autoconfigure.domain.EntityScanner;
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.convert.CustomConversions;
import org.springframework.data.r2dbc.convert.MappingR2dbcConverter;
@ -36,7 +38,9 @@ import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.r2dbc.dialect.DialectResolver;
import org.springframework.data.r2dbc.dialect.R2dbcDialect;
import org.springframework.data.r2dbc.mapping.R2dbcMappingContext;
import org.springframework.data.relational.RelationalManagedTypes;
import org.springframework.data.relational.core.mapping.NamingStrategy;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.r2dbc.core.DatabaseClient;
/**
@ -66,13 +70,20 @@ public class R2dbcDataAutoConfiguration {
return new R2dbcEntityTemplate(this.databaseClient, this.dialect, r2dbcConverter);
}
@Bean
@ConditionalOnMissingBean
RelationalManagedTypes r2dbcManagedTypes(ApplicationContext applicationContext) throws ClassNotFoundException {
return RelationalManagedTypes.fromIterable(new EntityScanner(applicationContext).scan(Table.class));
}
@Bean
@ConditionalOnMissingBean
public R2dbcMappingContext r2dbcMappingContext(ObjectProvider<NamingStrategy> namingStrategy,
R2dbcCustomConversions r2dbcCustomConversions) {
R2dbcCustomConversions r2dbcCustomConversions, RelationalManagedTypes r2dbcManagedTypes) {
R2dbcMappingContext relationalMappingContext = new R2dbcMappingContext(
namingStrategy.getIfAvailable(() -> NamingStrategy.INSTANCE));
relationalMappingContext.setSimpleTypeHolder(r2dbcCustomConversions.getSimpleTypeHolder());
relationalMappingContext.setManagedTypes(r2dbcManagedTypes);
return relationalMappingContext;
}

@ -32,15 +32,16 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients.WebClientConfigurationCallback;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveRestClients;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.unit.DataSize;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import org.springframework.web.reactive.function.client.WebClient;
import static org.springframework.data.elasticsearch.client.elc.ElasticsearchClients.WebClientConfigurationCallback;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Elasticsearch Reactive REST
* clients.
@ -51,6 +52,7 @@ import org.springframework.web.reactive.function.client.WebClient;
@AutoConfiguration
@ConditionalOnClass({ ReactiveRestClients.class, WebClient.class, HttpClient.class })
@EnableConfigurationProperties(ElasticsearchProperties.class)
@SuppressWarnings("deprecation")
public class ReactiveElasticsearchClientAutoConfiguration {
private final ConsolidatedProperties properties;

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,6 +36,7 @@ import org.springframework.data.cassandra.core.convert.CassandraConverter;
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ObjectUtils;
@ -67,12 +68,11 @@ class CassandraDataAutoConfigurationTests {
@Test
@SuppressWarnings("unchecked")
void entityScanShouldSetInitialEntitySet() {
void entityScanShouldSetManagedTypes() {
load(EntityScanConfig.class);
CassandraMappingContext mappingContext = this.context.getBean(CassandraMappingContext.class);
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils.getField(mappingContext,
"initialEntitySet");
assertThat(initialEntitySet).containsOnly(City.class);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
assertThat(managedTypes.toList()).containsOnly(City.class);
}
@Test

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,8 +16,6 @@
package org.springframework.boot.autoconfigure.data.cassandra;
import java.util.Set;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@ -31,6 +29,7 @@ import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
import org.springframework.data.cassandra.core.convert.CassandraConverter;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -61,12 +60,11 @@ class CassandraReactiveDataAutoConfigurationTests {
@Test
@SuppressWarnings("unchecked")
void entityScanShouldSetInitialEntitySet() {
void entityScanShouldSetManagedTypes() {
load(EntityScanConfig.class, "spring.data.cassandra.keyspaceName:boot_test");
CassandraMappingContext mappingContext = this.context.getBean(CassandraMappingContext.class);
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils.getField(mappingContext,
"initialEntitySet");
assertThat(initialEntitySet).containsOnly(City.class);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
assertThat(managedTypes.toList()).containsOnly(City.class);
}
@Test

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -35,6 +35,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -59,7 +60,7 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
this.contextRunner.withUserConfiguration(DefaultConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(ReactiveCityRepository.class);
assertThat(context).hasSingleBean(CqlSessionBuilder.class);
assertThat(getInitialEntitySet(context)).hasSize(1);
assertThat(getManagedTypes(context).toList()).hasSize(1);
});
}
@ -67,7 +68,7 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
void testNoRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CqlSessionBuilder.class);
assertThat(getInitialEntitySet(context)).isEmpty();
assertThat(getManagedTypes(context).toList()).isEmpty();
});
}
@ -75,7 +76,7 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.contextRunner.withUserConfiguration(CustomizedConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(ReactiveCityCassandraRepository.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
assertThat(getManagedTypes(context).toList()).hasSize(1).containsOnly(City.class);
});
}
@ -94,9 +95,9 @@ class CassandraReactiveRepositoriesAutoConfigurationTests {
}
@SuppressWarnings("unchecked")
private Set<Class<?>> getInitialEntitySet(ApplicationContext context) {
private ManagedTypes getManagedTypes(ApplicationContext context) {
CassandraMappingContext mappingContext = context.getBean(CassandraMappingContext.class);
return (Set<Class<?>>) ReflectionTestUtils.getField(mappingContext, "initialEntitySet");
return (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
}
@Configuration(proxyBeanMethods = false)

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,8 +16,6 @@
package org.springframework.boot.autoconfigure.data.cassandra;
import java.util.Set;
import com.datastax.oss.driver.api.core.CqlSessionBuilder;
import org.junit.jupiter.api.Test;
@ -35,6 +33,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.cassandra.core.mapping.CassandraMappingContext;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -57,7 +56,7 @@ class CassandraRepositoriesAutoConfigurationTests {
this.contextRunner.withUserConfiguration(DefaultConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CityRepository.class);
assertThat(context).hasSingleBean(CqlSessionBuilder.class);
assertThat(getInitialEntitySet(context)).hasSize(1);
assertThat(getManagedTypes(context).toList()).hasSize(1);
});
}
@ -65,7 +64,7 @@ class CassandraRepositoriesAutoConfigurationTests {
void testNoRepositoryConfiguration() {
this.contextRunner.withUserConfiguration(EmptyConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CqlSessionBuilder.class);
assertThat(getInitialEntitySet(context)).isEmpty();
assertThat(getManagedTypes(context).toList()).isEmpty();
});
}
@ -73,7 +72,7 @@ class CassandraRepositoriesAutoConfigurationTests {
void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
this.contextRunner.withUserConfiguration(CustomizedConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(CityCassandraRepository.class);
assertThat(getInitialEntitySet(context)).hasSize(1).containsOnly(City.class);
assertThat(getManagedTypes(context).toList()).hasSize(1).containsOnly(City.class);
});
}
@ -92,9 +91,9 @@ class CassandraRepositoriesAutoConfigurationTests {
}
@SuppressWarnings("unchecked")
private Set<Class<?>> getInitialEntitySet(AssertableApplicationContext context) {
private ManagedTypes getManagedTypes(AssertableApplicationContext context) {
CassandraMappingContext mappingContext = context.getBean(CassandraMappingContext.class);
return (Set<Class<?>>) ReflectionTestUtils.getField(mappingContext, "initialEntitySet");
return (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
}
@Configuration(proxyBeanMethods = false)

@ -39,6 +39,7 @@ import org.springframework.data.couchbase.core.convert.DefaultCouchbaseTypeMappe
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
import org.springframework.data.couchbase.core.mapping.event.ValidatingCouchbaseEventListener;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -69,9 +70,8 @@ class CouchbaseDataAutoConfigurationTests {
void entityScanShouldSetInitialEntitySet() {
this.contextRunner.withUserConfiguration(EntityScanConfig.class).run((context) -> {
CouchbaseMappingContext mappingContext = context.getBean(CouchbaseMappingContext.class);
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils.getField(mappingContext,
"initialEntitySet");
assertThat(initialEntitySet).containsOnly(City.class);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
assertThat(managedTypes.toList()).containsOnly(City.class);
});
}

@ -37,6 +37,7 @@ import org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate;
import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions;
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
import org.springframework.data.couchbase.core.mapping.event.ValidatingCouchbaseEventListener;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -68,9 +69,8 @@ class CouchbaseReactiveDataAutoConfigurationTests {
void entityScanShouldSetInitialEntitySet() {
this.contextRunner.withUserConfiguration(EntityScanConfig.class).run((context) -> {
CouchbaseMappingContext mappingContext = context.getBean(CouchbaseMappingContext.class);
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils.getField(mappingContext,
"initialEntitySet");
assertThat(initialEntitySet).containsOnly(City.class);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
assertThat(managedTypes.toList()).containsOnly(City.class);
});
}

@ -33,8 +33,8 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.client.erhlc.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchCustomConversions;
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
@ -53,6 +53,7 @@ import static org.mockito.Mockito.mock;
* @author Scott Frederick
* @author Stephane Nicoll
*/
@SuppressWarnings("deprecation")
class ElasticsearchDataAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()

@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestCli
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.client.erhlc.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import static org.assertj.core.api.Assertions.assertThat;
@ -46,6 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Brian Clozel
*/
@Testcontainers(disabledWithoutDocker = true)
@SuppressWarnings("deprecation")
class ElasticsearchRepositoriesAutoConfigurationTests {
@Container

@ -33,7 +33,7 @@ import org.springframework.boot.autoconfigure.elasticsearch.ReactiveElasticsearc
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableReactiveElasticsearchRepositories;
import static org.assertj.core.api.Assertions.assertThat;
@ -46,6 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Brian Clozel
*/
@Testcontainers(disabledWithoutDocker = true)
@SuppressWarnings("deprecation")
class ReactiveElasticsearchRepositoriesAutoConfigurationTests {
@Container

@ -33,10 +33,14 @@ import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration
import org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import org.springframework.data.r2dbc.mapping.R2dbcMappingContext;
import org.springframework.data.repository.Repository;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -45,6 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Mark Paluch
*/
class JdbcRepositoriesAutoConfigurationTests {
@ -88,6 +93,19 @@ class JdbcRepositoriesAutoConfigurationTests {
});
}
@Test
void entityScanShouldSetManagedTypes() {
this.contextRunner.with(database())
.withConfiguration(AutoConfigurations.of(JdbcTemplateAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class))
.withUserConfiguration(TestConfiguration.class).run((context) -> {
JdbcMappingContext mappingContext = context.getBean(JdbcMappingContext.class);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext,
"managedTypes");
assertThat(managedTypes.toList()).containsOnly(City.class);
});
}
@Test
void autoConfigurationWithNoRepositories() {
this.contextRunner.with(database())

@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,6 +37,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.data.mapping.model.CamelCaseAbbreviatingFieldNamingStrategy;
import org.springframework.data.mapping.model.FieldNamingStrategy;
import org.springframework.data.mapping.model.PropertyNameFieldNamingStrategy;
@ -57,6 +58,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Josh Long
* @author Oliver Gierke
* @author Mark Paluch
*/
class MongoDataAutoConfigurationTests {
@ -160,12 +162,11 @@ class MongoDataAutoConfigurationTests {
@Test
@SuppressWarnings("unchecked")
void entityScanShouldSetInitialEntitySet() {
void entityScanShouldSetManagedTypes() {
this.contextRunner.withUserConfiguration(EntityScanConfig.class).run((context) -> {
MongoMappingContext mappingContext = context.getBean(MongoMappingContext.class);
Set<Class<?>> initialEntitySet = (Set<Class<?>>) ReflectionTestUtils.getField(mappingContext,
"initialEntitySet");
assertThat(initialEntitySet).containsOnly(City.class, Country.class);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
assertThat(managedTypes.toList()).containsOnly(City.class, Country.class);
});
}
@ -210,10 +211,10 @@ class MongoDataAutoConfigurationTests {
.run((context) -> assertThat(context).hasSingleBean(MongoTemplate.class));
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("unchecked")
private static void assertDomainTypesDiscovered(MongoMappingContext mappingContext, Class<?>... types) {
Set<Class> initialEntitySet = (Set<Class>) ReflectionTestUtils.getField(mappingContext, "initialEntitySet");
assertThat(initialEntitySet).containsOnly(types);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
assertThat(managedTypes.toList()).containsOnly(types);
}
@Configuration(proxyBeanMethods = false)

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,6 +33,7 @@ import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
@ -60,9 +61,8 @@ class MongoReactiveRepositoriesAutoConfigurationTests {
assertThat(context).hasSingleBean(MongoClient.class);
MongoMappingContext mappingContext = context.getBean(MongoMappingContext.class);
@SuppressWarnings("unchecked")
Set<? extends Class<?>> entities = (Set<? extends Class<?>>) ReflectionTestUtils.getField(mappingContext,
"initialEntitySet");
assertThat(entities).hasSize(1);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
assertThat(managedTypes.toList()).hasSize(1);
});
}

@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.data.mongo.city.CityRepository;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.test.util.ReflectionTestUtils;
@ -56,9 +57,8 @@ class MongoRepositoriesAutoConfigurationTests {
assertThat(context).hasSingleBean(MongoClient.class);
MongoMappingContext mappingContext = context.getBean(MongoMappingContext.class);
@SuppressWarnings("unchecked")
Set<? extends Class<?>> entities = (Set<? extends Class<?>>) ReflectionTestUtils.getField(mappingContext,
"initialEntitySet");
assertThat(entities).hasSize(1);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
assertThat(managedTypes.toList()).hasSize(1);
});
}

@ -19,9 +19,14 @@ package org.springframework.boot.autoconfigure.data.r2dbc;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.data.r2dbc.city.City;
import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.data.domain.ManagedTypes;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.r2dbc.mapping.R2dbcMappingContext;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -40,4 +45,18 @@ class R2dbcDataAutoConfigurationTests {
this.contextRunner.run((context) -> assertThat(context).hasSingleBean(R2dbcEntityTemplate.class));
}
@Test
void entityScanShouldSetManagedTypes() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {
R2dbcMappingContext mappingContext = context.getBean(R2dbcMappingContext.class);
ManagedTypes managedTypes = (ManagedTypes) ReflectionTestUtils.getField(mappingContext, "managedTypes");
assertThat(managedTypes.toList()).containsOnly(City.class);
});
}
@TestAutoConfigurationPackage(City.class)
static class TestConfiguration {
}
}

@ -31,8 +31,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.ClientConfiguration.ClientConfigurationCallback;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveRestClients;
import org.springframework.http.HttpHeaders;
import org.springframework.http.codec.CodecConfigurer.DefaultCodecConfig;
import org.springframework.web.reactive.function.client.WebClient;
@ -45,6 +45,7 @@ import static org.mockito.Mockito.mock;
*
* @author Brian Clozel
*/
@SuppressWarnings("deprecation")
class ReactiveElasticsearchClientAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
@ -244,10 +245,11 @@ class ReactiveElasticsearchClientAutoConfigurationTests {
});
}
@SuppressWarnings("unchecked")
private WebClient configureWebClient(List<ClientConfigurationCallback<?>> callbacks) {
WebClient webClient = WebClient.create();
for (ClientConfigurationCallback<?> callback : callbacks) {
webClient = ((ReactiveRestClients.WebClientConfigurationCallback) callback).configure(webClient);
webClient = ((ClientConfiguration.ClientConfigurationCallback<WebClient>) callback).configure(webClient);
}
return webClient;
}

@ -31,7 +31,7 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.testcontainers.DockerImageNames;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.erhlc.ReactiveElasticsearchClient;
import static org.assertj.core.api.Assertions.assertThat;
@ -41,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Brian Clozel
*/
@Testcontainers(disabledWithoutDocker = true)
@SuppressWarnings("deprecation")
class ReactiveElasticsearchRestClientAutoConfigurationIntegrationTests {
@Container

@ -1374,7 +1374,7 @@ bom {
]
}
}
library("Spring Data Bom", "2022.0.0-M4") {
library("Spring Data Bom", "2022.0.0-SNAPSHOT") {
group("org.springframework.data") {
imports = [
"spring-data-bom"

Loading…
Cancel
Save