|
|
|
|
@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
@@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionOutcome; |
|
|
|
|
import org.springframework.boot.test.util.TestPropertyValues; |
|
|
|
|
import org.springframework.context.annotation.ConditionContext; |
|
|
|
|
import org.springframework.core.type.AnnotatedTypeMetadata; |
|
|
|
|
import org.springframework.mock.env.MockEnvironment; |
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
@ -37,40 +38,43 @@ class OnDatabaseInitializationConditionTests {
@@ -37,40 +38,43 @@ class OnDatabaseInitializationConditionTests {
|
|
|
|
|
@Test |
|
|
|
|
void getMatchOutcomeWithPropertyNoSetMatches() { |
|
|
|
|
OnDatabaseInitializationCondition condition = new OnTestDatabaseInitializationCondition("test.init-mode"); |
|
|
|
|
ConditionOutcome outcome = condition |
|
|
|
|
.getMatchOutcome(mockConditionContext(TestPropertyValues.of("test.another", "noise")), null); |
|
|
|
|
ConditionOutcome outcome = condition.getMatchOutcome( |
|
|
|
|
mockConditionContext(TestPropertyValues.of("test.another", "noise")), |
|
|
|
|
mock(AnnotatedTypeMetadata.class)); |
|
|
|
|
assertThat(outcome.isMatch()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void getMatchOutcomeWithPropertySetToAlwaysMatches() { |
|
|
|
|
OnDatabaseInitializationCondition condition = new OnTestDatabaseInitializationCondition("test.init-mode"); |
|
|
|
|
ConditionOutcome outcome = condition |
|
|
|
|
.getMatchOutcome(mockConditionContext(TestPropertyValues.of("test.init-mode=always")), null); |
|
|
|
|
ConditionOutcome outcome = condition.getMatchOutcome( |
|
|
|
|
mockConditionContext(TestPropertyValues.of("test.init-mode=always")), |
|
|
|
|
mock(AnnotatedTypeMetadata.class)); |
|
|
|
|
assertThat(outcome.isMatch()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void getMatchOutcomeWithPropertySetToEmbeddedMatches() { |
|
|
|
|
OnDatabaseInitializationCondition condition = new OnTestDatabaseInitializationCondition("test.init-mode"); |
|
|
|
|
ConditionOutcome outcome = condition |
|
|
|
|
.getMatchOutcome(mockConditionContext(TestPropertyValues.of("test.init-mode=embedded")), null); |
|
|
|
|
ConditionOutcome outcome = condition.getMatchOutcome( |
|
|
|
|
mockConditionContext(TestPropertyValues.of("test.init-mode=embedded")), |
|
|
|
|
mock(AnnotatedTypeMetadata.class)); |
|
|
|
|
assertThat(outcome.isMatch()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void getMatchOutcomeWithPropertySetToNeverDoesNotMatch() { |
|
|
|
|
OnDatabaseInitializationCondition condition = new OnTestDatabaseInitializationCondition("test.init-mode"); |
|
|
|
|
ConditionOutcome outcome = condition |
|
|
|
|
.getMatchOutcome(mockConditionContext(TestPropertyValues.of("test.init-mode=never")), null); |
|
|
|
|
ConditionOutcome outcome = condition.getMatchOutcome( |
|
|
|
|
mockConditionContext(TestPropertyValues.of("test.init-mode=never")), mock(AnnotatedTypeMetadata.class)); |
|
|
|
|
assertThat(outcome.isMatch()).isFalse(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void getMatchOutcomeWithPropertySetToEmptyStringIsIgnored() { |
|
|
|
|
OnDatabaseInitializationCondition condition = new OnTestDatabaseInitializationCondition("test.init-mode"); |
|
|
|
|
ConditionOutcome outcome = condition |
|
|
|
|
.getMatchOutcome(mockConditionContext(TestPropertyValues.of("test.init-mode")), null); |
|
|
|
|
ConditionOutcome outcome = condition.getMatchOutcome( |
|
|
|
|
mockConditionContext(TestPropertyValues.of("test.init-mode")), mock(AnnotatedTypeMetadata.class)); |
|
|
|
|
assertThat(outcome.isMatch()).isTrue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -78,8 +82,9 @@ class OnDatabaseInitializationConditionTests {
@@ -78,8 +82,9 @@ class OnDatabaseInitializationConditionTests {
|
|
|
|
|
void getMatchOutcomeWithMultiplePropertiesUsesFirstSet() { |
|
|
|
|
OnDatabaseInitializationCondition condition = new OnTestDatabaseInitializationCondition("test.init-mode", |
|
|
|
|
"test.schema-mode", "test.init-schema-mode"); |
|
|
|
|
ConditionOutcome outcome = condition |
|
|
|
|
.getMatchOutcome(mockConditionContext(TestPropertyValues.of("test.init-schema-mode=embedded")), null); |
|
|
|
|
ConditionOutcome outcome = condition.getMatchOutcome( |
|
|
|
|
mockConditionContext(TestPropertyValues.of("test.init-schema-mode=embedded")), |
|
|
|
|
mock(AnnotatedTypeMetadata.class)); |
|
|
|
|
assertThat(outcome.isMatch()).isTrue(); |
|
|
|
|
assertThat(outcome.getMessage()).isEqualTo("TestDatabase Initialization test.init-schema-mode is EMBEDDED"); |
|
|
|
|
} |
|
|
|
|
@ -87,15 +92,17 @@ class OnDatabaseInitializationConditionTests {
@@ -87,15 +92,17 @@ class OnDatabaseInitializationConditionTests {
|
|
|
|
|
@Test |
|
|
|
|
void getMatchOutcomeHasDedicatedDescription() { |
|
|
|
|
OnDatabaseInitializationCondition condition = new OnTestDatabaseInitializationCondition("test.init-mode"); |
|
|
|
|
ConditionOutcome outcome = condition |
|
|
|
|
.getMatchOutcome(mockConditionContext(TestPropertyValues.of("test.init-mode=embedded")), null); |
|
|
|
|
ConditionOutcome outcome = condition.getMatchOutcome( |
|
|
|
|
mockConditionContext(TestPropertyValues.of("test.init-mode=embedded")), |
|
|
|
|
mock(AnnotatedTypeMetadata.class)); |
|
|
|
|
assertThat(outcome.getMessage()).isEqualTo("TestDatabase Initialization test.init-mode is EMBEDDED"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void getMatchOutcomeHasWhenPropertyIsNotSetHasDefaultDescription() { |
|
|
|
|
OnDatabaseInitializationCondition condition = new OnTestDatabaseInitializationCondition("test.init-mode"); |
|
|
|
|
ConditionOutcome outcome = condition.getMatchOutcome(mockConditionContext(TestPropertyValues.empty()), null); |
|
|
|
|
ConditionOutcome outcome = condition.getMatchOutcome(mockConditionContext(TestPropertyValues.empty()), |
|
|
|
|
mock(AnnotatedTypeMetadata.class)); |
|
|
|
|
assertThat(outcome.getMessage()).isEqualTo("TestDatabase Initialization default value is EMBEDDED"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|