protected void doTupleLinksAndStylesheetMultipleEndHeaders(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected, List<String> links, String stylesheetUrl) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); // Test for handling when startDocument and startHeader are not called writer.handleStylesheet(stylesheetUrl); writer.startQueryResult(input.getBindingNames()); writer.handleLinks(links); writer.endHeader(); writer.endHeader(); try { while (input.hasNext()) { BindingSet bindingSet = input.next(); writer.handleSolution(bindingSet); } } finally { input.close(); } writer.endQueryResult(); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); TupleQueryResult output = QueryResultIO.parseTuple(in, format); assertQueryResultsEqual(expected, output); }
protected void doTupleMissingStartQueryResult(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected, List<String> links, String stylesheetUrl) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); // Test for handling when startDocument and startHeader are not called writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); writer.endHeader(); try { while (input.hasNext()) { BindingSet bindingSet = input.next(); writer.handleSolution(bindingSet); } writer.endQueryResult(); fail("Expected exception when calling handleSolution without startQueryResult"); } catch (IllegalStateException ise) { // Expected exception } finally { input.close(); } }