1
1
/*
2
- * Copyright 2012-2023 the original author or authors.
2
+ * Copyright 2012-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -458,8 +458,8 @@ void buildWhenDerivedFromCustomTypeWithTypeChange() {
458
458
}
459
459
460
460
@ Test
461
- void buildWhenDerivedFromCustomTypeDeriveDriverClassNameFromDerivedUrl () {
462
- UrlCapableLimitedCustomDataSource dataSource = new UrlCapableLimitedCustomDataSource ();
461
+ void buildWhenDerivedFromCustomTypeDeriveDriverClassNameFromUrl () {
462
+ NoDriverClassNameDataSource dataSource = new NoDriverClassNameDataSource ();
463
463
dataSource .setUsername ("test" );
464
464
dataSource .setPassword ("secret" );
465
465
dataSource .setUrl ("jdbc:postgresql://localhost:5432/postgres" );
@@ -471,6 +471,22 @@ void buildWhenDerivedFromCustomTypeDeriveDriverClassNameFromDerivedUrl() {
471
471
assertThat (testSource .getDriver ()).isInstanceOf (org .postgresql .Driver .class );
472
472
}
473
473
474
+ @ Test
475
+ void buildWhenDerivedFromCustomTypeDeriveDriverClassNameFromOverridenUrl () {
476
+ NoDriverClassNameDataSource dataSource = new NoDriverClassNameDataSource ();
477
+ dataSource .setUsername ("test" );
478
+ dataSource .setPassword ("secret" );
479
+ dataSource .setUrl ("jdbc:mysql://localhost:5432/mysql" );
480
+ DataSourceBuilder <?> builder = DataSourceBuilder .derivedFrom (dataSource )
481
+ .type (SimpleDriverDataSource .class )
482
+ .url ("jdbc:mariadb://localhost:5432/mariadb" );
483
+ SimpleDriverDataSource testSource = (SimpleDriverDataSource ) builder .build ();
484
+ assertThat (testSource .getUsername ()).isEqualTo ("test" );
485
+ assertThat (testSource .getUrl ()).isEqualTo ("jdbc:mariadb://localhost:5432/mariadb" );
486
+ assertThat (testSource .getPassword ()).isEqualTo ("secret" );
487
+ assertThat (testSource .getDriver ()).isInstanceOf (org .mariadb .jdbc .Driver .class );
488
+ }
489
+
474
490
@ Test // gh-31920
475
491
void buildWhenC3P0TypeSpecifiedReturnsExpectedDataSource () {
476
492
this .dataSource = DataSourceBuilder .create ()
@@ -634,7 +650,7 @@ void setPassword(String password) {
634
650
635
651
}
636
652
637
- static class UrlCapableLimitedCustomDataSource extends LimitedCustomDataSource {
653
+ static class NoDriverClassNameDataSource extends LimitedCustomDataSource {
638
654
639
655
private String url ;
640
656
@@ -648,10 +664,11 @@ void setUrl(String url) {
648
664
649
665
}
650
666
651
- static class CustomDataSource extends UrlCapableLimitedCustomDataSource {
667
+ static class CustomDataSource extends LimitedCustomDataSource {
652
668
653
669
private String driverClassName ;
654
670
671
+ private String url ;
655
672
656
673
String getDriverClassName () {
657
674
return this .driverClassName ;
@@ -661,6 +678,14 @@ void setDriverClassName(String driverClassName) {
661
678
this .driverClassName = driverClassName ;
662
679
}
663
680
681
+ String getUrl () {
682
+ return this .url ;
683
+ }
684
+
685
+ void setUrl (String url ) {
686
+ this .url = url ;
687
+ }
688
+
664
689
}
665
690
666
691
}
0 commit comments