12
12
import io .airbyte .commons .json .Jsons ;
13
13
import io .airbyte .db .Database ;
14
14
import io .airbyte .db .factory .DSLContextFactory ;
15
- import io .airbyte .db .jdbc . JdbcUtils ;
15
+ import io .airbyte .db .factory . DatabaseDriver ;
16
16
import io .airbyte .integrations .base .JavaBaseConstants ;
17
17
import io .airbyte .integrations .destination .ExtendedNameTransformer ;
18
- import io .airbyte .integrations .standardtest .destination .DestinationAcceptanceTest ;
18
+ import io .airbyte .integrations .standardtest .destination .JdbcDestinationAcceptanceTest ;
19
+ import io .airbyte .integrations .standardtest .destination .comparator .TestDataComparator ;
19
20
import io .airbyte .protocol .models .AirbyteCatalog ;
20
21
import io .airbyte .protocol .models .AirbyteMessage ;
21
22
import io .airbyte .protocol .models .AirbyteMessage .Type ;
25
26
import io .airbyte .protocol .models .ConfiguredAirbyteCatalog ;
26
27
import java .sql .SQLException ;
27
28
import java .time .Instant ;
28
- import java .util .ArrayList ;
29
29
import java .util .List ;
30
30
import java .util .stream .Collectors ;
31
31
import org .jooq .DSLContext ;
32
32
import org .jooq .SQLDialect ;
33
33
import org .junit .jupiter .api .Test ;
34
34
import org .testcontainers .containers .MySQLContainer ;
35
35
36
- public class MySQLStrictEncryptDestinationAcceptanceTest extends DestinationAcceptanceTest {
36
+ public class MySQLStrictEncryptDestinationAcceptanceTest extends JdbcDestinationAcceptanceTest {
37
37
38
38
private MySQLContainer <?> db ;
39
39
private final ExtendedNameTransformer namingResolver = new MySQLNameTransformer ();
@@ -58,6 +58,26 @@ protected boolean supportsNormalization() {
58
58
return true ;
59
59
}
60
60
61
+ @ Override
62
+ protected TestDataComparator getTestDataComparator () {
63
+ return new MySqlTestDataComparator ();
64
+ }
65
+
66
+ @ Override
67
+ protected boolean supportBasicDataTypeTest () {
68
+ return true ;
69
+ }
70
+
71
+ @ Override
72
+ protected boolean supportArrayDataTypeTest () {
73
+ return true ;
74
+ }
75
+
76
+ @ Override
77
+ protected boolean supportObjectDataTypeTest () {
78
+ return true ;
79
+ }
80
+
61
81
@ Override
62
82
protected JsonNode getConfig () {
63
83
return Jsons .jsonNode (ImmutableMap .builder ()
@@ -96,28 +116,28 @@ protected List<JsonNode> retrieveRecords(final TestDestinationEnv testEnv,
96
116
throws Exception {
97
117
return retrieveRecordsFromTable (namingResolver .getRawTableName (streamName ), namespace )
98
118
.stream ()
99
- .map (r -> Jsons . deserialize ( r .get (JavaBaseConstants .COLUMN_NAME_DATA ). asText () ))
119
+ .map (r -> r .get (JavaBaseConstants .COLUMN_NAME_DATA ))
100
120
.collect (Collectors .toList ());
101
121
}
102
122
103
123
private List <JsonNode > retrieveRecordsFromTable (final String tableName , final String schemaName ) throws SQLException {
104
- final DSLContext dslContext = DSLContextFactory .create (
124
+ try ( final DSLContext dslContext = DSLContextFactory .create (
105
125
db .getUsername (),
106
126
db .getPassword (),
107
127
db .getDriverClassName (),
108
- String .format ("jdbc:mysql://%s:%s/%s?useSSL=true&requireSSL=true&verifyServerCertificate=false" ,
128
+ String .format (DatabaseDriver . MYSQL . getUrlFormatString () ,
109
129
db .getHost (),
110
130
db .getFirstMappedPort (),
111
131
db .getDatabaseName ()),
112
- SQLDialect .MYSQL );
113
- return new Database (dslContext ).query (
114
- ctx -> ctx
115
- .fetch (String .format ("SELECT * FROM %s.%s ORDER BY %s ASC;" , schemaName , tableName ,
116
- JavaBaseConstants .COLUMN_NAME_EMITTED_AT ))
117
- .stream ()
118
- . map ( r -> r . formatJSON ( JdbcUtils . getDefaultJSONFormat ()) )
119
- . map ( Jsons :: deserialize )
120
- . collect ( Collectors . toList ()));
132
+ SQLDialect .MYSQL )) {
133
+ return new Database (dslContext ).query (
134
+ ctx -> ctx
135
+ .fetch (String .format ("SELECT * FROM %s.%s ORDER BY %s ASC;" , schemaName , tableName ,
136
+ JavaBaseConstants .COLUMN_NAME_EMITTED_AT ))
137
+ .stream ()
138
+ . map ( this :: getJsonFromRecord )
139
+ . collect ( Collectors . toList ()));
140
+ }
121
141
}
122
142
123
143
@ Override
@@ -128,18 +148,6 @@ protected List<JsonNode> retrieveNormalizedRecords(final TestDestinationEnv test
128
148
return retrieveRecordsFromTable (tableName , schema );
129
149
}
130
150
131
- @ Override
132
- protected List <String > resolveIdentifier (final String identifier ) {
133
- final List <String > result = new ArrayList <>();
134
- final String resolved = namingResolver .getIdentifier (identifier );
135
- result .add (identifier );
136
- result .add (resolved );
137
- if (!resolved .startsWith ("\" " )) {
138
- result .add (resolved .toLowerCase ());
139
- }
140
- return result ;
141
- }
142
-
143
151
@ Override
144
152
protected void setup (final TestDestinationEnv testEnv ) {
145
153
db = new MySQLContainer <>("mysql:8.0" );
@@ -163,10 +171,10 @@ private void grantCorrectPermissions() {
163
171
164
172
private void executeQuery (final String query ) {
165
173
try (final DSLContext dslContext = DSLContextFactory .create (
166
- db . getUsername () ,
167
- db . getPassword () ,
174
+ "root" ,
175
+ "test" ,
168
176
db .getDriverClassName (),
169
- String .format ("jdbc:mysql://%s:%s/%s?useSSL=true&requireSSL=true&verifyServerCertificate=false" ,
177
+ String .format (DatabaseDriver . MYSQL . getUrlFormatString () ,
170
178
db .getHost (),
171
179
db .getFirstMappedPort (),
172
180
db .getDatabaseName ()),
@@ -187,9 +195,10 @@ protected void tearDown(final TestDestinationEnv testEnv) {
187
195
188
196
@ Override
189
197
@ Test
190
- public void testCustomDbtTransformations () {
198
+ public void testCustomDbtTransformations () throws Exception {
191
199
// We need to create view for testing custom dbt transformations
192
200
executeQuery ("GRANT CREATE VIEW ON *.* TO " + db .getUsername () + "@'%';" );
201
+ super .testCustomDbtTransformations ();
193
202
}
194
203
195
204
@ Test
0 commit comments