|
1 | 1 | package org.testcontainers.jdbc; |
2 | 2 |
|
3 | | -import org.junit.Test; |
4 | | -import org.junit.runner.RunWith; |
5 | | -import org.junit.runners.Parameterized; |
6 | | -import org.junit.runners.Parameterized.Parameter; |
| 3 | +import org.junit.jupiter.params.ParameterizedTest; |
| 4 | +import org.junit.jupiter.params.provider.Arguments; |
| 5 | +import org.junit.jupiter.params.provider.MethodSource; |
7 | 6 |
|
8 | | -import java.util.Arrays; |
9 | 7 | import java.util.Optional; |
| 8 | +import java.util.stream.Stream; |
10 | 9 |
|
11 | 10 | import static org.assertj.core.api.Assertions.assertThat; |
12 | 11 |
|
13 | 12 | /** |
14 | 13 | * This Test class validates that all supported JDBC URL's can be parsed by ConnectionUrl class. |
15 | 14 | */ |
16 | | -@RunWith(Parameterized.class) |
17 | | -public class ConnectionUrlDriversTests { |
| 15 | +class ConnectionUrlDriversTests { |
18 | 16 |
|
19 | | - @Parameter |
20 | | - public String jdbcUrl; |
21 | | - |
22 | | - @Parameter(1) |
23 | | - public String databaseType; |
24 | | - |
25 | | - @Parameter(2) |
26 | | - public Optional<String> tag; |
27 | | - |
28 | | - @Parameter(3) |
29 | | - public String dbHostString; |
30 | | - |
31 | | - @Parameter(4) |
32 | | - public String databaseName; |
33 | | - |
34 | | - @Parameterized.Parameters(name = "{index} - {0}") |
35 | | - public static Iterable<Object[]> data() { |
36 | | - return Arrays.asList( |
37 | | - new Object[][] { |
38 | | - { "jdbc:tc:mysql:8.0.36://hostname/test", "mysql", Optional.of("8.0.36"), "hostname/test", "test" }, |
39 | | - { "jdbc:tc:mysql://hostname/test", "mysql", Optional.empty(), "hostname/test", "test" }, |
40 | | - { |
41 | | - "jdbc:tc:postgresql:1.2.3://hostname/test", |
42 | | - "postgresql", |
43 | | - Optional.of("1.2.3"), |
44 | | - "hostname/test", |
45 | | - "test", |
46 | | - }, |
47 | | - { "jdbc:tc:postgresql://hostname/test", "postgresql", Optional.empty(), "hostname/test", "test" }, |
48 | | - { |
49 | | - "jdbc:tc:sqlserver:1.2.3://localhost;instance=SQLEXPRESS:1433;databaseName=test", |
50 | | - "sqlserver", |
51 | | - Optional.of("1.2.3"), |
52 | | - "localhost;instance=SQLEXPRESS:1433;databaseName=test", |
53 | | - "test", |
54 | | - }, |
55 | | - { |
56 | | - "jdbc:tc:sqlserver://localhost;instance=SQLEXPRESS:1433;databaseName=test", |
57 | | - "sqlserver", |
58 | | - Optional.empty(), |
59 | | - "localhost;instance=SQLEXPRESS:1433;databaseName=test", |
60 | | - "test", |
61 | | - }, |
62 | | - { |
63 | | - "jdbc:tc:mariadb:1.2.3://localhost:3306/test", |
64 | | - "mariadb", |
65 | | - Optional.of("1.2.3"), |
66 | | - "localhost:3306/test", |
67 | | - "test", |
68 | | - }, |
69 | | - { "jdbc:tc:mariadb://localhost:3306/test", "mariadb", Optional.empty(), "localhost:3306/test", "test" }, |
70 | | - { |
71 | | - "jdbc:tc:oracle:1.2.3:thin://@localhost:1521/test", |
72 | | - "oracle", |
73 | | - Optional.of("1.2.3"), |
74 | | - "localhost:1521/test", |
75 | | - "test", |
76 | | - }, |
77 | | - { |
78 | | - "jdbc:tc:oracle:1.2.3:thin:@localhost:1521/test", |
79 | | - "oracle", |
80 | | - Optional.of("1.2.3"), |
81 | | - "localhost:1521/test", |
82 | | - "test", |
83 | | - }, |
84 | | - { |
85 | | - "jdbc:tc:oracle:thin:@localhost:1521/test", |
86 | | - "oracle", |
87 | | - Optional.empty(), |
88 | | - "localhost:1521/test", |
89 | | - "test", |
90 | | - }, |
91 | | - { |
92 | | - "jdbc:tc:oracle:1.2.3:thin:@localhost:1521:test", |
93 | | - "oracle", |
94 | | - Optional.of("1.2.3"), |
95 | | - "localhost:1521:test", |
96 | | - "test", |
97 | | - }, |
98 | | - { |
99 | | - "jdbc:tc:oracle:1.2.3:thin://@localhost:1521:test", |
100 | | - "oracle", |
101 | | - Optional.of("1.2.3"), |
102 | | - "localhost:1521:test", |
103 | | - "test", |
104 | | - }, |
105 | | - { |
106 | | - "jdbc:tc:oracle:1.2.3-anything:thin://@localhost:1521:test", |
107 | | - "oracle", |
108 | | - Optional.of("1.2.3-anything"), |
109 | | - "localhost:1521:test", |
110 | | - "test", |
111 | | - }, |
112 | | - { |
113 | | - "jdbc:tc:oracle:thin:@localhost:1521:test", |
114 | | - "oracle", |
115 | | - Optional.empty(), |
116 | | - "localhost:1521:test", |
117 | | - "test", |
118 | | - }, |
119 | | - } |
| 17 | + public static Stream<Arguments> data() { |
| 18 | + return Stream.of( |
| 19 | + Arguments.arguments( |
| 20 | + "jdbc:tc:mysql:8.0.36://hostname/test", |
| 21 | + "mysql", |
| 22 | + Optional.of("8.0.36"), |
| 23 | + "hostname/test", |
| 24 | + "test" |
| 25 | + ), |
| 26 | + Arguments.arguments("jdbc:tc:mysql://hostname/test", "mysql", Optional.empty(), "hostname/test", "test"), |
| 27 | + Arguments.arguments( |
| 28 | + "jdbc:tc:postgresql:1.2.3://hostname/test", |
| 29 | + "postgresql", |
| 30 | + Optional.of("1.2.3"), |
| 31 | + "hostname/test", |
| 32 | + "test" |
| 33 | + ), |
| 34 | + Arguments.arguments( |
| 35 | + "jdbc:tc:postgresql://hostname/test", |
| 36 | + "postgresql", |
| 37 | + Optional.empty(), |
| 38 | + "hostname/test", |
| 39 | + "test" |
| 40 | + ), |
| 41 | + Arguments.arguments( |
| 42 | + "jdbc:tc:sqlserver:1.2.3://localhost;instance=SQLEXPRESS:1433;databaseName=test", |
| 43 | + "sqlserver", |
| 44 | + Optional.of("1.2.3"), |
| 45 | + "localhost;instance=SQLEXPRESS:1433;databaseName=test", |
| 46 | + "test" |
| 47 | + ), |
| 48 | + Arguments.arguments( |
| 49 | + "jdbc:tc:sqlserver://localhost;instance=SQLEXPRESS:1433;databaseName=test", |
| 50 | + "sqlserver", |
| 51 | + Optional.empty(), |
| 52 | + "localhost;instance=SQLEXPRESS:1433;databaseName=test", |
| 53 | + "test" |
| 54 | + ), |
| 55 | + Arguments.arguments( |
| 56 | + "jdbc:tc:mariadb:1.2.3://localhost:3306/test", |
| 57 | + "mariadb", |
| 58 | + Optional.of("1.2.3"), |
| 59 | + "localhost:3306/test", |
| 60 | + "test" |
| 61 | + ), |
| 62 | + Arguments.arguments( |
| 63 | + "jdbc:tc:mariadb://localhost:3306/test", |
| 64 | + "mariadb", |
| 65 | + Optional.empty(), |
| 66 | + "localhost:3306/test", |
| 67 | + "test" |
| 68 | + ), |
| 69 | + Arguments.arguments( |
| 70 | + "jdbc:tc:oracle:1.2.3:thin://@localhost:1521/test", |
| 71 | + "oracle", |
| 72 | + Optional.of("1.2.3"), |
| 73 | + "localhost:1521/test", |
| 74 | + "test" |
| 75 | + ), |
| 76 | + Arguments.arguments( |
| 77 | + "jdbc:tc:oracle:1.2.3:thin:@localhost:1521/test", |
| 78 | + "oracle", |
| 79 | + Optional.of("1.2.3"), |
| 80 | + "localhost:1521/test", |
| 81 | + "test" |
| 82 | + ), |
| 83 | + Arguments.arguments( |
| 84 | + "jdbc:tc:oracle:thin:@localhost:1521/test", |
| 85 | + "oracle", |
| 86 | + Optional.empty(), |
| 87 | + "localhost:1521/test", |
| 88 | + "test" |
| 89 | + ), |
| 90 | + Arguments.arguments( |
| 91 | + "jdbc:tc:oracle:1.2.3:thin:@localhost:1521:test", |
| 92 | + "oracle", |
| 93 | + Optional.of("1.2.3"), |
| 94 | + "localhost:1521:test", |
| 95 | + "test" |
| 96 | + ), |
| 97 | + Arguments.arguments( |
| 98 | + "jdbc:tc:oracle:1.2.3:thin://@localhost:1521:test", |
| 99 | + "oracle", |
| 100 | + Optional.of("1.2.3"), |
| 101 | + "localhost:1521:test", |
| 102 | + "test" |
| 103 | + ), |
| 104 | + Arguments.arguments( |
| 105 | + "jdbc:tc:oracle:1.2.3-anything:thin://@localhost:1521:test", |
| 106 | + "oracle", |
| 107 | + Optional.of("1.2.3-anything"), |
| 108 | + "localhost:1521:test", |
| 109 | + "test" |
| 110 | + ), |
| 111 | + Arguments.arguments( |
| 112 | + "jdbc:tc:oracle:thin:@localhost:1521:test", |
| 113 | + "oracle", |
| 114 | + Optional.empty(), |
| 115 | + "localhost:1521:test", |
| 116 | + "test" |
| 117 | + ) |
120 | 118 | ); |
121 | 119 | } |
122 | 120 |
|
123 | | - @Test |
124 | | - public void test() { |
| 121 | + @ParameterizedTest(name = "{index} - {0}") |
| 122 | + @MethodSource("data") |
| 123 | + void test(String jdbcUrl, String databaseType, Optional<String> tag, String dbHostString, String databaseName) { |
125 | 124 | ConnectionUrl url = ConnectionUrl.newInstance(jdbcUrl); |
126 | 125 | assertThat(url.getDatabaseType()).as("Database Type is as expected").isEqualTo(databaseType); |
127 | 126 | assertThat(url.getImageTag()).as("Image tag is as expected").isEqualTo(tag); |
|
0 commit comments