4646import org .springframework .boot .jdbc .DataSourceBuilder ;
4747import org .springframework .boot .jdbc .SchemaManagement ;
4848import org .springframework .boot .orm .jpa .EntityManagerFactoryBuilder ;
49+ import org .springframework .boot .test .context .assertj .AssertableApplicationContext ;
4950import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
51+ import org .springframework .boot .test .context .runner .ContextConsumer ;
5052import org .springframework .boot .test .system .CapturedOutput ;
5153import org .springframework .boot .test .system .OutputCaptureExtension ;
5254import org .springframework .context .annotation .Bean ;
8284 * @author Dominic Gunn
8385 * @author András Deák
8486 * @author Takaaki Shimbo
87+ * @author Chris Bono
8588 */
8689@ ExtendWith (OutputCaptureExtension .class )
8790class FlywayAutoConfigurationTests {
@@ -413,34 +416,21 @@ void configurationCustomizersAreConfiguredAndOrdered() {
413416 @ Test
414417 void batchIsCorrectlyMapped () {
415418 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
416- .withPropertyValues ("spring.flyway.batch=true" ).run ((context ) -> {
417- assertThat (context ).hasFailed ();
418- Throwable failure = context .getStartupFailure ();
419- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
420- assertThat (failure ).hasMessageContaining (" batch " );
421- });
419+ .withPropertyValues ("spring.flyway.batch=true" ).run (validateTeamsPropertyCorrectlyMapped ("batch" ));
422420 }
423421
424422 @ Test
425423 void dryRunOutputIsCorrectlyMapped () {
426424 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
427- .withPropertyValues ("spring.flyway.dryRunOutput=dryrun.sql" ).run ((context ) -> {
428- assertThat (context ).hasFailed ();
429- Throwable failure = context .getStartupFailure ();
430- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
431- assertThat (failure ).hasMessageContaining (" dryRunOutput " );
432- });
425+ .withPropertyValues ("spring.flyway.dryRunOutput=dryrun.sql" )
426+ .run (validateTeamsPropertyCorrectlyMapped ("dryRunOutput" ));
433427 }
434428
435429 @ Test
436430 void errorOverridesIsCorrectlyMapped () {
437431 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
438- .withPropertyValues ("spring.flyway.errorOverrides=D12345" ).run ((context ) -> {
439- assertThat (context ).hasFailed ();
440- Throwable failure = context .getStartupFailure ();
441- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
442- assertThat (failure ).hasMessageContaining (" errorOverrides " );
443- });
432+ .withPropertyValues ("spring.flyway.errorOverrides=D12345" )
433+ .run (validateTeamsPropertyCorrectlyMapped ("errorOverrides" ));
444434 }
445435
446436 @ Test
@@ -453,45 +443,28 @@ void licenseKeyIsCorrectlyMapped(CapturedOutput output) {
453443 @ Test
454444 void oracleSqlplusIsCorrectlyMapped () {
455445 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
456- .withPropertyValues ("spring.flyway.oracle-sqlplus=true" ).run ((context ) -> {
457- assertThat (context ).hasFailed ();
458- Throwable failure = context .getStartupFailure ();
459- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
460- assertThat (failure ).hasMessageContaining (" oracle.sqlplus " );
461- });
446+ .withPropertyValues ("spring.flyway.oracle-sqlplus=true" )
447+ .run (validateTeamsPropertyCorrectlyMapped ("oracle.sqlplus" ));
462448 }
463449
464450 @ Test
465451 void oracleSqlplusWarnIsCorrectlyMapped () {
466452 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
467- .withPropertyValues ("spring.flyway.oracle-sqlplus-warn=true" ).run ((context ) -> {
468- assertThat (context ).hasFailed ();
469- Throwable failure = context .getStartupFailure ();
470- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
471- assertThat (failure ).hasMessageContaining (" oracle.sqlplusWarn " );
472- });
453+ .withPropertyValues ("spring.flyway.oracle-sqlplus-warn=true" )
454+ .run (validateTeamsPropertyCorrectlyMapped ("oracle.sqlplusWarn" ));
473455 }
474456
475457 @ Test
476458 void streamIsCorrectlyMapped () {
477459 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
478- .withPropertyValues ("spring.flyway.stream=true" ).run ((context ) -> {
479- assertThat (context ).hasFailed ();
480- Throwable failure = context .getStartupFailure ();
481- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
482- assertThat (failure ).hasMessageContaining (" stream " );
483- });
460+ .withPropertyValues ("spring.flyway.stream=true" ).run (validateTeamsPropertyCorrectlyMapped ("stream" ));
484461 }
485462
486463 @ Test
487464 void undoSqlMigrationPrefix () {
488465 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
489- .withPropertyValues ("spring.flyway.undo-sql-migration-prefix=undo" ).run ((context ) -> {
490- assertThat (context ).hasFailed ();
491- Throwable failure = context .getStartupFailure ();
492- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
493- assertThat (failure ).hasMessageContaining (" undoSqlMigrationPrefix " );
494- });
466+ .withPropertyValues ("spring.flyway.undo-sql-migration-prefix=undo" )
467+ .run (validateTeamsPropertyCorrectlyMapped ("undoSqlMigrationPrefix" ));
495468 }
496469
497470 @ Test
@@ -526,67 +499,78 @@ void initSqlsWithFlywayUrl() {
526499 @ Test
527500 void cherryPickIsCorrectlyMapped () {
528501 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
529- .withPropertyValues ("spring.flyway.cherry-pick=1.1" ).run ((context ) -> {
530- assertThat (context ).hasFailed ();
531- Throwable failure = context .getStartupFailure ();
532- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
533- assertThat (failure ).hasMessageContaining (" cherryPick " );
534- });
502+ .withPropertyValues ("spring.flyway.cherry-pick=1.1" )
503+ .run (validateTeamsPropertyCorrectlyMapped ("cherryPick" ));
535504 }
536505
537506 @ Test
538507 void jdbcPropertiesAreCorrectlyMapped () {
539508 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
540- .withPropertyValues ("spring.flyway.jdbc-properties.prop=value" ).run ((context ) -> {
541- assertThat (context ).hasFailed ();
542- Throwable failure = context .getStartupFailure ();
543- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
544- assertThat (failure ).hasMessageContaining (" jdbcProperties " );
545- });
509+ .withPropertyValues ("spring.flyway.jdbc-properties.prop=value" )
510+ .run (validateTeamsPropertyCorrectlyMapped ("jdbcProperties" ));
546511 }
547512
548513 @ Test
549514 void oracleKerberosCacheFileIsCorrectlyMapped () {
550515 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
551- .withPropertyValues ("spring.flyway.oracle-kerberos-cache-file=/tmp/cache" ).run ((context ) -> {
552- assertThat (context ).hasFailed ();
553- Throwable failure = context .getStartupFailure ();
554- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
555- assertThat (failure ).hasMessageContaining (" oracle.kerberosCacheFile " );
556- });
516+ .withPropertyValues ("spring.flyway.oracle-kerberos-cache-file=/tmp/cache" )
517+ .run (validateTeamsPropertyCorrectlyMapped ("oracle.kerberosCacheFile" ));
557518 }
558519
559520 @ Test
560521 void oracleKerberosConfigFileIsCorrectlyMapped () {
561522 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
562- .withPropertyValues ("spring.flyway.oracle-kerberos-config-file=/tmp/config" ).run ((context ) -> {
563- assertThat (context ).hasFailed ();
564- Throwable failure = context .getStartupFailure ();
565- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
566- assertThat (failure ).hasMessageContaining (" oracle.kerberosConfigFile " );
567- });
523+ .withPropertyValues ("spring.flyway.oracle-kerberos-config-file=/tmp/config" )
524+ .run (validateTeamsPropertyCorrectlyMapped ("oracle.kerberosConfigFile" ));
568525 }
569526
570527 @ Test
571528 void outputQueryResultsIsCorrectlyMapped () {
572529 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
573- .withPropertyValues ("spring.flyway.output-query-results=false" ).run ((context ) -> {
574- assertThat (context ).hasFailed ();
575- Throwable failure = context .getStartupFailure ();
576- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
577- assertThat (failure ).hasMessageContaining (" outputQueryResults " );
578- });
530+ .withPropertyValues ("spring.flyway.output-query-results=false" )
531+ .run (validateTeamsPropertyCorrectlyMapped ("outputQueryResults" ));
579532 }
580533
581534 @ Test
582535 void skipExecutingMigrationsIsCorrectlyMapped () {
583536 this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
584- .withPropertyValues ("spring.flyway.skip-executing-migrations=true" ).run ((context ) -> {
585- assertThat (context ).hasFailed ();
586- Throwable failure = context .getStartupFailure ();
587- assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
588- assertThat (failure ).hasMessageContaining (" skipExecutingMigrations " );
589- });
537+ .withPropertyValues ("spring.flyway.skip-executing-migrations=true" )
538+ .run (validateTeamsPropertyCorrectlyMapped ("skipExecutingMigrations" ));
539+ }
540+
541+ @ Test
542+ void conjurUrlIsCorrectlyMapped () {
543+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
544+ .withPropertyValues ("spring.flyway.conjur-url=http://foo.com/secrets" )
545+ .run (validateTeamsPropertyCorrectlyMapped ("conjurUrl" ));
546+ }
547+
548+ @ Test
549+ void conjurTokenIsCorrectlyMapped () {
550+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
551+ .withPropertyValues ("spring.flyway.conjur-token=5150" )
552+ .run (validateTeamsPropertyCorrectlyMapped ("conjurToken" ));
553+ }
554+
555+ @ Test
556+ void vaultUrlIsCorrectlyMapped () {
557+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
558+ .withPropertyValues ("spring.flyway.vault-url=http://foo.com/secrets" )
559+ .run (validateTeamsPropertyCorrectlyMapped ("vaultUrl" ));
560+ }
561+
562+ @ Test
563+ void vaultTokenIsCorrectlyMapped () {
564+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
565+ .withPropertyValues ("spring.flyway.vault-token=5150" )
566+ .run (validateTeamsPropertyCorrectlyMapped ("vaultToken" ));
567+ }
568+
569+ @ Test
570+ void vaultSecretsIsCorrectlyMapped () {
571+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
572+ .withPropertyValues ("spring.flyway.vault-secrets=kv/test/1/config,kv/test/2/config" )
573+ .run (validateTeamsPropertyCorrectlyMapped ("vaultSecrets" ));
590574 }
591575
592576 @ Test
@@ -616,6 +600,15 @@ void whenCustomFlywayIsDefinedThenJooqDslContextDependsOnIt() {
616600 });
617601 }
618602
603+ private ContextConsumer <AssertableApplicationContext > validateTeamsPropertyCorrectlyMapped (String propertyName ) {
604+ return (context ) -> {
605+ assertThat (context ).hasFailed ();
606+ Throwable failure = context .getStartupFailure ();
607+ assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
608+ assertThat (failure ).hasMessageContaining (String .format (" %s " , propertyName ));
609+ };
610+ }
611+
619612 @ Configuration (proxyBeanMethods = false )
620613 static class FlywayDataSourceConfiguration {
621614
0 commit comments