88import java .sql .Types ;
99
1010import org .junit .jupiter .api .Assertions ;
11- import org .junit .jupiter .api .Test ;
1211import org .junit .jupiter .api .extension .RegisterExtension ;
12+ import org .junit .jupiter .params .ParameterizedTest ;
13+ import org .junit .jupiter .params .provider .EnumSource ;
1314
1415import tech .ydb .test .junit5 .YdbHelperExtension ;
1516
@@ -21,23 +22,10 @@ public class YdbDriverExampleTest {
2122 @ RegisterExtension
2223 private static final YdbHelperExtension ydb = new YdbHelperExtension ();
2324
24- private static String jdbcURL () {
25- StringBuilder jdbc = new StringBuilder ("jdbc:ydb:" )
26- .append (ydb .useTls () ? "grpcs://" : "grpc://" )
27- .append (ydb .endpoint ())
28- .append ("/?database=" )
29- .append (ydb .database ());
30-
31- if (ydb .authToken () != null ) {
32- jdbc .append ("&" ).append ("token=" ).append (ydb .authToken ());
33- }
34-
35- return jdbc .toString ();
36- }
37-
38- @ Test
39- public void testYdb () throws SQLException {
40- try (Connection connection = DriverManager .getConnection (jdbcURL ())) {
25+ @ ParameterizedTest
26+ @ EnumSource (Mode .class )
27+ public void testYdb (Mode mode ) throws SQLException {
28+ try (Connection connection = DriverManager .getConnection (mode .getJdbcURL ())) {
4129 try {
4230 connection .createStatement ()
4331 .execute ("drop table table_sample" );
@@ -148,9 +136,10 @@ public void testYdb() throws SQLException {
148136 }
149137 }
150138
151- @ Test
152- public void testYdbNotNull () throws SQLException {
153- try (Connection connection = DriverManager .getConnection (jdbcURL ())) {
139+ @ ParameterizedTest
140+ @ EnumSource (Mode .class )
141+ public void testYdbNotNull (Mode mode ) throws SQLException {
142+ try (Connection connection = DriverManager .getConnection (mode .getJdbcURL ())) {
154143 try {
155144 connection .createStatement ().execute ("drop table table_sample" );
156145 } catch (SQLException e ) {
@@ -249,4 +238,57 @@ public void testYdbNotNull() throws SQLException {
249238 }
250239 }
251240 }
241+
242+ private enum Mode {
243+ BASE {
244+ @ Override
245+ String getJdbcURL () {
246+ StringBuilder jdbc = new StringBuilder ("jdbc:ydb:" )
247+ .append (ydb .useTls () ? "grpcs://" : "grpc://" )
248+ .append (ydb .endpoint ())
249+ .append ("/" )
250+ .append (ydb .database ());
251+
252+ if (ydb .authToken () != null ) {
253+ jdbc .append ("?" ).append ("token=" ).append (ydb .authToken ());
254+ }
255+
256+ return jdbc .toString ();
257+ }
258+ },
259+ OLD_STYLE {
260+ @ Override
261+ String getJdbcURL () {
262+ StringBuilder jdbc = new StringBuilder ("jdbc:ydb:" )
263+ .append (ydb .useTls () ? "grpcs://" : "grpc://" )
264+ .append (ydb .endpoint ())
265+ .append ("/?database=" )
266+ .append (ydb .database ());
267+
268+ if (ydb .authToken () != null ) {
269+ jdbc .append ("&" ).append ("token=" ).append (ydb .authToken ());
270+ }
271+
272+ return jdbc .toString ();
273+ }
274+ },
275+ NO_DISCOVERY {
276+ @ Override
277+ String getJdbcURL () {
278+ StringBuilder jdbc = new StringBuilder ("jdbc:ydb:" )
279+ .append (ydb .useTls () ? "grpcs://" : "grpc://" )
280+ .append (ydb .endpoint ())
281+ .append (ydb .database ())
282+ .append ("?useDiscovery=false" );
283+
284+ if (ydb .authToken () != null ) {
285+ jdbc .append ("&" ).append ("token=" ).append (ydb .authToken ());
286+ }
287+
288+ return jdbc .toString ();
289+ }
290+ };
291+
292+ abstract String getJdbcURL ();
293+ }
252294}
0 commit comments