Skip to content

Commit

Permalink
update configuration and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Mar 19, 2024
1 parent ce8d635 commit 33f1158
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,18 +77,17 @@ public void entityScanShouldSetInitialEntitySet() {
}

@Test
public void typeKeyDefault() {
public void classKeyDefault() {
contextRunner
.withPropertyValues("spring.aerospike.hosts=localhost:3000")
.withPropertyValues("spring.data.aerospike.namespace=TEST")
.withUserConfiguration(AerospikeClientMockConfiguration.class,
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);
});
}

Expand All @@ -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++");
});
Expand All @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,18 +75,17 @@ public void entityScanShouldSetInitialEntitySet() {
}

@Test
public void typeKeyDefault() {
public void classKeyDefault() {
contextRunner
.withPropertyValues("spring.aerospike.hosts=localhost:3000")
.withPropertyValues("spring.data.aerospike.namespace=TEST")
.withUserConfiguration(AerospikeClientMockConfiguration.class, MockReactiveIndexRefresher.class,
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);
});
}

Expand All @@ -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++");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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> T getField(AerospikeTypeAliasAccessor aliasAccessor, String fieldName) {
Field typeKeyField = ReflectionUtils.findField(AerospikeTypeAliasAccessor.class, fieldName);
public static <T> 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);
}
}

0 comments on commit 33f1158

Please sign in to comment.