From 33f1158b87987bb0e463d43650a6cdb338934372 Mon Sep 17 00:00:00 2001 From: agrgr Date: Tue, 19 Mar 2024 12:52:52 +0200 Subject: [PATCH] update configuration and tests --- .../aerospike/AerospikeCommonDataConfiguration.java | 11 +++++++++++ .../AerospikeDataAutoConfigurationTest.java | 12 ++++++------ .../AerospikeReactiveDataAutoConfigurationTest.java | 10 +++++----- .../boot/autoconfigure/data/aerospike/TestUtils.java | 7 +++---- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeCommonDataConfiguration.java b/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeCommonDataConfiguration.java index b08cfc1..d7b0994 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeCommonDataConfiguration.java +++ b/spring-boot-autoconfigure-data-aerospike/src/main/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeCommonDataConfiguration.java @@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.domain.EntityScanner; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; +import org.springframework.data.aerospike.config.AerospikeConnectionSettings; import org.springframework.data.aerospike.config.AerospikeDataSettings; import org.springframework.data.aerospike.convert.AerospikeCustomConversions; import org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor; @@ -99,6 +100,16 @@ public AerospikeExceptionTranslator aerospikeExceptionTranslator() { return new DefaultAerospikeExceptionTranslator(); } + @Bean + public AerospikeDataSettings readAerospikeDataSettings() { + return new AerospikeDataSettings(); + } + + @Bean + public AerospikeConnectionSettings readAerospikeSettings() { + return new AerospikeConnectionSettings(); + } + private AerospikeDataSettings aerospikeDataSettings(AerospikeDataProperties aerospikeDataProperties, AerospikeDataSettings dataSettings) { return configureDataSettings(dataSettings, aerospikeDataProperties); diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfigurationTest.java b/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfigurationTest.java index abf9d50..9e392b1 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfigurationTest.java +++ b/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeDataAutoConfigurationTest.java @@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.data.aerospike.city.City; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.data.aerospike.convert.AerospikeConverter; import org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor; import org.springframework.data.aerospike.convert.MappingAerospikeConverter; import org.springframework.data.aerospike.core.AerospikeTemplate; @@ -76,7 +77,7 @@ public void entityScanShouldSetInitialEntitySet() { } @Test - public void typeKeyDefault() { + public void classKeyDefault() { contextRunner .withPropertyValues("spring.aerospike.hosts=localhost:3000") .withPropertyValues("spring.data.aerospike.namespace=TEST") @@ -84,10 +85,9 @@ public void typeKeyDefault() { AerospikeServerVersionSupportMockConfiguration.class) .run(context -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); - String typeKey = getField(aliasAccessor, "typeKey"); - String defaultTypeKey = getField(aliasAccessor, "TYPE_KEY"); + String classKey = getField(aliasAccessor, "classKey"); - assertThat(typeKey).isEqualTo(defaultTypeKey); + assertThat(classKey).isEqualTo(AerospikeConverter.CLASS_KEY); }); } @@ -101,7 +101,7 @@ public void typeKeyCanBeCustomized() { .withPropertyValues("spring.data.aerospike.type-key=++amazing++") .run((context) -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); - String typeKey = getField(aliasAccessor, "typeKey"); + String typeKey = getField(aliasAccessor, "classKey"); assertThat(typeKey).isEqualTo("++amazing++"); }); @@ -117,7 +117,7 @@ public void typeKeyCanBeNull() { .withPropertyValues("spring.data.aerospike.type-key=") .run((context) -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); - String typeKey = getField(aliasAccessor, "typeKey"); + String typeKey = getField(aliasAccessor, "classKey"); assertThat(typeKey).isNull(); }); diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfigurationTest.java b/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfigurationTest.java index 0be59b4..10fdcc6 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfigurationTest.java +++ b/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/AerospikeReactiveDataAutoConfigurationTest.java @@ -26,6 +26,7 @@ import org.springframework.boot.autoconfigure.data.aerospike.AerospikeTestConfigurations.MockReactiveIndexRefresher; import org.springframework.boot.autoconfigure.data.aerospike.city.City; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.data.aerospike.convert.AerospikeConverter; import org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor; import org.springframework.data.aerospike.convert.MappingAerospikeConverter; import org.springframework.data.aerospike.core.AerospikeTemplate; @@ -74,7 +75,7 @@ public void entityScanShouldSetInitialEntitySet() { } @Test - public void typeKeyDefault() { + public void classKeyDefault() { contextRunner .withPropertyValues("spring.aerospike.hosts=localhost:3000") .withPropertyValues("spring.data.aerospike.namespace=TEST") @@ -82,10 +83,9 @@ public void typeKeyDefault() { AerospikeServerVersionSupportMockConfiguration.class) .run(context -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); - String typeKey = getField(aliasAccessor, "typeKey"); - String defaultTypeKey = getField(aliasAccessor, "TYPE_KEY"); + String typeKey = getField(aliasAccessor, "classKey"); - assertThat(typeKey).isEqualTo(defaultTypeKey); + assertThat(typeKey).isEqualTo(AerospikeConverter.CLASS_KEY); }); } @@ -99,7 +99,7 @@ public void typeKeyCanBeCustomized() { .withPropertyValues("spring.data.aerospike.type-key=++amazing++") .run((context) -> { AerospikeTypeAliasAccessor aliasAccessor = context.getBean(AerospikeTypeAliasAccessor.class); - String typeKey = getField(aliasAccessor, "typeKey"); + String typeKey = getField(aliasAccessor, "classKey"); assertThat(typeKey).isEqualTo("++amazing++"); }); diff --git a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/TestUtils.java b/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/TestUtils.java index 1fb1e65..7b1e4fb 100644 --- a/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/TestUtils.java +++ b/spring-boot-autoconfigure-data-aerospike/src/test/java/org/springframework/boot/autoconfigure/data/aerospike/TestUtils.java @@ -1,15 +1,14 @@ package org.springframework.boot.autoconfigure.data.aerospike; -import org.springframework.data.aerospike.convert.AerospikeTypeAliasAccessor; import org.springframework.util.ReflectionUtils; import java.lang.reflect.Field; public class TestUtils { - public static T getField(AerospikeTypeAliasAccessor aliasAccessor, String fieldName) { - Field typeKeyField = ReflectionUtils.findField(AerospikeTypeAliasAccessor.class, fieldName); + public static T getField(Object object, String fieldName) { + Field typeKeyField = ReflectionUtils.findField(object.getClass(), fieldName); typeKeyField.setAccessible(true); - return (T) ReflectionUtils.getField(typeKeyField, aliasAccessor); + return (T) ReflectionUtils.getField(typeKeyField, object); } }