22
33import static apoc .util .TestUtil .testCall ;
44import static org .junit .Assert .assertEquals ;
5+ import static org .junit .Assert .assertTrue ;
56
67import apoc .util .MySQLContainerExtension ;
78import apoc .util .TestUtil ;
89import apoc .util .Util ;
10+ import java .time .LocalDate ;
11+ import java .time .LocalDateTime ;
12+ import java .time .LocalTime ;
13+ import java .time .ZonedDateTime ;
914import java .util .Map ;
1015import org .junit .AfterClass ;
1116import org .junit .BeforeClass ;
1621import org .neo4j .test .rule .DbmsRule ;
1722import org .neo4j .test .rule .ImpermanentDbmsRule ;
1823
19- import java .time .LocalDate ;
20- import java .time .LocalDateTime ;
21- import java .time .LocalTime ;
22- import java .time .ZonedDateTime ;
23- import java .util .Map ;
24-
25- import static apoc .util .TestUtil .testCall ;
26- import static org .junit .Assert .assertEquals ;
27- import static org .junit .Assert .assertTrue ;
28-
2924@ RunWith (Enclosed .class )
3025public class MySQLJdbcTest extends AbstractJdbcTest {
31-
26+
3227 public static class MySQLJdbcLatestVersionTest {
33-
28+
3429 @ ClassRule
3530 public static MySQLContainerExtension mysql = new MySQLContainerExtension ("mysql:8.0.31" );
3631
3732 @ ClassRule
3833 public static DbmsRule db = new ImpermanentDbmsRule ();
39-
34+
4035 @ BeforeClass
4136 public static void setUpContainer () {
4237 mysql .start ();
4338 TestUtil .registerProcedure (db , Jdbc .class );
4439 }
40+
4541 @ AfterClass
4642 public static void tearDown () {
4743 mysql .stop ();
4844 db .shutdown ();
4945 }
46+
5047 @ Test
5148 public void testLoadJdbc () {
5249 MySQLJdbcTest .testLoadJdbc (db , mysql );
@@ -57,9 +54,9 @@ public void testIssue3496() {
5754 MySQLJdbcTest .testIssue3496 (db , mysql );
5855 }
5956 }
60-
57+
6158 public static class MySQLJdbcFiveVersionTest {
62-
59+
6360 @ ClassRule
6461 public static MySQLContainerExtension mysql = new MySQLContainerExtension ("mysql:5.7" );
6562
@@ -90,34 +87,58 @@ public void testIssue3496() {
9087 }
9188
9289 private static void testLoadJdbc (DbmsRule db , MySQLContainerExtension mysql ) {
93- // with the config {timezone: 'UTC'} and `preserveInstants=true&connectionTimeZone=SERVER` to make the result deterministic,
94- // since `TIMESTAMP` values are automatically converted from the session time zone to UTC for storage, and vice versa.
95- testCall (db , "CALL apoc.load.jdbc($url, $table, [], {timezone: 'UTC'})" ,
90+ // with the config {timezone: 'UTC'} and `preserveInstants=true&connectionTimeZone=SERVER` to make the result
91+ // deterministic,
92+ // since `TIMESTAMP` values are automatically converted from the session time zone to UTC for storage, and vice
93+ // versa.
94+ testCall (
95+ db ,
96+ "CALL apoc.load.jdbc($url, $table, [], {timezone: 'UTC'})" ,
9697 Util .map (
97- "url" , mysql .getJdbcUrl () + "&preserveInstants=true&connectionTimeZone=SERVER" ,
98- "table" , "country" ),
98+ "url" ,
99+ mysql .getJdbcUrl () + "&preserveInstants=true&connectionTimeZone=SERVER" ,
100+ "table" ,
101+ "country" ),
99102 row -> {
100103 Map <String , Object > expected = Util .map (
101- "Code" , "NLD" ,
102- "Name" , "Netherlands" ,
103- "Continent" , "Europe" ,
104- "Region" , "Western Europe" ,
105- "SurfaceArea" , 41526f ,
106- "IndepYear" , 1581 ,
107- "Population" , 15864000 ,
108- "LifeExpectancy" , 78.3f ,
109- "GNP" , 371362f ,
110- "GNPOld" , 360478f ,
111- "LocalName" , "Nederland" ,
112- "GovernmentForm" , "Constitutional Monarchy" ,
113- "HeadOfState" , "Beatrix" ,
114- "Capital" , 5 ,
115- "Code2" , "NL" ,
116- "myTime" , LocalTime .of (1 , 0 , 0 ),
117- "myTimeStamp" , ZonedDateTime .parse ("2003-01-01T01:00Z" ),
118- "myDate" , LocalDate .parse ("2003-01-01" ),
119- "myYear" , LocalDate .parse ("2003-01-01" )
120- );
104+ "Code" ,
105+ "NLD" ,
106+ "Name" ,
107+ "Netherlands" ,
108+ "Continent" ,
109+ "Europe" ,
110+ "Region" ,
111+ "Western Europe" ,
112+ "SurfaceArea" ,
113+ 41526f ,
114+ "IndepYear" ,
115+ 1581 ,
116+ "Population" ,
117+ 15864000 ,
118+ "LifeExpectancy" ,
119+ 78.3f ,
120+ "GNP" ,
121+ 371362f ,
122+ "GNPOld" ,
123+ 360478f ,
124+ "LocalName" ,
125+ "Nederland" ,
126+ "GovernmentForm" ,
127+ "Constitutional Monarchy" ,
128+ "HeadOfState" ,
129+ "Beatrix" ,
130+ "Capital" ,
131+ 5 ,
132+ "Code2" ,
133+ "NL" ,
134+ "myTime" ,
135+ LocalTime .of (1 , 0 , 0 ),
136+ "myTimeStamp" ,
137+ ZonedDateTime .parse ("2003-01-01T01:00Z" ),
138+ "myDate" ,
139+ LocalDate .parse ("2003-01-01" ),
140+ "myYear" ,
141+ LocalDate .parse ("2003-01-01" ));
121142 Map actual = (Map ) row .get ("row" );
122143 Object myDateTime = actual .remove ("myDateTime" );
123144 assertTrue (myDateTime instanceof LocalDateTime );
@@ -126,22 +147,24 @@ private static void testLoadJdbc(DbmsRule db, MySQLContainerExtension mysql) {
126147 }
127148
128149 private static void testIssue3496 (DbmsRule db , MySQLContainerExtension mysql ) {
129- testCall (db , "CALL apoc.load.jdbc($url,'SELECT DATE(NOW()), NOW(), CURDATE(), CURTIME(), UTC_DATE(), UTC_TIME(), UTC_TIMESTAMP(), DATE(UTC_TIMESTAMP());')" ,
150+ testCall (
151+ db ,
152+ "CALL apoc.load.jdbc($url,'SELECT DATE(NOW()), NOW(), CURDATE(), CURTIME(), UTC_DATE(), UTC_TIME(), UTC_TIMESTAMP(), DATE(UTC_TIMESTAMP());')" ,
130153 Util .map ("url" , mysql .getJdbcUrl ()),
131154 r -> {
132155 Map row = (Map ) r .get ("row" );
133156 assertEquals (8 , row .size ());
134-
157+
135158 assertTrue (row .get ("UTC_DATE()" ) instanceof LocalDate );
136159 assertTrue (row .get ("CURDATE()" ) instanceof LocalDate );
137-
160+
138161 assertTrue (row .get ("UTC_TIMESTAMP()" ) instanceof LocalDateTime );
139162 assertTrue (row .get ("NOW()" ) instanceof LocalDateTime );
140163 assertTrue (row .get ("DATE(UTC_TIMESTAMP())" ) instanceof LocalDate );
141164 assertTrue (row .get ("DATE(NOW())" ) instanceof LocalDate );
142-
165+
143166 assertTrue (row .get ("CURTIME()" ) instanceof LocalTime );
144167 assertTrue (row .get ("UTC_TIME()" ) instanceof LocalTime );
145168 });
146169 }
147- }
170+ }
0 commit comments