46
46
import org .springframework .boot .jdbc .DataSourceBuilder ;
47
47
import org .springframework .boot .jdbc .SchemaManagement ;
48
48
import org .springframework .boot .orm .jpa .EntityManagerFactoryBuilder ;
49
+ import org .springframework .boot .test .context .assertj .AssertableApplicationContext ;
49
50
import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
51
+ import org .springframework .boot .test .context .runner .ContextConsumer ;
50
52
import org .springframework .boot .test .system .CapturedOutput ;
51
53
import org .springframework .boot .test .system .OutputCaptureExtension ;
52
54
import org .springframework .context .annotation .Bean ;
82
84
* @author Dominic Gunn
83
85
* @author András Deák
84
86
* @author Takaaki Shimbo
87
+ * @author Chris Bono
85
88
*/
86
89
@ ExtendWith (OutputCaptureExtension .class )
87
90
class FlywayAutoConfigurationTests {
@@ -413,34 +416,21 @@ void configurationCustomizersAreConfiguredAndOrdered() {
413
416
@ Test
414
417
void batchIsCorrectlyMapped () {
415
418
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 (validateFlywayTeamsPropertyOnly ("batch" ));
422
420
}
423
421
424
422
@ Test
425
423
void dryRunOutputIsCorrectlyMapped () {
426
424
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 (validateFlywayTeamsPropertyOnly ("dryRunOutput" ));
433
427
}
434
428
435
429
@ Test
436
430
void errorOverridesIsCorrectlyMapped () {
437
431
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 (validateFlywayTeamsPropertyOnly ("errorOverrides" ));
444
434
}
445
435
446
436
@ Test
@@ -453,45 +443,28 @@ void licenseKeyIsCorrectlyMapped(CapturedOutput output) {
453
443
@ Test
454
444
void oracleSqlplusIsCorrectlyMapped () {
455
445
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 (validateFlywayTeamsPropertyOnly ("oracle.sqlplus" ));
462
448
}
463
449
464
450
@ Test
465
451
void oracleSqlplusWarnIsCorrectlyMapped () {
466
452
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 (validateFlywayTeamsPropertyOnly ("oracle.sqlplusWarn" ));
473
455
}
474
456
475
457
@ Test
476
458
void streamIsCorrectlyMapped () {
477
459
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 (validateFlywayTeamsPropertyOnly ("stream" ));
484
461
}
485
462
486
463
@ Test
487
464
void undoSqlMigrationPrefix () {
488
465
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 (validateFlywayTeamsPropertyOnly ("undoSqlMigrationPrefix" ));
495
468
}
496
469
497
470
@ Test
@@ -526,67 +499,77 @@ void initSqlsWithFlywayUrl() {
526
499
@ Test
527
500
void cherryPickIsCorrectlyMapped () {
528
501
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" ).run (validateFlywayTeamsPropertyOnly ("cherryPick" ));
535
503
}
536
504
537
505
@ Test
538
506
void jdbcPropertiesAreCorrectlyMapped () {
539
507
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
- });
508
+ .withPropertyValues ("spring.flyway.jdbc-properties.prop=value" )
509
+ .run (validateFlywayTeamsPropertyOnly ("jdbcProperties" ));
546
510
}
547
511
548
512
@ Test
549
513
void oracleKerberosCacheFileIsCorrectlyMapped () {
550
514
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
- });
515
+ .withPropertyValues ("spring.flyway.oracle-kerberos-cache-file=/tmp/cache" )
516
+ .run (validateFlywayTeamsPropertyOnly ("oracle.kerberosCacheFile" ));
557
517
}
558
518
559
519
@ Test
560
520
void oracleKerberosConfigFileIsCorrectlyMapped () {
561
521
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
- });
522
+ .withPropertyValues ("spring.flyway.oracle-kerberos-config-file=/tmp/config" )
523
+ .run (validateFlywayTeamsPropertyOnly ("oracle.kerberosConfigFile" ));
568
524
}
569
525
570
526
@ Test
571
527
void outputQueryResultsIsCorrectlyMapped () {
572
528
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
- });
529
+ .withPropertyValues ("spring.flyway.output-query-results=false" )
530
+ .run (validateFlywayTeamsPropertyOnly ("outputQueryResults" ));
579
531
}
580
532
581
533
@ Test
582
534
void skipExecutingMigrationsIsCorrectlyMapped () {
583
535
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
- });
536
+ .withPropertyValues ("spring.flyway.skip-executing-migrations=true" )
537
+ .run (validateFlywayTeamsPropertyOnly ("skipExecutingMigrations" ));
538
+ }
539
+
540
+ @ Test
541
+ void conjurUrlIsCorrectlyMapped () {
542
+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
543
+ .withPropertyValues ("spring.flyway.conjur-url=http://foo.com/secrets" )
544
+ .run (validateFlywayTeamsPropertyOnly ("conjurUrl" ));
545
+ }
546
+
547
+ @ Test
548
+ void conjurTokenIsCorrectlyMapped () {
549
+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
550
+ .withPropertyValues ("spring.flyway.conjur-token=5150" )
551
+ .run (validateFlywayTeamsPropertyOnly ("conjurToken" ));
552
+ }
553
+
554
+ @ Test
555
+ void vaultUrlIsCorrectlyMapped () {
556
+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
557
+ .withPropertyValues ("spring.flyway.vault-url=http://foo.com/secrets" )
558
+ .run (validateFlywayTeamsPropertyOnly ("vaultUrl" ));
559
+ }
560
+
561
+ @ Test
562
+ void vaultTokenIsCorrectlyMapped () {
563
+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
564
+ .withPropertyValues ("spring.flyway.vault-token=5150" )
565
+ .run (validateFlywayTeamsPropertyOnly ("vaultToken" ));
566
+ }
567
+
568
+ @ Test
569
+ void vaultSecretsIsCorrectlyMapped () {
570
+ this .contextRunner .withUserConfiguration (EmbeddedDataSourceConfiguration .class )
571
+ .withPropertyValues ("spring.flyway.vault-secrets=kv/data/test/1/config,kv/data/test/2/config" )
572
+ .run (validateFlywayTeamsPropertyOnly ("vaultSecrets" ));
590
573
}
591
574
592
575
@ Test
@@ -616,6 +599,15 @@ void whenCustomFlywayIsDefinedThenJooqDslContextDependsOnIt() {
616
599
});
617
600
}
618
601
602
+ private ContextConsumer <AssertableApplicationContext > validateFlywayTeamsPropertyOnly (String propertyName ) {
603
+ return (context ) -> {
604
+ assertThat (context ).hasFailed ();
605
+ Throwable failure = context .getStartupFailure ();
606
+ assertThat (failure ).hasRootCauseInstanceOf (FlywayTeamsUpgradeRequiredException .class );
607
+ assertThat (failure ).hasMessageContaining (String .format (" %s " , propertyName ));
608
+ };
609
+ }
610
+
619
611
@ Configuration (proxyBeanMethods = false )
620
612
static class FlywayDataSourceConfiguration {
621
613
0 commit comments