Skip to content

Commit

Permalink
clean up unit tests, add bootstrap.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
agrgr committed Dec 23, 2024
1 parent fbb09e4 commit 5819f3b
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@
public class AerospikeReactiveDataAutoConfigurationTest {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(AerospikeAutoConfiguration.class))
.withConfiguration(AutoConfigurations.of(AerospikeReactiveDataAutoConfiguration.class))
.withPropertyValues("starters.aerospike.reactive=true");
.withConfiguration(AutoConfigurations.of(AerospikeAutoConfiguration.class,
AerospikeReactiveDataAutoConfiguration.class));

@Test
public void aerospikeTemplateAndClientAreNotSetupWhenNoHostsPropertyGiven() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.boot.aerospike.reactive.data.city.ReactiveCityRepository;
import org.springframework.boot.aerospike.reactive.data.empty.EmptyDataPackage;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -37,9 +38,11 @@
* @author Igor Ermolenko
*/
public class AerospikeReactiveRepositoriesAutoConfigurationTest {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(AerospikeReactiveRepositoriesAutoConfiguration.class,
MockConfiguration.class));
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(AerospikeAutoConfiguration.class,
AerospikeReactiveDataAutoConfiguration.class, AerospikeReactiveRepositoriesAutoConfiguration.class))
.withPropertyValues("spring.aerospike.hosts=localhost:3000")
.withPropertyValues("spring.data.aerospike.namespace=TEST");

@Test
public void reactiveRepositoryIsCreated() {
Expand Down Expand Up @@ -93,23 +96,4 @@ static class DefaultConfiguration {
@TestAutoConfigurationPackage(EmptyDataPackage.class)
static class NoRepositoryConfiguration {
}

@Configuration
static class MockConfiguration {

@Bean
public ReactiveAerospikeTemplate reactiveAerospikeTemplate() {
AerospikeMappingContext context = new AerospikeMappingContext();
ReactiveAerospikeTemplate mock = Mockito.mock(ReactiveAerospikeTemplate.class);
Mockito.when(mock.getMappingContext()).thenReturn((MappingContext) context);
return mock;
}


@Bean
public MappingContext aerospikeMappingContext() {
return Mockito.mock(MappingContext.class);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* value.
*
* @author Phillip Webb
*
* <p>
* Copied from spring-boot project
* https://github.com/spring-projects/spring-boot/issues/6718
*/
Expand All @@ -40,6 +40,5 @@
@Import(TestAutoConfigurationPackageRegistrar.class)
public @interface TestAutoConfigurationPackage {

Class<?> value();

Class<?> value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@
* {@link ImportBeanDefinitionRegistrar} to store the base package for tests.
*
* @author Phillip Webb
*
* <p>
* Copied from spring-boot project
* https://github.com/spring-projects/spring-boot/issues/6718
*/
public class TestAutoConfigurationPackageRegistrar implements ImportBeanDefinitionRegistrar {

@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
AnnotationAttributes attributes = AnnotationAttributes
.fromMap(metadata.getAnnotationAttributes(TestAutoConfigurationPackage.class.getName(), true));
AutoConfigurationPackages.register(registry, ClassUtils.getPackageName(attributes.getString("value")));
}

@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
AnnotationAttributes attributes = AnnotationAttributes
.fromMap(metadata.getAnnotationAttributes(TestAutoConfigurationPackage.class.getName(), true));
AutoConfigurationPackages.register(registry, ClassUtils.getPackageName(attributes.getString("value")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
public class AerospikeDataAutoConfigurationTest {

private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withClassLoader(new FilteredClassLoader(IAerospikeReactorClient.class))
.withConfiguration(AutoConfigurations.of(
AerospikeAutoConfiguration.class, AerospikeDataAutoConfiguration.class));
.withConfiguration(
AutoConfigurations.of(AerospikeAutoConfiguration.class, AerospikeDataAutoConfiguration.class));

@Test
public void aerospikeTemplateAndClientAreNotSetupWhenNoHostsPropertyGiven() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.boot.aerospike.data.city.City;
import org.springframework.boot.aerospike.data.city.CityRepository;
import org.springframework.boot.aerospike.data.empty.EmptyDataPackage;
import org.springframework.boot.autoconfigure.aerospike.AerospikeAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -37,9 +38,11 @@
* @author Igor Ermolenko
*/
public class AerospikeRepositoriesAutoConfigurationTest {
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(AerospikeRepositoriesAutoConfiguration.class,
MockConfiguration.class));
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(AerospikeAutoConfiguration.class,
AerospikeDataAutoConfiguration.class, AerospikeRepositoriesAutoConfiguration.class))
.withPropertyValues("spring.aerospike.hosts=localhost:3000")
.withPropertyValues("spring.data.aerospike.namespace=TEST");

@Test
public void repositoryIsCreated() {
Expand Down Expand Up @@ -93,20 +96,4 @@ static class DefaultConfiguration {
@TestAutoConfigurationPackage(EmptyDataPackage.class)
static class NoRepositoryConfiguration {
}

@Configuration
static class MockConfiguration {
@Bean
public AerospikeTemplate aerospikeTemplate() {
AerospikeMappingContext context = new AerospikeMappingContext();
AerospikeTemplate mock = Mockito.mock(AerospikeTemplate.class);
Mockito.when(mock.getMappingContext()).thenReturn((MappingContext) context);
return mock;
}

@Bean
public MappingContext aerospikeMappingContext() {
return Mockito.mock(MappingContext.class);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* value.
*
* @author Phillip Webb
*
* <p>
* Copied from spring-boot project
* https://github.com/spring-projects/spring-boot/issues/6718
*/
Expand All @@ -36,6 +36,5 @@
@Import(TestAutoConfigurationPackageRegistrar.class)
public @interface TestAutoConfigurationPackage {

Class<?> value();

Class<?> value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
* {@link ImportBeanDefinitionRegistrar} to store the base package for tests.
*
* @author Phillip Webb
*
* <p>
* Copied from spring-boot project
* https://github.com/spring-projects/spring-boot/issues/6718
*/
public class TestAutoConfigurationPackageRegistrar implements ImportBeanDefinitionRegistrar {

@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
AnnotationAttributes attributes = AnnotationAttributes
.fromMap(metadata.getAnnotationAttributes(TestAutoConfigurationPackage.class.getName(), true));
AutoConfigurationPackages.register(registry, ClassUtils.getPackageName(attributes.getString("value")));
}
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
AnnotationAttributes attributes = AnnotationAttributes
.fromMap(metadata.getAnnotationAttributes(TestAutoConfigurationPackage.class.getName(), true));
AutoConfigurationPackages.register(registry, ClassUtils.getPackageName(attributes.getString("value")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#This property is optional, it is added for convenience to quickly disable embedded-aerospike
embedded.containers.enabled=true
embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#This property is optional, it is added for convenience to quickly disable embedded-aerospike
embedded.containers.enabled=true
embedded.containers.enabled=true
embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#This property is optional, it is added for convenience to quickly disable embedded-aerospike
embedded.containers.enabled=true
embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#This property is optional, it is added for convenience to quickly disable embedded-aerospike
embedded.containers.enabled=true
embedded.containers.enabled=true
embedded.aerospike.dockerImage=aerospike/aerospike-server:6.4.0.10

0 comments on commit 5819f3b

Please sign in to comment.