diff --git a/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthProperties.java b/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthProperties.java index 6bacafd..88bd17b 100644 --- a/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthProperties.java +++ b/src/main/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthProperties.java @@ -11,6 +11,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConstructorBinding; +import org.springframework.boot.context.properties.bind.DefaultValue; /** * Represents properties for managing pg-index-health-test-starter configuration. @@ -27,7 +28,7 @@ public class DatabaseStructureHealthProperties { */ private final boolean enabled; - public DatabaseStructureHealthProperties(final boolean enabled) { + public DatabaseStructureHealthProperties(@DefaultValue("true") final boolean enabled) { this.enabled = enabled; } diff --git a/src/test/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfigurationTest.java b/src/test/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfigurationTest.java index 4fbb04d..3bfdc4b 100644 --- a/src/test/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfigurationTest.java +++ b/src/test/java/io/github/mfvanek/pg/spring/DatabaseStructureHealthAutoConfigurationTest.java @@ -26,6 +26,14 @@ class DatabaseStructureHealthAutoConfigurationTest extends AutoConfigurationTestBase { + @Test + void propertiesDefaultValueShouldBeUsed() { + assertWithTestConfig() + .run(context -> assertThat(context.getBean(DatabaseStructureHealthProperties.class)) + .isInstanceOf(DatabaseStructureHealthProperties.class) + .satisfies(p -> assertThat(p.isEnabled()).isTrue())); + } + @Test void withoutDataSource() { assertWithTestConfig() @@ -82,10 +90,14 @@ void shouldNotCreateAutoConfigurationWithDisabledProperty() { assertWithTestConfig() .withPropertyValues("pg.index.health.test.enabled=false") .withInitializer(AutoConfigurationTestBase::initialize) - .run(context -> assertThat(context.getBeanDefinitionNames()) - .isNotEmpty() - .filteredOn(beanNamesFilter) - .isEmpty()); + .run(context -> { + assertThat(context.getBeansOfType(DatabaseStructureHealthProperties.class)) + .isEmpty(); + assertThat(context.getBeanDefinitionNames()) + .isNotEmpty() + .filteredOn(beanNamesFilter) + .isEmpty(); + }); } @Test