-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
TemporalAcceptanceTest.scala
548 lines (458 loc) · 26.7 KB
/
TemporalAcceptanceTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
/*
* Copyright (c) 2002-2018 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.internal.cypher.acceptance
import java.time.format.DateTimeParseException
import java.time.temporal.UnsupportedTemporalTypeException
import org.neo4j.cypher._
import org.neo4j.graphdb.QueryExecutionException
import org.neo4j.internal.cypher.acceptance.CypherComparisonSupport.Configs
class TemporalAcceptanceTest extends ExecutionEngineFunSuite with QueryStatisticsTestSupport with CypherComparisonSupport {
// Getting current value of a temporal
test("should return something for current time/date/etc") {
for (s <- Seq("date", "localtime", "time", "localdatetime", "datetime")) {
shouldReturnSomething(s"$s()")
shouldReturnSomething(s"$s.transaction()")
shouldReturnSomething(s"$s.statement()")
shouldReturnSomething(s"$s.realtime()")
shouldReturnSomething(s"$s.transaction('America/Los_Angeles')")
shouldReturnSomething(s"$s.statement('America/Los_Angeles')")
shouldReturnSomething(s"$s.realtime('America/Los_Angeles')")
shouldReturnSomething(s"$s({timezone: '+01:00'})")
}
shouldReturnSomething("datetime({epochMillis:timestamp()})")
shouldReturnSomething("datetime({epochSeconds:timestamp() / 1000})")
}
// Failing when skipping certain values in create or specifying conflicting values
test("should not create date with missing values") {
val queries = Seq("{}", "{year:1984, day:11}", "{year:1984, dayOfWeek:3}", "{year:1984, dayOfQuarter:45}")
shouldNotConstructWithArg("date", queries)
}
test("should not create date with conflicting values") {
val queries = Seq("{year:1984, month: 2, week:11}", "{year:1984, month: 2, dayOfWeek:6}",
"{year:1984, month: 2, quarter:11}", "{year:1984, month: 2, dayOfQuarter:11}",
"{year:1984, week: 2, day:11}", "{year:1984, week: 2, quarter:11}", "{year:1984, week: 2, dayOfQuarter:11}",
"{year:1984, quarter: 2, day:11}", "{year:1984, quarter: 2, dayOfWeek:6}")
shouldNotConstructWithArg("date", queries)
}
test("should not create local time with missing values") {
val queries = Seq("{}", "{hour:12, minute:31, nanosecond: 645876123}", "{hour:12, second:14, microsecond: 645876}",
"{hour:12, millisecond: 645}", "{hour:12, second: 45}")
shouldNotConstructWithArg("localtime", queries)
}
test("should not create time with missing values") {
val queries = Seq("{}", "{hour:12, minute:31, nanosecond: 645876123}", "{hour:12, second:14, microsecond: 645876}",
"{hour:12, millisecond: 645}", "{hour:12, second: 45}")
shouldNotConstructWithArg("time", queries)
}
test("should not create local date time with missing values") {
val queries = Seq("{}", "{year:1984, day:11}", "{year:1984, dayOfWeek:3}", "{year:1984, dayOfQuarter:45}",
"{year:1984, hour:11}", "{year:1984, minute:11}", "{year:1984, second:3}",
"{year:1984, millisecond:45}", "{year:1984, microsecond:11}", "{year:1984, nanosecond:3}",
"{year:1984, month: 2, hour:11}", "{year:1984, month: 2, minute:11}", "{year:1984, month: 2, second:3}",
"{year:1984, month: 2, millisecond:45}", "{year:1984, month: 2, microsecond:11}", "{year:1984, month: 2, nanosecond:3}",
"{year:1984, week: 2, hour:11}", "{year:1984, week: 2, minute:11}", "{year:1984, week: 2, second:3}",
"{year:1984, week: 2, millisecond:45}", "{year:1984, week: 2, microsecond:11}", "{year:1984, week: 2, nanosecond:3}",
"{year:1984, quarter: 2, hour:11}", "{year:1984, quarter: 2, minute:11}", "{year:1984, quarter: 2, second:3}",
"{year:1984, quarter: 2, millisecond:45}", "{year:1984, quarter: 2, microsecond:11}", "{year:1984, quarter: 2, nanosecond:3}",
"{year:1984, month:2, day:8, hour:12, minute:31, nanosecond: 645876123}", "{year:1984, month:2, day:8, hour:12, second:14, microsecond: 645876}",
"{year:1984, month:2, day:8, hour:12, millisecond: 645}", "{year:1984, month:2, day:8, hour:12, second: 45}")
shouldNotConstructWithArg("localdatetime", queries)
}
test("should not create local date time with conflicting values") {
val queries = Seq("{year:1984, month: 2, week:11}", "{year:1984, month: 2, dayOfWeek:6}",
"{year:1984, month: 2, quarter:11}", "{year:1984, month: 2, dayOfQuarter:11}",
"{year:1984, week: 2, day:11}", "{year:1984, week: 2, quarter:11}", "{year:1984, week: 2, dayOfQuarter:11}",
"{year:1984, quarter: 2, day:11}", "{year:1984, quarter: 2, dayOfWeek:6}", "{datetime: datetime(), date: date()}",
"{datetime: datetime(), time: time()}")
shouldNotConstructWithArg("localdatetime", queries)
}
test("should not create date time with missing values") {
val queries = Seq("{}", "{year:1984, day:11}", "{year:1984, dayOfWeek:3}", "{year:1984, dayOfQuarter:45}",
"{year:1984, hour:11}", "{year:1984, minute:11}", "{year:1984, second:3}",
"{year:1984, millisecond:45}", "{year:1984, microsecond:11}", "{year:1984, nanosecond:3}",
"{year:1984, month: 2, hour:11}", "{year:1984, month: 2, minute:11}", "{year:1984, month: 2, second:3}",
"{year:1984, month: 2, millisecond:45}", "{year:1984, month: 2, microsecond:11}", "{year:1984, month: 2, nanosecond:3}",
"{year:1984, week: 2, hour:11}", "{year:1984, week: 2, minute:11}", "{year:1984, week: 2, second:3}",
"{year:1984, week: 2, millisecond:45}", "{year:1984, week: 2, microsecond:11}", "{year:1984, week: 2, nanosecond:3}",
"{year:1984, quarter: 2, hour:11}", "{year:1984, quarter: 2, minute:11}", "{year:1984, quarter: 2, second:3}",
"{year:1984, quarter: 2, millisecond:45}", "{year:1984, quarter: 2, microsecond:11}", "{year:1984, quarter: 2, nanosecond:3}",
"{year:1984, month:2, day:8, hour:12, minute:31, nanosecond: 645876123}", "{year:1984, month:2, day:8, hour:12, second:14, microsecond: 645876}",
"{year:1984, month:2, day:8, hour:12, millisecond: 645}", "{year:1984, month:2, day:8, hour:12, second: 45}")
shouldNotConstructWithArg("datetime", queries)
}
test("should not create date time with conflicting values") {
val queries = Seq("{year:1984, month: 2, week:11}", "{year:1984, month: 2, dayOfWeek:6}",
"{year:1984, month: 2, quarter:11}", "{year:1984, month: 2, dayOfQuarter:11}",
"{year:1984, week: 2, day:11}", "{year:1984, week: 2, quarter:11}", "{year:1984, week: 2, dayOfQuarter:11}",
"{year:1984, quarter: 2, day:11}", "{year:1984, quarter: 2, dayOfWeek:6}", "{datetime: datetime(), date: date()}",
"{datetime: datetime(), time: time()}", "{datetime: datetime(), epochSeconds:1}", "{datetime: datetime(), epochMillis: timestamp()}",
"{date: date(), epochSeconds:1}","{date: date(), epochMillis: timestamp()}",
"{time: time(), epochSeconds:1}", "{time: time(), epochMillis: timestamp()}", "{epochSeconds:1, epochMillis: timestamp()}")
shouldNotConstructWithArg("datetime", queries)
}
test("should not create date time with conflicting time zones")
{
val query = "WITH datetime('1984-07-07T12:34+03:00[Europe/Stockholm]') as d RETURN d"
val errorMsg = "Timezone and offset do not match"
failWithError(Configs.Interpreted - Configs.Version2_3, query, Seq(errorMsg))
}
// Failing when selecting a wrong group
test("should not select time from date") {
shouldNotSelectWithArg[IllegalArgumentException]("date({year:1984, month: 2, day:11})",
Seq("localtime", "time", "localdatetime", "datetime"), Seq("{time:x}", "x"))
}
test("should not select date from time") {
shouldNotSelectWithArg[IllegalArgumentException]("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
Seq("date", "localdatetime", "datetime"), Seq("{date:x}", "x"))
}
test("should not select date from local time") {
shouldNotSelectWithArg[IllegalArgumentException]("localtime({hour: 12, minute: 30, second: 40})",
Seq("date", "localdatetime", "datetime"), Seq("{date:x}", "x"))
}
test("should not select datetime from date") {
shouldNotSelectWithArg[IllegalArgumentException]("date({year:1984, month: 2, day:11})",
Seq("localdatetime", "datetime"), Seq("{datetime:x}", "x"))
}
test("should not select datetime from time") {
shouldNotSelectWithArg[IllegalArgumentException]("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
Seq("localdatetime", "datetime"), Seq("{datetime:x}", "x"))
}
test("should not select datetime from local time") {
shouldNotSelectWithArg[IllegalArgumentException]("localtime({hour: 12, minute: 30, second: 40})",
Seq("localdatetime", "datetime"), Seq("{datetime:x}", "x"))
}
test("should not select time into date") {
shouldNotSelectWithArg[IllegalArgumentException]("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
Seq("date"), Seq("{time:x}", "{hour: 12}", "{minute: 30}", "{second: 40}", "{year:1984, month: 2, day:11, timezone: '+1:00'}"))
}
test("should not select date into time") {
shouldNotSelectWithArg[IllegalArgumentException]("date({year:1984, month: 2, day:11})",
Seq("time"), Seq("{date:x}", "{year: 1984}", "{month: 2}", "{day: 11}"))
}
test("should not select date into local time") {
shouldNotSelectWithArg[IllegalArgumentException]("date({year:1984, month: 2, day:11})",
Seq("localtime"), Seq("{date:x}", "{year: 1984}", "{month: 2}", "{day: 11}"))
}
test("should not select datetime into date") {
shouldNotSelectWithArg[IllegalArgumentException]("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
Seq("date"), Seq("{datetime:x}"))
}
test("should not select datetime into time") {
shouldNotSelectWithArg[IllegalArgumentException]("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
Seq("time"), Seq("{datetime:x}"))
}
test("should not select datetime into local time") {
shouldNotSelectWithArg[IllegalArgumentException]("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
Seq("localtime"), Seq("{datetime:x}"))
}
// Truncating with wrong receiver or argument
test("should not truncate to millennium with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("time", "localtime"), "millennium",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate to millennium with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime", "localdatetime", "date"), "millennium",
Seq("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})", "localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate to century with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("time", "localtime"), "century",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate to century with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime", "localdatetime", "date"), "century",
Seq("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})", "localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate to decade with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("time", "localtime"), "decade",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate to decade with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime", "localdatetime", "date"), "decade",
Seq("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})", "localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate to year with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("time", "localtime"), "year",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate to year with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime", "localdatetime", "date"), "year",
Seq("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})", "localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate to weekYear with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("time", "localtime"), "weekYear",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate to weekYear with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime", "localdatetime", "date"), "weekYear",
Seq("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})", "localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate to quarter with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("time", "localtime"), "quarter",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate to quarter with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime", "localdatetime", "date"), "quarter",
Seq("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})", "localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate to month with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("time", "localtime"), "month",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate to month with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime", "localdatetime", "date"), "month",
Seq("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})", "localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate to week with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("time", "localtime"), "week",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate to week with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime", "localdatetime", "date"), "week",
Seq("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})", "localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate to day with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime", "localdatetime", "date"), "day",
Seq("time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})", "localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate to hour with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("date"), "hour",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate datetime to hour with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime"), "hour",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate localdatetime to hour with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localdatetime"), "hour",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate time to hour with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("time"), "hour",
Seq("date({year:1984, month: 2, day:11})"))
}
test("should not truncate localtime to hour with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localtime"), "hour",
Seq("date({year:1984, month: 2, day:11})"))
}
test("should not truncate to minute with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("date"), "minute",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate datetime to minute with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime"), "minute",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate localdatetime to minute with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localdatetime"), "minute",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate time to minute with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("time"), "minute",
Seq("date({year:1984, month: 2, day:11})"))
}
test("should not truncate localtime to minute with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localtime"), "minute",
Seq("date({year:1984, month: 2, day:11})"))
}
test("should not truncate to second with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("date"), "second",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate datetime to second with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime"), "second",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate localdatetime to second with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localdatetime"), "second",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate time to second with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("time"), "second",
Seq("date({year:1984, month: 2, day:11})"))
}
test("should not truncate localtime to second with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localtime"), "second",
Seq("date({year:1984, month: 2, day:11})"))
}
test("should not truncate to millisecond with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("date"), "millisecond",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate datetime to millisecond with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime"), "millisecond",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate localdatetime to millisecond with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localdatetime"), "millisecond",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate time to millisecond with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("time"), "millisecond",
Seq("date({year:1984, month: 2, day:11})"))
}
test("should not truncate localtime to millisecond with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localtime"), "millisecond",
Seq("date({year:1984, month: 2, day:11})"))
}
test("should not truncate to microsecond with wrong receiver") {
shouldNotTruncate[UnsupportedTemporalTypeException](Seq("date"), "microsecond",
Seq("datetime({year:1984, month: 2, day:11, hour: 12, minute: 30, second: 40, timezone:'+01:00'})"))
}
test("should not truncate datetime to microsecond with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("datetime"), "microsecond",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate localdatetime to microsecond with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localdatetime"), "microsecond",
Seq("date({year:1984, month: 2, day:11})",
"time({hour: 12, minute: 30, second: 40, timezone:'+01:00'})",
"localtime({hour: 12, minute: 30, second: 40})"))
}
test("should not truncate time to microsecond with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("time"), "microsecond",
Seq("date({year:1984, month: 2, day:11})"))
}
test("should not truncate localtime to microsecond with wrong argument") {
shouldNotTruncate[IllegalArgumentException](Seq("localtime"), "microsecond",
Seq("date({year:1984, month: 2, day:11})"))
}
// Arithmetic
test("subtracting temporal instants should give meaningful error message") {
for (func <- Seq("date", "localtime", "time", "localdatetime", "datetime")) {
val query = s"RETURN $func() - $func()"
val exception = intercept[QueryExecutionException] {
println(graph.execute(query).next())
}
exception.getMessage should be ("You cannot subtract a temporal instant from another. " +
"To obtain the duration, use 'duration.between(temporal1, temporal2)' instead.")
}
}
// Parsing
test("should not allow decimals on any but the least significant given value") {
for (arg <- Seq("P1.5Y1M", "P1Y1.5M1D", "P1Y1M1.5DT1H", "P1Y1M1DT1.5H1M", "P1Y1M1DT1H1.5M1S")) {
val query = s"RETURN duration('$arg')"
val exception = intercept[DateTimeParseException] {
println(graph.execute(query).next())
}
exception.getMessage should be ("Text cannot be parsed to a Duration")
}
}
// Accessors
test("should not provide undefined accessors for date") {
shouldNotHaveAccessor("date", Seq("hour", "minute", "second", "millisecond", "microsecond", "nanosecond",
"timezone", "offset", "offsetMinutes", "epochSeconds", "epochMillis",
"years", "months", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"))
}
test("should not provide undefined accessors for local time") {
shouldNotHaveAccessor("localtime", Seq("year", "quarter", "month", "week", "weekYear", "day", "ordinalDay", "weekDay", "dayOfQuarter",
"timezone", "offset", "offsetMinutes", "epochSeconds", "epochMillis",
"years", "months", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"))
}
test("should not provide undefined accessors for time") {
shouldNotHaveAccessor("time", Seq("year", "quarter", "month", "week", "weekYear", "day", "ordinalDay", "weekDay", "dayOfQuarter",
"years", "months", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"))
}
test("should not provide undefined accessors for local date time") {
shouldNotHaveAccessor("localdatetime", Seq("timezone", "offset", "offsetMinutes", "epochSeconds", "epochMillis",
"years", "months", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"))
}
test("should not provide undefined accessors for date time") {
shouldNotHaveAccessor("datetime", Seq("years", "months", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"))
}
test("should not provide undefined accessors for duration") {
shouldNotHaveAccessor("duration", Seq("year", "quarter", "month", "week", "weekYear", "day", "ordinalDay", "weekDay", "dayOfQuarter",
"hour", "minute", "second", "millisecond", "microsecond", "nanosecond",
"timezone", "offset", "offsetMinutes", "epochSeconds", "epochMillis"), "{days: 14, hours:16, minutes: 12}")
}
// Duration between
test("should not compute the duration in day units between two time values") {
val args = Seq("time()", "localtime()")
for (func <- Seq("inMonths", "inDays"); arg1 <- args; arg2 <- args) {
val query = s"RETURN duration.$func($arg1, $arg2)"
withClue(s"Executing $query") {
an[UnsupportedTemporalTypeException] shouldBe thrownBy {
println(graph.execute(query).next())
}
}
}
}
private def shouldNotTruncate[E : Manifest](receivers: Seq[String], truncationUnit: String, args: Seq[String]): Unit = {
for (receiver <- receivers; arg <- args) {
val query = s"RETURN $receiver.truncate('$truncationUnit', $arg)"
withClue(s"Executing $query") {
an[E] shouldBe thrownBy {
println(graph.execute(query).next())
}
}
}
}
private def shouldNotSelectWithArg[E : Manifest](withX: String, returnFuncs: Seq[String], args: Seq[String]): Unit = {
for (func <- returnFuncs; arg <- args) {
val query = s"WITH $withX as x RETURN $func($arg)"
withClue(s"Executing $query") {
an[E] shouldBe thrownBy {
println(graph.execute(query).next())
}
}
}
}
private def shouldNotHaveAccessor(typ: String, accessors: Seq[String], args: String = ""): Unit = {
for (acc <- accessors) {
val query = s"RETURN $typ($args).$acc"
withClue(s"Executing $query") {
an[UnsupportedTemporalTypeException] shouldBe thrownBy {
println(graph.execute(query).next())
}
}
}
}
private def shouldNotConstructWithArg(func: String, args: Seq[String]): Unit = {
for (arg <- args) {
val query = s"RETURN $func($arg)"
withClue(s"Executing $query") {
an[IllegalArgumentException] shouldBe thrownBy {
println(graph.execute(query).next())
}
}
}
}
private def shouldReturnSomething(func: String): Unit = {
val query = s"RETURN $func"
graph.execute(query).next() should not be null
}
}