@ -17,6 +17,8 @@
@@ -17,6 +17,8 @@
package org.springframework.boot.autoconfigure.couchbase ;
import java.time.Duration ;
import java.util.HashSet ;
import java.util.Set ;
import java.util.function.Consumer ;
import com.couchbase.client.core.env.IoConfig ;
@ -26,7 +28,9 @@ import com.couchbase.client.java.Cluster;
@@ -26,7 +28,9 @@ import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.codec.JacksonJsonSerializer ;
import com.couchbase.client.java.codec.JsonSerializer ;
import com.couchbase.client.java.env.ClusterEnvironment ;
import com.couchbase.client.java.json.JsonValueModule ;
import com.fasterxml.jackson.databind.ObjectMapper ;
import org.assertj.core.api.InstanceOfAssertFactories ;
import org.junit.jupiter.api.Test ;
import org.springframework.boot.autoconfigure.AutoConfigurations ;
@ -66,14 +70,18 @@ class CouchbaseAutoConfigurationTests {
@@ -66,14 +70,18 @@ class CouchbaseAutoConfigurationTests {
}
@Test
void environmentUseObjectMapperByDefaul t( ) {
void whenObjectMapperBeanIsDefinedThenClusterEnvironmentObjectMapperIsDerivedFromI t( ) {
this . contextRunner . withUserConfiguration ( CouchbaseTestConfiguration . class )
. withConfiguration ( AutoConfigurations . of ( JacksonAutoConfiguration . class ) )
. withPropertyValues ( "spring.couchbase.connection-string=localhost" ) . run ( ( context ) - > {
ClusterEnvironment env = context . getBean ( ClusterEnvironment . class ) ;
Set < Object > expectedModuleIds = new HashSet < > (
context . getBean ( ObjectMapper . class ) . getRegisteredModuleIds ( ) ) ;
expectedModuleIds . add ( new JsonValueModule ( ) . getTypeId ( ) ) ;
JsonSerializer serializer = env . jsonSerializer ( ) ;
assertThat ( serializer ) . isInstanceOf ( JacksonJsonSerializer . class )
. hasFieldOrPropertyWithValue ( "mapper" , context . getBean ( ObjectMapper . class ) ) ;
assertThat ( serializer ) . isInstanceOf ( JacksonJsonSerializer . class ) . extracting ( "mapper" )
. asInstanceOf ( InstanceOfAssertFactories . type ( ObjectMapper . class ) )
. extracting ( ObjectMapper : : getRegisteredModuleIds ) . isEqualTo ( expectedModuleIds ) ;
} ) ;
}