use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector in project rdf4j by eclipse.
the class SPARQLJSONTupleTest method testNonStandardDistinct.
@Test
public void testNonStandardDistinct() throws Exception {
SPARQLResultsJSONParser parser = new SPARQLResultsJSONParser(SimpleValueFactory.getInstance());
QueryResultCollector handler = new QueryResultCollector();
parser.setQueryResultHandler(handler);
InputStream stream = this.getClass().getResourceAsStream("/sparqljson/non-standard-distinct.srj");
assertNotNull("Could not find test resource", stream);
parser.parseQueryResult(stream);
// there must be 1 variable
assertEquals(1, handler.getBindingNames().size());
// first must be called "Concept", etc.,
assertEquals("Concept", handler.getBindingNames().get(0));
// -1 results
assertEquals(100, handler.getBindingSets().size());
}
use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector in project rdf4j by eclipse.
the class SPARQLJSONTupleTest method testBindings1.
@Test
public void testBindings1() throws Exception {
SPARQLResultsJSONParser parser = new SPARQLResultsJSONParser(SimpleValueFactory.getInstance());
QueryResultCollector handler = new QueryResultCollector();
parser.setQueryResultHandler(handler);
InputStream stream = this.getClass().getResourceAsStream("/sparqljson/bindings1.srj");
assertNotNull("Could not find test resource", stream);
parser.parseQueryResult(stream);
// there must be two variables
assertEquals(2, handler.getBindingNames().size());
// first must be called "book", the second "title"
assertEquals("book", handler.getBindingNames().get(0));
assertEquals("title", handler.getBindingNames().get(1));
// should be 7 solutions alltogether
assertEquals(7, handler.getBindingSets().size());
// Results are ordered, so first should be book6
assertEquals("http://example.org/book/book6", handler.getBindingSets().get(0).getValue("book").stringValue());
for (BindingSet b : handler.getBindingSets()) {
assertNotNull(b.getValue("book"));
assertNotNull(b.getValue("title"));
assertTrue(b.getValue("book") instanceof IRI);
assertTrue(b.getValue("title") instanceof Literal);
IRI book = (IRI) b.getValue("book");
if (book.stringValue().equals("http://example.org/book/book6")) {
assertEquals("Harry Potter and the Half-Blood Prince", b.getValue("title").stringValue());
} else if (book.stringValue().equals("http://example.org/book/book7")) {
assertEquals("Harry Potter and the Deathly Hallows", b.getValue("title").stringValue());
} else if (book.stringValue().equals("http://example.org/book/book5")) {
assertEquals("Harry Potter and the Order of the Phoenix", b.getValue("title").stringValue());
} else if (book.stringValue().equals("http://example.org/book/book4")) {
assertEquals("Harry Potter and the Goblet of Fire", b.getValue("title").stringValue());
} else if (book.stringValue().equals("http://example.org/book/book2")) {
assertEquals("Harry Potter and the Chamber of Secrets", b.getValue("title").stringValue());
} else if (book.stringValue().equals("http://example.org/book/book3")) {
assertEquals("Harry Potter and the Prisoner Of Azkaban", b.getValue("title").stringValue());
} else if (book.stringValue().equals("http://example.org/book/book1")) {
assertEquals("Harry Potter and the Philosopher's Stone", b.getValue("title").stringValue());
} else {
fail("Found unexpected binding set in result: " + b.toString());
}
}
}
use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector in project rdf4j by eclipse.
the class SPARQLXMLParserCustomTest method testEntityExpansionUnrelatedSettings.
/**
* Test with unrelated ParserConfig settings
*
* @throws Exception
*/
@Test
public void testEntityExpansionUnrelatedSettings() throws Exception {
ParserConfig config = new ParserConfig();
QueryResultCollector handler = new QueryResultCollector();
ParseErrorCollector errorCollector = new ParseErrorCollector();
QueryResultParser aParser = QueryResultIO.createTupleParser(TupleQueryResultFormat.SPARQL).setQueryResultHandler(handler).setParserConfig(config).setParseErrorListener(errorCollector);
try {
// this should trigger a SAX parse exception that will blow up at
// the 64k entity limit rather than OOMing
aParser.parseQueryResult(this.getClass().getResourceAsStream("/sparqlxml/bad-entity-expansion-limit.srx"));
fail("Parser did not throw an exception");
} catch (QueryResultParseException e) {
// assertTrue(e.getMessage().contains(
// "The parser has encountered more than \"64,000\" entity
// expansions in this document; this is the limit imposed by the
// "));
}
assertEquals(0, errorCollector.getWarnings().size());
assertEquals(0, errorCollector.getErrors().size());
assertEquals(1, errorCollector.getFatalErrors().size());
}
use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector in project rdf4j by eclipse.
the class SPARQLXMLParserCustomTest method testEntityExpansionDefaultSettings.
/**
* Test with the default ParserConfig settings. Ie, setParserConfig is not
* called.
*
* @throws Exception
*/
@Test
public void testEntityExpansionDefaultSettings() throws Exception {
QueryResultCollector handler = new QueryResultCollector();
ParseErrorCollector errorCollector = new ParseErrorCollector();
QueryResultParser aParser = QueryResultIO.createTupleParser(TupleQueryResultFormat.SPARQL).setQueryResultHandler(handler).setParseErrorListener(errorCollector);
try {
// this should trigger a SAX parse exception that will blow up at
// the 64k entity limit rather than OOMing
aParser.parseQueryResult(this.getClass().getResourceAsStream("/sparqlxml/bad-entity-expansion-limit.srx"));
fail("Parser did not throw an exception");
} catch (QueryResultParseException e) {
// assertTrue(e.getMessage().contains(
// "The parser has encountered more than \"64,000\" entity
// expansions in this document; this is the limit imposed by the
// "));
}
assertEquals(0, errorCollector.getWarnings().size());
assertEquals(0, errorCollector.getErrors().size());
assertEquals(1, errorCollector.getFatalErrors().size());
}
use of org.eclipse.rdf4j.query.resultio.helpers.QueryResultCollector in project rdf4j by eclipse.
the class SPARQLXMLParserCustomTest method testEntityExpansionSecureProcessing.
/**
* Test with Secure processing setting on.
*
* @throws Exception
*/
@Test
public void testEntityExpansionSecureProcessing() throws Exception {
QueryResultCollector handler = new QueryResultCollector();
ParseErrorCollector errorCollector = new ParseErrorCollector();
QueryResultParser aParser = QueryResultIO.createTupleParser(TupleQueryResultFormat.SPARQL).setQueryResultHandler(handler).set(XMLParserSettings.SECURE_PROCESSING, true).setParseErrorListener(errorCollector);
try {
// this should trigger a SAX parse exception that will blow up at
// the 64k entity limit rather than OOMing
aParser.parseQueryResult(this.getClass().getResourceAsStream("/sparqlxml/bad-entity-expansion-limit.srx"));
fail("Parser did not throw an exception");
} catch (QueryResultParseException e) {
// assertTrue(e.getMessage().contains(
// "The parser has encountered more than \"64,000\" entity
// expansions in this document; this is the limit imposed by the
// "));
}
assertEquals(0, errorCollector.getWarnings().size());
assertEquals(0, errorCollector.getErrors().size());
assertEquals(1, errorCollector.getFatalErrors().size());
}
Aggregations