Skip to content

Commit ebdc3d0

Browse files
committed
[test] Tighten up tests for setting XQuery external variables of type attribute() via the eXist-db REST API
1 parent a8d66d8 commit ebdc3d0

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,9 @@ public void queryPostWithExternalVariableTextzSuppliedUntypeds() throws IOExcept
10421042
@Test
10431043
public void queryPostWithExternalVariableUntypedSuppliedUntypedAttribute() throws IOException {
10441044
final ExternalVariableValueRep externalVariable = value("hello", "world");
1045-
queryPostWithExternalVariable(HttpStatus.OK_200, null, externalVariable);
1045+
// NOTE(AR) we expect this to return xs:string because neither the input nor the variable is actually typed as attribute()
1046+
final ExternalVariableValueRep[] expectedResult = new ExternalVariableValueRep[] { value(Type.STRING, "world") };
1047+
queryPostWithExternalVariable(HttpStatus.OK_200, expectedResult, null, externalVariable);
10461048
}
10471049

10481050
@Test
@@ -1078,13 +1080,16 @@ public void queryPostWithExternalVariableAttributeSuppliedAttributes() throws IO
10781080
@Test
10791081
public void queryPostWithExternalVariableAttributeSuppliedUntyped() throws IOException {
10801082
final ExternalVariableValueRep externalVariable = value("revt:hello", "world");
1081-
queryPostWithExternalVariable(HttpStatus.OK_200, "attribute()", externalVariable);
1083+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected attribute(), got xs:string</message></exception>";
1084+
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "attribute()", externalVariable);
10821085
}
10831086

10841087
@Test
10851088
public void queryPostWithExternalVariableUntypedSuppliedUntypedAttributes() throws IOException {
10861089
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("revt:hello", "world"), value("goodbye", "see you soon") };
1087-
queryPostWithExternalVariable(HttpStatus.OK_200, null, externalVariable);
1090+
// NOTE(AR) we expect this to return xs:string because neither the input nor the variable is actually typed as attribute()
1091+
final ExternalVariableValueRep[] expectedResult = new ExternalVariableValueRep[] { value(Type.STRING, "world"), value(Type.STRING, "see you soon") };
1092+
queryPostWithExternalVariable(HttpStatus.OK_200, expectedResult, null, externalVariable);
10881093
}
10891094

10901095
@Test
@@ -1119,7 +1124,8 @@ public void queryPostWithExternalVariableOptAttributeSuppliedAttributes() throws
11191124
@Test
11201125
public void queryPostWithExternalVariableOptAttributeSuppliedUntyped() throws IOException {
11211126
final ExternalVariableValueRep externalVariable = value("revt:hello", "world");
1122-
queryPostWithExternalVariable(HttpStatus.OK_200, "attribute()?", externalVariable);
1127+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected attribute(), got xs:string</message></exception>";
1128+
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "attribute()?", externalVariable);
11231129
}
11241130

11251131
@Test
@@ -1148,13 +1154,15 @@ public void queryPostWithExternalVariableAttributesSuppliedAttributes() throws I
11481154
@Test
11491155
public void queryPostWithExternalVariableAttributesSuppliedUntyped() throws IOException {
11501156
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("revt:hello", "world") };
1151-
queryPostWithExternalVariable(HttpStatus.OK_200, "attribute()+", externalVariable);
1157+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected attribute(), got xs:string</message></exception>";
1158+
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "attribute()+", externalVariable);
11521159
}
11531160

11541161
@Test
11551162
public void queryPostWithExternalVariableAttributesSuppliedUntypeds() throws IOException {
11561163
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("revt:hello", "world"), value("goodbye", "see you soon") };
1157-
queryPostWithExternalVariable(HttpStatus.OK_200, "attribute()+", externalVariable);
1164+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected attribute(), got xs:string</message></exception>";
1165+
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "attribute()+", externalVariable);
11581166
}
11591167

11601168
@Test
@@ -1183,13 +1191,15 @@ public void queryPostWithExternalVariableAttributezSuppliedAttributes() throws I
11831191
@Test
11841192
public void queryPostWithExternalVariableAttributeszSuppliedUntyped() throws IOException {
11851193
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("revt:hello", "world") };
1186-
queryPostWithExternalVariable(HttpStatus.OK_200, "attribute()*", externalVariable);
1194+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected attribute(), got xs:string</message></exception>";
1195+
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "attribute()*", externalVariable);
11871196
}
11881197

11891198
@Test
11901199
public void queryPostWithExternalVariableAttributezSuppliedUntypeds() throws IOException {
11911200
final ExternalVariableValueRep[] externalVariable = new ExternalVariableValueRep[] { value("revt:hello", "world"), value("goodbye", "see you soon") };
1192-
queryPostWithExternalVariable(HttpStatus.OK_200, "attribute()*", externalVariable);
1201+
final String expectedResponseError = "<exception><path>/db/test/test.xml</path><message>err:XPTY0004 Invalid type for variable $local:my-variable. Expected attribute(), got xs:string</message></exception>";
1202+
queryPostWithExternalVariable(Tuple(HttpStatus.BAD_REQUEST_400, expectedResponseError), "attribute()*", externalVariable);
11931203
}
11941204

11951205
@Test
@@ -1765,7 +1775,7 @@ private static void buildQueryExternalVariableSequence(final StringBuilder build
17651775
builder.append(" type=\"").append(Type.getTypeName(((ExternalVariableTypedValueRep) externalVariableSequenceItem).getXdmType())).append("\"");
17661776
}
17671777

1768-
if (externalVariableSequenceItem instanceof NamedValueRep) {
1778+
if (externalVariableSequenceItem instanceof TypedNamedValueRep) {
17691779
// Attribute Node type
17701780
final String name = ((NamedValueRep) externalVariableSequenceItem).getName();
17711781
builder.append(" name=\"").append(name).append("\"");

0 commit comments

Comments
 (0)