From 8355d304560fb13f10ba6130021d893fc59da368 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 24 Mar 2020 14:08:08 +0100 Subject: [PATCH 1/2] Migrate off deprecated Spring Data Cassandra API Configure UserTypeResolver and CodecRegistry on MappingCassandraConverter. Configure on CassandraMappingContext only the simple type holder instead of custom conversions. See gh-20662 --- .../CassandraDataAutoConfiguration.java | 5 ++-- .../CassandraDataAutoConfigurationTests.java | 24 +++++++++++++++---- ...draReactiveDataAutoConfigurationTests.java | 15 +++++++++--- ...iveRepositoriesAutoConfigurationTests.java | 10 +++++++- ...draRepositoriesAutoConfigurationTests.java | 10 +++++++- 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java index 557a58d1dc..80d1a4da57 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.java @@ -80,8 +80,7 @@ public class CassandraDataAutoConfiguration { if (!packages.isEmpty()) { context.setInitialEntitySet(CassandraEntityClassScanner.scan(packages)); } - context.setUserTypeResolver(new SimpleUserTypeResolver(this.session)); - context.setCustomConversions(conversions); + context.setSimpleTypeHolder(conversions.getSimpleTypeHolder()); return context; } @@ -90,7 +89,9 @@ public class CassandraDataAutoConfiguration { public CassandraConverter cassandraConverter(CassandraMappingContext mapping, CassandraCustomConversions conversions) { MappingCassandraConverter converter = new MappingCassandraConverter(mapping); + converter.setCodecRegistry(this.session.getContext().getCodecRegistry()); converter.setCustomConversions(conversions); + converter.setUserTypeResolver(new SimpleUserTypeResolver(this.session)); return converter; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java index 6b7ab3d312..c5f7aab67f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java @@ -20,8 +20,11 @@ import java.util.Collections; import java.util.Set; import com.datastax.oss.driver.api.core.CqlSession; +import com.datastax.oss.driver.api.core.context.DriverContext; +import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; +import org.mockito.BDDMockito; import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; import org.springframework.boot.autoconfigure.data.cassandra.city.City; @@ -32,6 +35,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.convert.converter.Converter; import org.springframework.data.cassandra.core.CassandraTemplate; +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; @@ -39,6 +43,7 @@ import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.mock; /** @@ -78,8 +83,15 @@ class CassandraDataAutoConfigurationTests { @Test void userTypeResolverShouldBeSet() { load(); - CassandraMappingContext mappingContext = this.context.getBean(CassandraMappingContext.class); - assertThat(mappingContext).extracting("userTypeResolver").isInstanceOf(SimpleUserTypeResolver.class); + CassandraConverter cassandraConverter = this.context.getBean(CassandraConverter.class); + assertThat(cassandraConverter).extracting("userTypeResolver").isInstanceOf(SimpleUserTypeResolver.class); + } + + @Test + void codecRegistryShouldBeSet() { + load(); + CassandraConverter cassandraConverter = this.context.getBean(CassandraConverter.class); + assertThat(BDDMockito.mockingDetails(cassandraConverter.getCodecRegistry()).isMock()).isTrue(); } @Test @@ -94,7 +106,6 @@ class CassandraDataAutoConfigurationTests { load(CustomConversionConfig.class); CassandraTemplate template = this.context.getBean(CassandraTemplate.class); assertThat(template.getConverter().getConversionService().canConvert(Person.class, String.class)).isTrue(); - } @Test @@ -119,7 +130,12 @@ class CassandraDataAutoConfigurationTests { @Bean CqlSession cqlSession() { - return mock(CqlSession.class); + CodecRegistry codecRegistry = mock(CodecRegistry.class); + DriverContext context = mock(DriverContext.class); + CqlSession cqlSession = mock(CqlSession.class); + when(context.getCodecRegistry()).thenReturn(codecRegistry); + when(cqlSession.getContext()).thenReturn(context); + return cqlSession; } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java index aa19296d22..c6a854e4fa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java @@ -19,6 +19,8 @@ package org.springframework.boot.autoconfigure.data.cassandra; import java.util.Set; import com.datastax.oss.driver.api.core.CqlSession; +import com.datastax.oss.driver.api.core.context.DriverContext; +import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -30,11 +32,13 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; 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.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.mock; /** @@ -74,8 +78,8 @@ class CassandraReactiveDataAutoConfigurationTests { @Test void userTypeResolverShouldBeSet() { load("spring.data.cassandra.keyspaceName:boot_test"); - CassandraMappingContext mappingContext = this.context.getBean(CassandraMappingContext.class); - assertThat(mappingContext).extracting("userTypeResolver").isInstanceOf(SimpleUserTypeResolver.class); + CassandraConverter cassandraConverter = this.context.getBean(CassandraConverter.class); + assertThat(cassandraConverter).extracting("userTypeResolver").isInstanceOf(SimpleUserTypeResolver.class); } private void load(String... environment) { @@ -99,7 +103,12 @@ class CassandraReactiveDataAutoConfigurationTests { @Bean CqlSession cqlSession() { - return mock(CqlSession.class); + CodecRegistry codecRegistry = mock(CodecRegistry.class); + DriverContext context = mock(DriverContext.class); + CqlSession cqlSession = mock(CqlSession.class); + when(context.getCodecRegistry()).thenReturn(codecRegistry); + when(cqlSession.getContext()).thenReturn(context); + return cqlSession; } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java index 51ddff301e..85ddb3f5a0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java @@ -20,6 +20,8 @@ import java.util.Set; import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.CqlSessionBuilder; +import com.datastax.oss.driver.api.core.context.DriverContext; +import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -40,6 +42,7 @@ import org.springframework.data.cassandra.repository.config.EnableReactiveCassan import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.mock; /** @@ -107,7 +110,12 @@ class CassandraReactiveRepositoriesAutoConfigurationTests { @Bean CqlSession cqlSession() { - return mock(CqlSession.class); + CodecRegistry codecRegistry = mock(CodecRegistry.class); + DriverContext context = mock(DriverContext.class); + CqlSession cqlSession = mock(CqlSession.class); + when(context.getCodecRegistry()).thenReturn(codecRegistry); + when(cqlSession.getContext()).thenReturn(context); + return cqlSession; } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java index 4f6aa0f5de..b014b665d5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java @@ -20,6 +20,8 @@ import java.util.Set; import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.CqlSessionBuilder; +import com.datastax.oss.driver.api.core.context.DriverContext; +import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -40,6 +42,7 @@ import org.springframework.data.cassandra.repository.config.EnableCassandraRepos import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.when; import static org.mockito.Mockito.mock; /** @@ -105,7 +108,12 @@ class CassandraRepositoriesAutoConfigurationTests { @Bean CqlSession cqlSession() { - return mock(CqlSession.class); + CodecRegistry codecRegistry = mock(CodecRegistry.class); + DriverContext context = mock(DriverContext.class); + CqlSession cqlSession = mock(CqlSession.class); + when(context.getCodecRegistry()).thenReturn(codecRegistry); + when(cqlSession.getContext()).thenReturn(context); + return cqlSession; } } From 97bf3ecf1cafb7a0070c40ad263bdcc27ab63ab9 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 24 Mar 2020 18:26:33 +0100 Subject: [PATCH 2/2] Polish "Migrate off deprecated Spring Data Cassandra API" See gh-20662 --- .../CassandraDataAutoConfigurationTests.java | 28 ++--------- .../cassandra/CassandraMockConfiguration.java | 48 +++++++++++++++++++ ...draReactiveDataAutoConfigurationTests.java | 25 +--------- ...iveRepositoriesAutoConfigurationTests.java | 27 ++--------- ...draRepositoriesAutoConfigurationTests.java | 27 ++--------- 5 files changed, 61 insertions(+), 94 deletions(-) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraMockConfiguration.java diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java index c5f7aab67f..c9d6ef7434 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfigurationTests.java @@ -20,11 +20,8 @@ import java.util.Collections; import java.util.Set; import com.datastax.oss.driver.api.core.CqlSession; -import com.datastax.oss.driver.api.core.context.DriverContext; -import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; -import org.mockito.BDDMockito; import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; import org.springframework.boot.autoconfigure.data.cassandra.city.City; @@ -43,8 +40,6 @@ import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.when; -import static org.mockito.Mockito.mock; /** * Tests for {@link CassandraDataAutoConfiguration}. @@ -66,7 +61,7 @@ class CassandraDataAutoConfigurationTests { @Test void templateExists() { - load(TestConfiguration.class); + load(CassandraMockConfiguration.class); assertThat(this.context.getBeanNamesForType(CassandraTemplate.class)).hasSize(1); } @@ -91,7 +86,8 @@ class CassandraDataAutoConfigurationTests { void codecRegistryShouldBeSet() { load(); CassandraConverter cassandraConverter = this.context.getBean(CassandraConverter.class); - assertThat(BDDMockito.mockingDetails(cassandraConverter.getCodecRegistry()).isMock()).isTrue(); + assertThat(cassandraConverter.getCodecRegistry()) + .isSameAs(this.context.getBean(CassandraMockConfiguration.class).codecRegistry); } @Test @@ -120,26 +116,12 @@ class CassandraDataAutoConfigurationTests { if (!ObjectUtils.isEmpty(config)) { ctx.register(config); } - ctx.register(TestConfiguration.class, CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class); + ctx.register(CassandraMockConfiguration.class, CassandraAutoConfiguration.class, + CassandraDataAutoConfiguration.class); ctx.refresh(); this.context = ctx; } - @Configuration(proxyBeanMethods = false) - static class TestConfiguration { - - @Bean - CqlSession cqlSession() { - CodecRegistry codecRegistry = mock(CodecRegistry.class); - DriverContext context = mock(DriverContext.class); - CqlSession cqlSession = mock(CqlSession.class); - when(context.getCodecRegistry()).thenReturn(codecRegistry); - when(cqlSession.getContext()).thenReturn(context); - return cqlSession; - } - - } - @Configuration(proxyBeanMethods = false) @EntityScan("org.springframework.boot.autoconfigure.data.cassandra.city") static class EntityScanConfig { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraMockConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraMockConfiguration.java new file mode 100644 index 0000000000..dc74693830 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraMockConfiguration.java @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2020 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data.cassandra; + +import com.datastax.oss.driver.api.core.CqlSession; +import com.datastax.oss.driver.api.core.context.DriverContext; +import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +/** + * Test configuration that mocks access to Cassandra. + * + * @author Stephane Nicoll + */ +@Configuration(proxyBeanMethods = false) +class CassandraMockConfiguration { + + final CodecRegistry codecRegistry = mock(CodecRegistry.class); + + @Bean + CqlSession cqlSession() { + DriverContext context = mock(DriverContext.class); + given(context.getCodecRegistry()).willReturn(this.codecRegistry); + CqlSession cqlSession = mock(CqlSession.class); + given(cqlSession.getContext()).willReturn(context); + return cqlSession; + } + +} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java index c6a854e4fa..c546888c00 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveDataAutoConfigurationTests.java @@ -18,9 +18,6 @@ package org.springframework.boot.autoconfigure.data.cassandra; import java.util.Set; -import com.datastax.oss.driver.api.core.CqlSession; -import com.datastax.oss.driver.api.core.context.DriverContext; -import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -29,7 +26,6 @@ import org.springframework.boot.autoconfigure.data.cassandra.city.City; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.cassandra.core.ReactiveCassandraTemplate; import org.springframework.data.cassandra.core.convert.CassandraConverter; @@ -38,8 +34,6 @@ import org.springframework.data.cassandra.core.mapping.SimpleUserTypeResolver; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.when; -import static org.mockito.Mockito.mock; /** * Tests for {@link CassandraReactiveDataAutoConfiguration}. @@ -92,27 +86,12 @@ class CassandraReactiveDataAutoConfigurationTests { if (config != null) { ctx.register(config); } - ctx.register(TestConfiguration.class, CassandraAutoConfiguration.class, CassandraDataAutoConfiguration.class, - CassandraReactiveDataAutoConfiguration.class); + ctx.register(CassandraMockConfiguration.class, CassandraAutoConfiguration.class, + CassandraDataAutoConfiguration.class, CassandraReactiveDataAutoConfiguration.class); ctx.refresh(); this.context = ctx; } - @Configuration(proxyBeanMethods = false) - static class TestConfiguration { - - @Bean - CqlSession cqlSession() { - CodecRegistry codecRegistry = mock(CodecRegistry.class); - DriverContext context = mock(DriverContext.class); - CqlSession cqlSession = mock(CqlSession.class); - when(context.getCodecRegistry()).thenReturn(codecRegistry); - when(cqlSession.getContext()).thenReturn(context); - return cqlSession; - } - - } - @Configuration(proxyBeanMethods = false) @EntityScan("org.springframework.boot.autoconfigure.data.cassandra.city") static class EntityScanConfig { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java index 85ddb3f5a0..3f2b3b23f4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraReactiveRepositoriesAutoConfigurationTests.java @@ -18,10 +18,7 @@ package org.springframework.boot.autoconfigure.data.cassandra; import java.util.Set; -import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.CqlSessionBuilder; -import com.datastax.oss.driver.api.core.context.DriverContext; -import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -34,7 +31,6 @@ import org.springframework.boot.autoconfigure.data.cassandra.city.ReactiveCityRe import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; @@ -42,8 +38,6 @@ import org.springframework.data.cassandra.repository.config.EnableReactiveCassan import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.when; -import static org.mockito.Mockito.mock; /** * Tests for {@link CassandraReactiveRepositoriesAutoConfiguration}. @@ -105,31 +99,16 @@ class CassandraReactiveRepositoriesAutoConfigurationTests { return (Set>) ReflectionTestUtils.getField(mappingContext, "initialEntitySet"); } - @Configuration(proxyBeanMethods = false) - static class TestConfiguration { - - @Bean - CqlSession cqlSession() { - CodecRegistry codecRegistry = mock(CodecRegistry.class); - DriverContext context = mock(DriverContext.class); - CqlSession cqlSession = mock(CqlSession.class); - when(context.getCodecRegistry()).thenReturn(codecRegistry); - when(cqlSession.getContext()).thenReturn(context); - return cqlSession; - } - - } - @Configuration(proxyBeanMethods = false) @TestAutoConfigurationPackage(EmptyDataPackage.class) - @Import(TestConfiguration.class) + @Import(CassandraMockConfiguration.class) static class EmptyConfiguration { } @Configuration(proxyBeanMethods = false) @TestAutoConfigurationPackage(City.class) - @Import(TestConfiguration.class) + @Import(CassandraMockConfiguration.class) static class DefaultConfiguration { } @@ -137,7 +116,7 @@ class CassandraReactiveRepositoriesAutoConfigurationTests { @Configuration(proxyBeanMethods = false) @TestAutoConfigurationPackage(CassandraReactiveRepositoriesAutoConfigurationTests.class) @EnableReactiveCassandraRepositories(basePackageClasses = ReactiveCityCassandraRepository.class) - @Import(TestConfiguration.class) + @Import(CassandraMockConfiguration.class) static class CustomizedConfiguration { } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java index b014b665d5..017d1c1018 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/cassandra/CassandraRepositoriesAutoConfigurationTests.java @@ -18,10 +18,7 @@ package org.springframework.boot.autoconfigure.data.cassandra; import java.util.Set; -import com.datastax.oss.driver.api.core.CqlSession; import com.datastax.oss.driver.api.core.CqlSessionBuilder; -import com.datastax.oss.driver.api.core.context.DriverContext; -import com.datastax.oss.driver.api.core.type.codec.registry.CodecRegistry; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -34,7 +31,6 @@ import org.springframework.boot.autoconfigure.data.cassandra.city.CityRepository import org.springframework.boot.autoconfigure.data.empty.EmptyDataPackage; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.data.cassandra.core.mapping.CassandraMappingContext; @@ -42,8 +38,6 @@ import org.springframework.data.cassandra.repository.config.EnableCassandraRepos import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.when; -import static org.mockito.Mockito.mock; /** * Tests for {@link CassandraRepositoriesAutoConfiguration}. @@ -103,31 +97,16 @@ class CassandraRepositoriesAutoConfigurationTests { return (Set>) ReflectionTestUtils.getField(mappingContext, "initialEntitySet"); } - @Configuration(proxyBeanMethods = false) - static class TestConfiguration { - - @Bean - CqlSession cqlSession() { - CodecRegistry codecRegistry = mock(CodecRegistry.class); - DriverContext context = mock(DriverContext.class); - CqlSession cqlSession = mock(CqlSession.class); - when(context.getCodecRegistry()).thenReturn(codecRegistry); - when(cqlSession.getContext()).thenReturn(context); - return cqlSession; - } - - } - @Configuration(proxyBeanMethods = false) @TestAutoConfigurationPackage(EmptyDataPackage.class) - @Import(TestConfiguration.class) + @Import(CassandraMockConfiguration.class) static class EmptyConfiguration { } @Configuration(proxyBeanMethods = false) @TestAutoConfigurationPackage(City.class) - @Import(TestConfiguration.class) + @Import(CassandraMockConfiguration.class) static class DefaultConfiguration { } @@ -135,7 +114,7 @@ class CassandraRepositoriesAutoConfigurationTests { @Configuration(proxyBeanMethods = false) @TestAutoConfigurationPackage(CassandraRepositoriesAutoConfigurationTests.class) @EnableCassandraRepositories(basePackageClasses = CityCassandraRepository.class) - @Import(TestConfiguration.class) + @Import(CassandraMockConfiguration.class) static class CustomizedConfiguration { }