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(); } }
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 doTupleLinksAndStylesheetAndNamespaces(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected, List<String> links, String stylesheetUrl, Map<String, String> namespaces) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); for (String nextPrefix : namespaces.keySet()) { writer.handleNamespace(nextPrefix, namespaces.get(nextPrefix)); } writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); QueryResults.report(input, writer); // 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 doTupleLinksAndStylesheet(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); writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); QueryResults.report(input, writer); // 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 doTupleLinks(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected, List<String> links) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); writer.startDocument(); writer.startHeader(); writer.handleLinks(links); QueryResults.report(input, writer); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); TupleQueryResult output = QueryResultIO.parseTuple(in, format); assertQueryResultsEqual(expected, output); }
if (writer.getSupportedSettings().contains(BasicQueryWriterSettings.ADD_SESAME_QNAME)) { writer.getWriterConfig().set(BasicQueryWriterSettings.ADD_SESAME_QNAME, true); writer.handleNamespace(nextPrefix, namespaces.get(nextPrefix)); writer.startDocument(); writer.handleStylesheet(stylesheetUrl); writer.startHeader(); writer.handleLinks(links); QueryResults.report(input, writer); if (writer.getSupportedSettings().contains(BasicQueryWriterSettings.ADD_SESAME_QNAME)) { assertTrue(result.contains("test:bindingA")); assertFalse(result.contains("other:bindingB"));
private TupleQueryResultWriter getTupleResultWriter(String format, OutputStream os) { TupleQueryResultFormat resultFormat; if(format == null) { resultFormat = TupleQueryResultFormat.SPARQL; } else { resultFormat = QueryResultIO.getWriterFormatForMIMEType(format); if(resultFormat == null) { throw new InvalidArgumentException("could not produce format "+format); } } TupleQueryResultWriter writer = QueryResultIO.createWriter(resultFormat, os); if(writer.getSupportedSettings().contains(SPARQLHTMLSettings.TEMPLATING_SERVICE)) { writer.getWriterConfig().set(SPARQLHTMLSettings.TEMPLATING_SERVICE, templatingService); } return writer; }
w.handleBoolean(iter.hasNext()); } else { final List<String> columnHeaders = new LinkedList<>(); w.startQueryResult(columnHeaders); int count = 0; while (iter.hasNext() && count < limit) { w.handleSolution(iter.next()); count++; w.endQueryResult();
protected void doTupleLinksAndStylesheetNoStarts(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.handleLinks(links); QueryResults.report(input, writer); // System.out.println("output: " + out.toString("UTF-8")); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); TupleQueryResult output = QueryResultIO.parseTuple(in, format); assertQueryResultsEqual(expected, output); }
private TupleQueryResultWriter getTupleResultWriter(String format, OutputStream os) { TupleQueryResultFormat resultFormat; if(format == null) { resultFormat = TupleQueryResultFormat.SPARQL; } else { resultFormat = QueryResultIO.getWriterFormatForMIMEType(format); if(resultFormat == null) { throw new InvalidArgumentException("could not produce format "+format); } } TupleQueryResultWriter writer = QueryResultIO.createWriter(resultFormat, os); if(writer.getSupportedSettings().contains(SPARQLHTMLSettings.TEMPLATING_SERVICE)) { writer.getWriterConfig().set(SPARQLHTMLSettings.TEMPLATING_SERVICE, templatingService); } return writer; }
/** * Test specifically for JSONP callback support. */ protected void doTupleJSONPCallback(TupleQueryResultFormat format, TupleQueryResult input, TupleQueryResult expected) throws QueryResultHandlerException, QueryEvaluationException, QueryResultParseException, UnsupportedQueryResultFormatException, IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(4096); TupleQueryResultWriter writer = QueryResultIO.createTupleWriter(format, out); // only do this test if the callback is enabled if (writer.getSupportedSettings().contains(BasicQueryWriterSettings.JSONP_CALLBACK)) { String callback = "nextfunctionname" + Math.abs(new Random().nextInt()); writer.getWriterConfig().set(BasicQueryWriterSettings.JSONP_CALLBACK, callback); QueryResults.report(input, writer); String result = out.toString("UTF-8"); // System.out.println("output: " + result); assertTrue(result.startsWith(callback + "(")); assertTrue(result.endsWith(");")); // Strip off the callback function and verify that it contains a valid // JSON object containing the correct results result = result.substring(callback.length() + 1, result.length() - 2); ByteArrayInputStream in = new ByteArrayInputStream(result.getBytes("UTF-8")); TupleQueryResult output = QueryResultIO.parseTuple(in, format); assertQueryResultsEqual(expected, output); } }
TupleQueryResult tupleQueryResult = (TupleQueryResult)model.get(QUERY_RESULT_KEY); if (qrWriter.getSupportedSettings().contains(BasicQueryWriterSettings.JSONP_CALLBACK)) { String parameter = request.getParameter(DEFAULT_JSONP_CALLBACK_PARAMETER); qrWriter.getWriterConfig().set(BasicQueryWriterSettings.JSONP_CALLBACK, parameter);