21
21
*/
22
22
package org .exist .xquery ;
23
23
24
- import java .net .URISyntaxException ;
25
- import java .nio .file .Path ;
26
- import java .nio .file .Paths ;
27
- import java .text .SimpleDateFormat ;
28
- import java .util .Date ;
29
- import java .util .Locale ;
30
- import java .util .Optional ;
31
-
32
24
import com .googlecode .junittoolbox .ParallelRunner ;
33
25
import org .exist .test .ExistXmldbEmbeddedServer ;
34
- import org .exist .util .ConfigurationHelper ;
35
- import org .exist .util .FileUtils ;
36
26
import org .exist .xmldb .XmldbURI ;
37
- import org .junit .*;
27
+ import org .junit .ClassRule ;
28
+ import org .junit .Ignore ;
29
+ import org .junit .Test ;
38
30
import org .junit .runner .RunWith ;
39
31
import org .xmldb .api .base .Collection ;
40
32
import org .xmldb .api .base .ResourceSet ;
41
33
import org .xmldb .api .base .XMLDBException ;
42
34
import org .xmldb .api .modules .BinaryResource ;
43
35
import org .xmldb .api .modules .CollectionManagementService ;
44
36
45
- import static org .junit .Assert .assertEquals ;
46
- import static org .junit .Assert .assertNotNull ;
47
- import static org .junit .Assert .assertTrue ;
37
+ import java .net .URISyntaxException ;
38
+ import java .nio .file .Path ;
39
+ import java .nio .file .Paths ;
40
+ import java .text .SimpleDateFormat ;
41
+ import java .util .Date ;
42
+ import java .util .Locale ;
43
+
44
+ import static org .junit .Assert .*;
48
45
49
46
/**
50
47
* Tests for various standard XQuery functions
@@ -70,7 +67,7 @@ public class XQueryFunctionsTest {
70
67
private final static String ROOT_COLLECTION_URI = "xmldb:exist:///db" ;
71
68
72
69
@ Test
73
- public void arguments () throws XPathException , XMLDBException {
70
+ public void arguments () throws XMLDBException {
74
71
ResourceSet result = existEmbeddedServer .executeQuery ("declare function local:testAnyURI($uri as xs:string) as xs:string { " +
75
72
"concat('Successfully processed as xs:string : ',$uri) " +
76
73
"}; " +
@@ -94,7 +91,7 @@ public void arguments() throws XPathException, XMLDBException {
94
91
* with the rounding value typed xs:integer
95
92
*/
96
93
@ Test
97
- public void roundHtE_INTEGER () throws XPathException , XMLDBException {
94
+ public void roundHtE_INTEGER () throws XMLDBException {
98
95
String query = "fn:round-half-to-even( xs:integer('1'), 0 )" ;
99
96
ResourceSet result = existEmbeddedServer .executeQuery (query );
100
97
String r = (String ) result .getResource (0 ).getContent ();
@@ -116,7 +113,7 @@ public void roundHtE_INTEGER() throws XPathException, XMLDBException {
116
113
* with the rounding value typed xs:double
117
114
*/
118
115
@ Test
119
- public void roundHtE_DOUBLE () throws XPathException , XMLDBException {
116
+ public void roundHtE_DOUBLE () throws XMLDBException {
120
117
/* List of Values to test with Rounding */
121
118
String [] testvalues =
122
119
{"0.5" , "1.5" , "2.5" , "3.567812E+3" , "4.7564E-3" , "35612.25" };
@@ -137,7 +134,7 @@ public void roundHtE_DOUBLE() throws XPathException, XMLDBException {
137
134
* Tests the XQuery-XPath function fn:tokenize()
138
135
*/
139
136
@ Test
140
- public void tokenize () throws XPathException , XMLDBException {
137
+ public void tokenize () throws XMLDBException {
141
138
ResourceSet result = existEmbeddedServer .executeQuery ("count ( tokenize('a/b' , '/') )" );
142
139
String r = (String ) result .getResource (0 ).getContent ();
143
140
assertEquals ("2" , r );
@@ -171,7 +168,7 @@ public void tokenize() throws XPathException, XMLDBException {
171
168
}
172
169
173
170
@ Test
174
- public void deepEqual () throws XPathException , XMLDBException {
171
+ public void deepEqual () throws XMLDBException {
175
172
ResourceSet result = existEmbeddedServer .executeQuery (
176
173
"let $res := ('a', 'b')" +
177
174
"let $reference := ('a', 'b')" +
@@ -196,7 +193,7 @@ public void compare() throws XPathException, XMLDBException {
196
193
}
197
194
198
195
@ Test
199
- public void distinctValues () throws XPathException , XMLDBException {
196
+ public void distinctValues () throws XMLDBException {
200
197
ResourceSet result = existEmbeddedServer .executeQuery ("declare variable $c { distinct-values(('a', 'a')) }; $c" );
201
198
String r = (String ) result .getResource (0 ).getContent ();
202
199
assertEquals ("a" , r );
@@ -215,7 +212,7 @@ public void distinctValues() throws XPathException, XMLDBException {
215
212
}
216
213
217
214
@ Test
218
- public void sum () throws XPathException , XMLDBException {
215
+ public void sum () throws XMLDBException {
219
216
ResourceSet result = existEmbeddedServer .executeQuery ("declare variable $c { sum((1, 2)) }; $c" );
220
217
String r = (String ) result .getResource (0 ).getContent ();
221
218
assertEquals ("3" , r );
@@ -231,7 +228,7 @@ public void sum() throws XPathException, XMLDBException {
231
228
}
232
229
233
230
@ Test
234
- public void avg () throws XPathException , XMLDBException {
231
+ public void avg () throws XMLDBException {
235
232
ResourceSet result = existEmbeddedServer .executeQuery ("avg((2, 2))" );
236
233
String r = (String ) result .getResource (0 ).getContent ();
237
234
assertEquals ("2" , r );
@@ -257,7 +254,7 @@ public void avg() throws XPathException, XMLDBException {
257
254
} catch (XMLDBException e ) {
258
255
message = e .getMessage ();
259
256
}
260
- assertTrue (message .indexOf ("FORG0006" ) > - 1 );
257
+ assertTrue (message .contains ("FORG0006" ));
261
258
262
259
result = existEmbeddedServer .executeQuery ("avg(())" );
263
260
assertEquals (0 , result .getSize ());
@@ -298,7 +295,7 @@ public void min() throws XPathException, XMLDBException {
298
295
} catch (XMLDBException e ) {
299
296
message = e .getMessage ();
300
297
}
301
- assertTrue (message .indexOf ("FORG0006" ) > - 1 );
298
+ assertTrue (message .contains ("FORG0006" ));
302
299
303
300
try {
304
301
message = "" ;
@@ -307,7 +304,7 @@ public void min() throws XPathException, XMLDBException {
307
304
message = e .getMessage ();
308
305
}
309
306
//depends whether we have strict type checking or not
310
- assertTrue (message .indexOf ("XPTY0004" ) > - 1 | message .indexOf ("FORG0001" ) > - 1 | message .indexOf ("FOCH0002" ) > - 1 );
307
+ assertTrue (message .contains ("XPTY0004" ) | message .contains ("FORG0001" ) | message .contains ("FOCH0002" ));
311
308
}
312
309
313
310
public void max () throws XPathException , XMLDBException {
@@ -336,7 +333,7 @@ public void max() throws XPathException, XMLDBException {
336
333
} catch (XMLDBException e ) {
337
334
message = e .getMessage ();
338
335
}
339
- assertTrue (message .indexOf ("FORG0006" ) > - 1 );
336
+ assertTrue (message .contains ("FORG0006" ));
340
337
341
338
try {
342
339
message = "" ;
@@ -345,11 +342,11 @@ public void max() throws XPathException, XMLDBException {
345
342
message = e .getMessage ();
346
343
}
347
344
//depends whether we have strict type checking or not
348
- assertTrue (message .indexOf ("XPTY0004" ) > - 1 | message .indexOf ("FORG0001" ) > - 1 | message .indexOf ("FOCH0002" ) > - 1 );
345
+ assertTrue (message .contains ("XPTY0004" ) | message .contains ("FORG0001" ) | message .contains ("FOCH0002" ));
349
346
}
350
347
351
348
@ Test
352
- public void exclusiveLock () throws XPathException , XMLDBException {
349
+ public void exclusiveLock () throws XMLDBException {
353
350
String query = "let $query1 := (<a/>)\n " +
354
351
"let $query2 := (2, 3)\n " +
355
352
"let $a := util:exclusive-lock(//*,($query1, $query2))\n " +
@@ -398,17 +395,17 @@ public void exclusiveLock() throws XPathException, XMLDBException {
398
395
399
396
@ Ignore
400
397
@ Test
401
- public void utilEval1 () throws XPathException , XMLDBException {
398
+ public void utilEval1 () throws XMLDBException {
402
399
String query = "<a><b/></a>/util:eval('*')" ;
403
400
ResourceSet result = existEmbeddedServer .executeQuery (query );
404
401
assertEquals (1 , result .getSize ());
405
402
}
406
403
407
404
/**
408
- * @see http://sourceforge.net/tracker/index.php?func=detail&aid=1629363&group_id=17691&atid=117691
405
+ * @see { http://sourceforge.net/tracker/index.php?func=detail&aid=1629363&group_id=17691&atid=117691}
409
406
*/
410
407
@ Test
411
- public void utilEval2 () throws XPathException , XMLDBException {
408
+ public void utilEval2 () throws XMLDBException {
412
409
String query = "let $context := <item/> " +
413
410
"return util:eval(\" <result>{$context}</result>\" )" ;
414
411
// TODO check result
@@ -417,7 +414,7 @@ public void utilEval2() throws XPathException, XMLDBException {
417
414
}
418
415
419
416
@ Test
420
- public void utilEvalForFunction () throws XPathException , XMLDBException {
417
+ public void utilEvalForFunction () throws XMLDBException {
421
418
422
419
String query = "declare function local:home()\n "
423
420
+ "{\n "
@@ -430,7 +427,7 @@ public void utilEvalForFunction() throws XPathException, XMLDBException {
430
427
}
431
428
432
429
@ Test
433
- public void sharedLock () throws XPathException , XMLDBException {
430
+ public void sharedLock () throws XMLDBException {
434
431
String query = "let $query1 := (<a/>)\n " +
435
432
"let $query2 := (2, 3)\n " +
436
433
"let $a := util:shared-lock(//*,($query1, $query2))\n " +
@@ -560,7 +557,7 @@ public void escapeHTMLURI() throws XMLDBException {
560
557
}
561
558
562
559
@ Test
563
- public void localName () throws XPathException , XMLDBException {
560
+ public void localName () throws XMLDBException {
564
561
final ResourceSet result = existEmbeddedServer .executeQuery (
565
562
"let $a := <a><b></b></a>" +
566
563
"return fn:local-name($a)" );
@@ -569,31 +566,31 @@ public void localName() throws XPathException, XMLDBException {
569
566
}
570
567
571
568
@ Test
572
- public void localName_empty () throws XPathException , XMLDBException {
569
+ public void localName_empty () throws XMLDBException {
573
570
final ResourceSet result = existEmbeddedServer .executeQuery (
574
571
"fn:local-name(())" );
575
572
final String r = (String ) result .getResource (0 ).getContent ();
576
573
assertEquals ("" , r );
577
574
}
578
575
579
576
@ Test
580
- public void localName_emptyElement () throws XPathException , XMLDBException {
577
+ public void localName_emptyElement () throws XMLDBException {
581
578
final ResourceSet result = existEmbeddedServer .executeQuery (
582
579
"<a>b</a>/fn:local-name(c)" );
583
580
final String r = (String ) result .getResource (0 ).getContent ();
584
581
assertEquals ("" , r );
585
582
}
586
583
587
584
@ Test
588
- public void localName_emptyText () throws XPathException , XMLDBException {
585
+ public void localName_emptyText () throws XMLDBException {
589
586
final ResourceSet result = existEmbeddedServer .executeQuery (
590
587
"<a>b</a>/fn:local-name(text())" );
591
588
final String r = (String ) result .getResource (0 ).getContent ();
592
589
assertEquals ("" , r );
593
590
}
594
591
595
592
@ Test
596
- public void localName_contextItem () throws XPathException , XMLDBException {
593
+ public void localName_contextItem () throws XMLDBException {
597
594
final ResourceSet result = existEmbeddedServer .executeQuery (
598
595
"let $a := <a><b/></a>" +
599
596
"return $a/b/fn:local-name()" );
@@ -602,7 +599,7 @@ public void localName_contextItem() throws XPathException, XMLDBException {
602
599
}
603
600
604
601
@ Test
605
- public void localName_contextItem_empty () throws XPathException , XMLDBException {
602
+ public void localName_contextItem_empty () throws XMLDBException {
606
603
final ResourceSet result = existEmbeddedServer .executeQuery (
607
604
"let $a := <a><b/></a>" +
608
605
"return $a/b/c/fn:local-name()" );
@@ -619,31 +616,31 @@ public void name() throws XPathException, XMLDBException {
619
616
}
620
617
621
618
@ Test
622
- public void name_empty () throws XPathException , XMLDBException {
619
+ public void name_empty () throws XMLDBException {
623
620
final ResourceSet result = existEmbeddedServer .executeQuery (
624
621
"fn:name(())" );
625
622
final String r = (String ) result .getResource (0 ).getContent ();
626
623
assertEquals ("" , r );
627
624
}
628
625
629
626
@ Test
630
- public void name_emptyElement () throws XPathException , XMLDBException {
627
+ public void name_emptyElement () throws XMLDBException {
631
628
final ResourceSet result = existEmbeddedServer .executeQuery (
632
629
"<a>b</a>/fn:name(c)" );
633
630
final String r = (String ) result .getResource (0 ).getContent ();
634
631
assertEquals ("" , r );
635
632
}
636
633
637
634
@ Test
638
- public void name_emptyText () throws XPathException , XMLDBException {
635
+ public void name_emptyText () throws XMLDBException {
639
636
final ResourceSet result = existEmbeddedServer .executeQuery (
640
637
"<a>b</a>/fn:local-name(text())" );
641
638
final String r = (String ) result .getResource (0 ).getContent ();
642
639
assertEquals ("" , r );
643
640
}
644
641
645
642
@ Test
646
- public void name_contextItem () throws XPathException , XMLDBException {
643
+ public void name_contextItem () throws XMLDBException {
647
644
final ResourceSet result = existEmbeddedServer .executeQuery (
648
645
"let $a := <a><b/></a>" +
649
646
"return $a/b/fn:name()" );
@@ -652,15 +649,15 @@ public void name_contextItem() throws XPathException, XMLDBException {
652
649
}
653
650
654
651
@ Test
655
- public void name_contextItem_empty () throws XPathException , XMLDBException {
652
+ public void name_contextItem_empty () throws XMLDBException {
656
653
final ResourceSet result = existEmbeddedServer .executeQuery (
657
654
"let $a := <a><b/></a>" +
658
655
"return $a/b/c/fn:name()" );
659
656
assertEquals (0 , result .getSize ());
660
657
}
661
658
662
659
@ Test
663
- public void dateTimeConstructor () throws XPathException , XMLDBException {
660
+ public void dateTimeConstructor () throws XMLDBException {
664
661
ResourceSet result = existEmbeddedServer .executeQuery (
665
662
"let $date := xs:date('2007-05-02+02:00') " +
666
663
"return dateTime($date, xs:time('15:12:52.421+02:00'))"
@@ -670,7 +667,7 @@ public void dateTimeConstructor() throws XPathException, XMLDBException {
670
667
}
671
668
672
669
@ Test
673
- public void currentDateTime () throws XPathException , XMLDBException {
670
+ public void currentDateTime () throws XMLDBException {
674
671
//Do not use this test around midnight on the last day of a month ;-)
675
672
ResourceSet result = existEmbeddedServer .executeQuery (
676
673
"('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', " +
@@ -691,7 +688,7 @@ public void currentDateTime() throws XPathException, XMLDBException {
691
688
/**
692
689
* Bugfix 3070
693
690
*
694
- * @see http://svn.sourceforge.net/exist/?rev=3070&view=rev
691
+ * @see { http://svn.sourceforge.net/exist/?rev=3070&view=rev}
695
692
*
696
693
* seconds-from-dateTime() returned wrong value when dateTime had
697
694
* no millesecs available. Special value was returned.
@@ -751,7 +748,7 @@ public void namespaceURI() throws XMLDBException {
751
748
}
752
749
753
750
@ Test
754
- public void namespaceURI_contextItem () throws XPathException , XMLDBException {
751
+ public void namespaceURI_contextItem () throws XMLDBException {
755
752
final ResourceSet result = existEmbeddedServer .executeQuery (
756
753
"let $a := <a><exist:b/></a>" +
757
754
"return $a/exist:b/fn:namespace-uri()" );
@@ -796,28 +793,28 @@ public void nodeName() throws XMLDBException {
796
793
}
797
794
798
795
@ Test
799
- public void noeName_empty () throws XPathException , XMLDBException {
796
+ public void noeName_empty () throws XMLDBException {
800
797
final ResourceSet result = existEmbeddedServer .executeQuery (
801
798
"fn:node-name(())" );
802
799
assertEquals (0 , result .getSize ());
803
800
}
804
801
805
802
@ Test
806
- public void nodeName_emptyElement () throws XPathException , XMLDBException {
803
+ public void nodeName_emptyElement () throws XMLDBException {
807
804
final ResourceSet result = existEmbeddedServer .executeQuery (
808
805
"<a>b</a>/fn:node-name(c)" );
809
806
assertEquals (0 , result .getSize ());
810
807
}
811
808
812
809
@ Test
813
- public void nodeName_emptyText () throws XPathException , XMLDBException {
810
+ public void nodeName_emptyText () throws XMLDBException {
814
811
final ResourceSet result = existEmbeddedServer .executeQuery (
815
812
"<a>b</a>/fn:node-name(text())" );
816
813
assertEquals (0 , result .getSize ());
817
814
}
818
815
819
816
@ Test
820
- public void nodeName_contextItem () throws XPathException , XMLDBException {
817
+ public void nodeName_contextItem () throws XMLDBException {
821
818
final ResourceSet result = existEmbeddedServer .executeQuery (
822
819
"let $a := <a><b/></a>" +
823
820
"return $a/b/fn:node-name()" );
@@ -826,7 +823,7 @@ public void nodeName_contextItem() throws XPathException, XMLDBException {
826
823
}
827
824
828
825
@ Test
829
- public void nodeName_contextItem_empty () throws XPathException , XMLDBException {
826
+ public void nodeName_contextItem_empty () throws XMLDBException {
830
827
final ResourceSet result = existEmbeddedServer .executeQuery (
831
828
"let $a := <a><b/></a>" +
832
829
"return $a/b/c/fn:node-name()" );
@@ -978,11 +975,11 @@ private void runCollectionAvailableTest(String collectionPath, boolean expectedR
978
975
String query = importXMLDB + collectionAvailable ;
979
976
ResourceSet result = existEmbeddedServer .executeQuery (query );
980
977
assertNotNull (result );
981
- assertTrue ( result .getSize () == 1 );
978
+ assertEquals ( 1 , result .getSize ());
982
979
assertNotNull (result .getResource (0 ));
983
980
String content = (String ) result .getResource (0 ).getContent ();
984
981
assertNotNull (content );
985
- assertEquals (expectedResult , Boolean .valueOf (content ). booleanValue () );
982
+ assertEquals (expectedResult , Boolean .valueOf (content ));
986
983
}
987
984
988
985
@ Test
0 commit comments