MCPcopy Create free account
hub / github.com/BaseXdb/basex / errors

Method errors

basex-api/src/test/java/org/basex/http/FnHttpTest.java:327–377  ·  view source on GitHub ↗

Tests if errors are thrown when some mandatory attributes are missing in a , or . @throws IOException I/O Exception

()

Source from the content-addressed store, hash-verified

325 * @throws IOException I/O Exception
326 */
327 @Test public final void errors() throws IOException {
328 // Incorrect requests
329 final HashMap<String, String> queries = new HashMap<>();
330
331 queries.put("Request without method",
332 "<http:request xmlns:http='http://expath.org/ns/http-client' "
333 + "href='" + REST_ROOT + "'/>");
334
335 queries.put("Request with send-authorization and only username",
336 "<http:request xmlns:http='http://expath.org/ns/http-client' "
337 + "method='GET' href='" + REST_ROOT + "' username='test'/>");
338
339 queries.put("Request with body that has no media-type",
340 "<http:request xmlns:http='http://expath.org/ns/http-client' "
341 + "method='POST' href='" + REST_ROOT + "'>" + "<http:body>"
342 + "</http:body>" + "</http:request>");
343
344 queries.put("Request with multipart that has no media-type",
345 "<http:request xmlns:http='http://expath.org/ns/http-client' "
346 + " method='POST' href='" + REST_ROOT + "'>" + "<http:multipart boundary='xxx'>"
347 + "</http:multipart>" + "</http:request>");
348
349 queries.put("Request with multipart with part that has a body without media-type",
350 "<http:request xmlns:http='http://expath.org/ns/http-client' "
351 + " method='POST' href='" + REST_ROOT + "'>" + "<http:multipart boundary='xxx'>"
352 + "<http:header name='hdr1' value-='val1'/>"
353 + "<http:body media-type='text/plain'>" + "Part1" + "</http:body>"
354 + "<http:header name='hdr1' value-='val1'/>"
355 + "<http:body>" + "Part1" + "</http:body>"
356 + "</http:multipart>" + "</http:request>");
357
358 queries.put("Request with schema different from http",
359 "<http:request xmlns:http='http://expath.org/ns/http-client' "
360 + "href='ftp://basex.org'/>");
361
362 final StringBuilder error = new StringBuilder();
363 for(final Entry<String, String> entry : queries.entrySet()) {
364 final String name = entry.getKey(), query = entry.getValue();
365 final DBNode dbNode = new DBNode(new IOContent(query));
366 try {
367 final RequestParser rp = new RequestParser(null);
368 rp.parse(dbNode.childIter().next(), Empty.VALUE);
369 error.append(name).append(": Request did not fail.");
370 } catch(final QueryException ex) {
371 if(!ex.getMessage().contains(ErrType.HC.toString())) {
372 error.append(name).append(": Wrong error code (").append(ex.getMessage()).append(")");
373 }
374 }
375 }
376 if(!error.isEmpty()) fail(error.toString());
377 }
378
379 /**
380 * Tests method setRequestContent of HttpClient.

Callers

nothing calls this directly

Calls 11

parseMethod · 0.95
childIterMethod · 0.95
getKeyMethod · 0.80
nextMethod · 0.65
appendMethod · 0.65
containsMethod · 0.65
toStringMethod · 0.65
putMethod · 0.45
getValueMethod · 0.45
getMessageMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected