Skip to content

Commit a8d66d8

Browse files
committed
[test] Add tests for setting XQuery external variables of type xs:string via the eXist-db XML:DB API
1 parent 234c7ee commit a8d66d8

File tree

4 files changed

+443
-15
lines changed

4 files changed

+443
-15
lines changed

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@
764764
<include>src/main/java/org/exist/util/OSUtil.java</include>
765765
<include>src/main/java/org/exist/util/StringUtil.java</include>
766766
<include>src/test/java/org/exist/util/serializer/SAXSerializerTest.java</include>
767+
<include>src/test/java/org/exist/xmldb/XMLDBExternalVariableTest.java</include>
767768
<include>src/test/resources-filtered/org/exist/xquery/import-from-pkg-test.conf.xml</include>
768769
<include>src/test/java/org/exist/xquery/ImportFromPkgTest.java</include>
769770
<include>src/main/java/org/exist/xquery/JavaBinding.java</include>
@@ -1698,6 +1699,7 @@
16981699
<exclude>src/test/java/org/exist/xmldb/SerializationTest.java</exclude>
16991700
<exclude>src/test/java/org/exist/xmldb/TestEXistXMLSerialize.java</exclude>
17001701
<exclude>src/test/java/org/exist/xmldb/TreeLevelOrderTest.java</exclude>
1702+
<exclude>src/test/java/org/exist/xmldb/XMLDBExternalVariableTest.java</exclude>
17011703
<exclude>src/test/java/org/exist/xmldb/concurrent/AbstractConcurrentTest.java</exclude>
17021704
<exclude>src/test/java/org/exist/xmldb/concurrent/ComplexUpdateTest.java</exclude>
17031705
<exclude>src/test/java/org/exist/xmldb/concurrent/ConcurrentAttrUpdateTest.java</exclude>

exist-core/src/main/java/org/exist/xquery/VariableImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,22 +156,22 @@ public void setSequenceType(SequenceType type) throws XPathException {
156156
else {actualCardinality = Cardinality.EXACTLY_ONE;}
157157
//Type.EMPTY is *not* a subtype of other types ; checking cardinality first
158158
if (!getSequenceType().getCardinality().isSuperCardinalityOrEqualOf(actualCardinality))
159-
{throw new XPathException(getValue(), "XPTY0004: Invalid cardinality for variable $" + getQName() +
159+
{throw new XPathException(getValue(), ErrorCodes.W3CErrorCode.XPTY0004, "Invalid cardinality for variable $" + getQName() +
160160
". Expected " +
161161
getSequenceType().getCardinality().getHumanDescription() +
162162
", got " + actualCardinality.getHumanDescription());}
163163
//TODO : ignore nodes right now ; they are returned as xs:untypedAtomicType
164164
if (!Type.subTypeOf(getSequenceType().getPrimaryType(), Type.NODE)) {
165165
if (!getValue().isEmpty() && !Type.subTypeOf(getValue().getItemType(), getSequenceType().getPrimaryType()))
166-
{throw new XPathException(getValue(), "XPTY0004: Invalid type for variable $" + getQName() +
166+
{throw new XPathException(getValue(), ErrorCodes.W3CErrorCode.XPTY0004, "Invalid type for variable $" + getQName() +
167167
". Expected " +
168168
Type.getTypeName(getSequenceType().getPrimaryType()) +
169169
", got " +Type.getTypeName(getValue().getItemType()));}
170170
//Here is an attempt to process the nodes correctly
171171
} else {
172172
//Same as above : we probably may factorize
173173
if (!getValue().isEmpty() && !Type.subTypeOf(getValue().getItemType(), getSequenceType().getPrimaryType()))
174-
{throw new XPathException(getValue(), "XPTY0004: Invalid type for variable $" + getQName() +
174+
{throw new XPathException(getValue(), ErrorCodes.W3CErrorCode.XPTY0004, "Invalid type for variable $" + getQName() +
175175
". Expected " +
176176
Type.getTypeName(getSequenceType().getPrimaryType()) +
177177
", got " +Type.getTypeName(getValue().getItemType()));}

exist-core/src/test/java/org/exist/http/RESTExternalVariableTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public void queryPostWithExternalVariableDocumentSuppliedDocuments() throws IOEx
453453
@Test
454454
public void queryPostWithExternalVariableDocumentSuppliedUntyped() throws IOException {
455455
final ExternalVariableValueRep externalVariable = value("<hello>world</hello>");
456-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
456+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
457457
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "document-node()", externalVariable);
458458
}
459459

@@ -495,7 +495,7 @@ public void queryPostWithExternalVariableOptDocumentSuppliedDocuments() throws I
495495
@Test
496496
public void queryPostWithExternalVariableOptDocumentSuppliedUntyped() throws IOException {
497497
final ExternalVariableValueRep externalVariable = value("<hello>world</hello>");
498-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
498+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
499499
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "document-node()?", externalVariable);
500500
}
501501

@@ -525,14 +525,14 @@ public void queryPostWithExternalVariableDocumentsSuppliedDocuments() throws IOE
525525
@Test
526526
public void queryPostWithExternalVariableDocumentsSuppliedUntyped() throws IOException {
527527
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("<hello>world</hello>") };
528-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
528+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
529529
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "document-node()+", externalVariable);
530530
}
531531

532532
@Test
533533
public void queryPostWithExternalVariableDocumentsSuppliedUntypeds() throws IOException {
534534
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("<hello>world</hello>"), value("<goodbye>see you soon</goodbye>") };
535-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
535+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
536536
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "document-node()+", externalVariable);
537537
}
538538

@@ -562,14 +562,14 @@ public void queryPostWithExternalVariableDocumentzSuppliedDocuments() throws IOE
562562
@Test
563563
public void queryPostWithExternalVariableDocumentszSuppliedUntyped() throws IOException {
564564
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("<hello>world</hello>") };
565-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
565+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
566566
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "document-node()*", externalVariable);
567567
}
568568

569569
@Test
570570
public void queryPostWithExternalVariableDocumentzSuppliedUntypeds() throws IOException {
571571
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("<hello>world</hello>"), value("<goodbye>see you soon</goodbye>") };
572-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
572+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected document-node(), got element()</message></exception>";
573573
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "document-node()*", externalVariable);
574574
}
575575

@@ -917,7 +917,7 @@ public void queryPostWithExternalVariableTextSuppliedTexts() throws IOException
917917
@Test
918918
public void queryPostWithExternalVariableTextSuppliedUntyped() throws IOException {
919919
final ExternalVariableValueRep externalVariable = value("hello world");
920-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
920+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
921921
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "text()", externalVariable);
922922
}
923923

@@ -961,7 +961,7 @@ public void queryPostWithExternalVariableOptTextSuppliedTexts() throws IOExcepti
961961
@Test
962962
public void queryPostWithExternalVariableOptTextSuppliedUntyped() throws IOException {
963963
final ExternalVariableValueRep externalVariable = value("hello world");
964-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
964+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
965965
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "text()?", externalVariable);
966966
}
967967

@@ -991,14 +991,14 @@ public void queryPostWithExternalVariableTextsSuppliedTexts() throws IOException
991991
@Test
992992
public void queryPostWithExternalVariableTextsSuppliedUntyped() throws IOException {
993993
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("hello world") };
994-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
994+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
995995
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "text()+", externalVariable);
996996
}
997997

998998
@Test
999999
public void queryPostWithExternalVariableTextsSuppliedUntypeds() throws IOException {
10001000
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("hello world"), value("goodbye see you soon") };
1001-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
1001+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
10021002
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "text()+", externalVariable);
10031003
}
10041004

@@ -1028,14 +1028,14 @@ public void queryPostWithExternalVariableTextzSuppliedTexts() throws IOException
10281028
@Test
10291029
public void queryPostWithExternalVariableTextszSuppliedUntyped() throws IOException {
10301030
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("hello world") };
1031-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
1031+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
10321032
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "text()*", externalVariable);
10331033
}
10341034

10351035
@Test
10361036
public void queryPostWithExternalVariableTextzSuppliedUntypeds() throws IOException {
10371037
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("hello world"), value("goodbye see you soon") };
1038-
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>exerr:ERROR XPTY0004: Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
1038+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected text(), got xs:string</message></exception>";
10391039
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "text()*", externalVariable);
10401040
}
10411041

0 commit comments

Comments
 (0)