1- // SPDX-FileCopyrightText: Copyright 2021-2025 Mark Rotteveel
1+ // SPDX-FileCopyrightText: Copyright 2021-2026 Mark Rotteveel
22// SPDX-License-Identifier: LGPL-2.1-or-later
33package org .firebirdsql .jdbc ;
44
55import org .firebirdsql .common .FBTestProperties ;
66import org .firebirdsql .common .extension .UsesDatabaseExtension ;
77import org .firebirdsql .ds .FBSimpleDataSource ;
88import org .firebirdsql .gds .impl .GDSFactory ;
9- import org .firebirdsql .jaybird .props .PropertyConstants ;
109import org .firebirdsql .jaybird .props .PropertyNames ;
1110import org .firebirdsql .util .FirebirdSupportInfo ;
1211import org .junit .jupiter .api .extension .RegisterExtension ;
2019import java .util .List ;
2120import java .util .Locale ;
2221import java .util .Properties ;
23- import java .util .stream .Collectors ;
2422import java .util .stream .Stream ;
2523
2624import static org .firebirdsql .common .FBTestProperties .*;
@@ -47,7 +45,7 @@ void testConnectionWithDriverManager(String url) throws Exception {
4745 @ SuppressWarnings ("unused" )
4846 static Stream <Arguments > testConnectionWithDriverManager () {
4947 final List <String > urlPrefixes = GDSFactory .getPlugin (FBTestProperties .getGdsType ()).getSupportedProtocolList ();
50- final List <String > urls = urlsWithoutProtocolPrefix ();
48+ final List <String > urls = urlsWithoutProtocolPrefix (). toList () ;
5149
5250 return urlPrefixes .stream ()
5351 .flatMap (urlPrefix -> urls .stream ()
@@ -62,9 +60,12 @@ static Stream<Arguments> testConnectionWithDriverManager() {
6260 @ MethodSource
6361 void testConnectionWithEmptyUrl (String url ) throws Exception {
6462 Properties properties = FBTestProperties .getDefaultPropertiesForConnection ();
65- properties .put (PropertyNames .databaseName , getDatabasePath ());
63+ String databaseName = isEmbeddedType ().matches (GDS_TYPE ) || (isLocalhost () && isDefaultPort ())
64+ ? getDatabasePath ()
65+ : getdbpath (DB_NAME );
66+ properties .put (PropertyNames .databaseName , databaseName );
6667
67- try (Connection connection = DriverManager .getConnection (url , properties )) {
68+ try (var connection = DriverManager .getConnection (url , properties )) {
6869 assertTrue (connection .isValid (1000 ));
6970 }
7071 }
@@ -97,35 +98,34 @@ void testConnectionWithSimpleDataSource(String serverName, Integer portNumber, S
9798 @ SuppressWarnings ("unused" )
9899 static Stream <Arguments > testConnectionWithSimpleDataSource () {
99100 return Stream .concat (
100- urlsWithoutProtocolPrefix (). stream ()
101+ urlsWithoutProtocolPrefix ()
101102 // URLS with a question mark are only for JDBC url test
102103 .filter (url -> url .indexOf ('?' ) == -1 )
103104 .map (url -> Arguments .of (null , null , url )),
104105 Stream .of (Arguments .of (DB_SERVER_URL , DB_SERVER_PORT , FBTestProperties .getDatabasePath ())));
105106 }
106107
107- private static List <String > urlsWithoutProtocolPrefix () {
108+ private static Stream <String > urlsWithoutProtocolPrefix () {
108109 final String databasePath = getDatabasePath ();
109110 final String serverName = DB_SERVER_URL ;
110111 final boolean localhost = isLocalhost ();
111112 final String ipv6SafeServerName = serverName .indexOf (':' ) != -1 ? '[' + serverName + ']' : serverName ;
112- final int portNumber = DB_SERVER_PORT ;
113113 final String gdsTypeName = GDS_TYPE ;
114114 final List <String > urlFormats = new ArrayList <>();
115115 if (isEmbeddedType ().matches (gdsTypeName )) {
116116 // file path only
117117 urlFormats .add ("%3$s" );
118118 urlFormats .add ("nopath?databaseName=%3$s" );
119119 } else {
120- urlFormats .add ("///%3$s" );
121120 urlFormats .add ("%1$s/%2$d:%3$s" );
122121 urlFormats .add ("//%1$s:%2$d/%3$s" );
123- if (portNumber == PropertyConstants . DEFAULT_PORT ) {
122+ if (isDefaultPort () ) {
124123 urlFormats .add ("%1$s:%3$s" );
125124 urlFormats .add ("//%1$s/%3$s" );
126125 if (localhost ) {
127126 // no hostname + port:
128127 urlFormats .add ("%3$s" );
128+ urlFormats .add ("///%3$s" );
129129 }
130130 }
131131
@@ -167,8 +167,8 @@ private static List<String> urlsWithoutProtocolPrefix() {
167167 }
168168
169169 return urlFormats .stream ()
170- .map (urlFormat -> String . format ( urlFormat , ipv6SafeServerName , portNumber , databasePath , serverName ))
171- . collect ( Collectors . toList ( ));
170+ .map (urlFormat ->
171+ urlFormat . formatted ( ipv6SafeServerName , DB_SERVER_PORT , databasePath , serverName ));
172172 }
173173
174174 private static boolean isWindowsSystem () {
0 commit comments