Skip to content

Commit e4b69c8

Browse files
committed
Tests for adaptive and JSON serialization of Query results
Closes #9
1 parent 1a81caf commit e4b69c8

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/test/java/com/fusiondb/studio/api/QueryIT.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,76 @@ public void serializeQueryAsXmlIndent() {
230230
assertThat().
231231
body("results", is("<a>\n <b>hello</b>\n</a>"));
232232
}
233+
234+
@Test
235+
public void serializeQueryAsAdaptive() {
236+
final Map<String, Object> requestBody = mapOf(
237+
Tuple("query", "( map {'x': 'y'}, <a>hello</a>, xs:date('2020-01-01') )"),
238+
Tuple("defaultSerialization", mapOf(
239+
Tuple("method", "adaptive")
240+
))
241+
);
242+
243+
given().
244+
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
245+
contentType(JSON).
246+
body(requestBody).
247+
when().
248+
post(getApiBaseUri() + "/query").
249+
then().
250+
statusCode(SC_OK).
251+
assertThat().
252+
body("results", is("map{\"x\":\"y\"}\n" +
253+
"<a>hello</a>\n" +
254+
"xs:date(\"2020-01-01\")"));
255+
}
256+
257+
@Test
258+
public void serializeQueryAsJsonNoIndent() {
259+
final Map<String, Object> requestBody = mapOf(
260+
Tuple("query", "map {'a': 'b', 'x': ['y', 'z'], 't': true(), 'f': false() }"),
261+
Tuple("defaultSerialization", mapOf(
262+
Tuple("method", "json"),
263+
Tuple("indent", false)
264+
))
265+
);
266+
267+
given().
268+
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
269+
contentType(JSON).
270+
body(requestBody).
271+
when().
272+
post(getApiBaseUri() + "/query").
273+
then().
274+
statusCode(SC_OK).
275+
assertThat().
276+
body("results", is("{\"a\":\"b\",\"x\":[\"y\",\"z\"],\"t\":true,\"f\":false}"));
277+
}
278+
279+
@Test
280+
public void serializeQueryAsJsonIndent() {
281+
final Map<String, Object> requestBody = mapOf(
282+
Tuple("query", "map {'a': 'b', 'x': ['y', 'z'], 't': true(), 'f': false() }"),
283+
Tuple("defaultSerialization", mapOf(
284+
Tuple("method", "json"),
285+
Tuple("indent", true)
286+
))
287+
);
288+
289+
given().
290+
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
291+
contentType(JSON).
292+
body(requestBody).
293+
when().
294+
post(getApiBaseUri() + "/query").
295+
then().
296+
statusCode(SC_OK).
297+
assertThat().
298+
body("results", is("{\n" +
299+
" \"a\" : \"b\",\n" +
300+
" \"x\" : [ \"y\", \"z\" ],\n" +
301+
" \"t\" : true,\n" +
302+
" \"f\" : false\n" +
303+
"}"));
304+
}
233305
}

0 commit comments

Comments
 (0)