Search in sources :

Example 6 with OutputVariable

use of org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable in project wikidata-query-rdf by wikimedia.

the class MWApiServiceCallUnitTest method testResultsBadXML.

@Test(expected = SAXException.class)
public void testResultsBadXML() throws Exception {
    List<OutputVariable> outputVars = ImmutableList.of(new OutputVariable(makeVariable("var"), "@test"));
    InputStream responseStream = new ByteArrayInputStream("Fatal error: I am a teapot".getBytes("UTF-8"));
    when(template.getItemsPath()).thenReturn("/api/result");
    Object results = createCall(outputVars).parseResponse(responseStream, binding);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputVariable(org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable) Test(org.junit.Test)

Example 7 with OutputVariable

use of org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable in project wikidata-query-rdf by wikimedia.

the class MWApiServiceCallUnitTest method testEmptyResult.

@Test
public void testEmptyResult() throws Exception {
    List<OutputVariable> outputVars = ImmutableList.of(new OutputVariable(makeVariable("var"), "@test"));
    InputStream responseStream = new ByteArrayInputStream("<result></result>".getBytes("UTF-8"));
    when(template.getItemsPath()).thenReturn("/api/result");
    Object results = createCall(outputVars).parseResponse(responseStream, binding);
    assertNull(results);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputVariable(org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable) Test(org.junit.Test)

Example 8 with OutputVariable

use of org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable in project wikidata-query-rdf by wikimedia.

the class MWApiServiceCallUnitTest method testResultsNoContinue.

@Test
public void testResultsNoContinue() throws Exception {
    List<OutputVariable> outputVars = ImmutableList.of(new OutputVariable(makeVariable("var"), "@name"));
    when(template.getItemsPath()).thenReturn("/api/result");
    InputStream responseStream = new ByteArrayInputStream("<api><header value=\"heading\"></header><result name=\"result1\">datadata</result></api>".getBytes("UTF-8"));
    ResultWithContinue results = createCall(outputVars).parseResponse(responseStream, binding);
    assertNull(results.getContinue());
}
Also used : ResultWithContinue(org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceCall.ResultWithContinue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputVariable(org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable) Test(org.junit.Test)

Example 9 with OutputVariable

use of org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable in project wikidata-query-rdf by wikimedia.

the class MWApiServiceCallUnitTest method testResultsWithContinue.

@Test
public void testResultsWithContinue() throws Exception {
    List<OutputVariable> outputVars = ImmutableList.of(new OutputVariable(makeVariable("var"), "@name"));
    when(template.getItemsPath()).thenReturn("/api/result");
    InputStream responseStream = new ByteArrayInputStream("<api><continue sroffset=\"5\" continue=\"-||\"></continue><header value=\"heading\"></header><result name=\"result1\">datadata</result></api>".getBytes("UTF-8"));
    ResultWithContinue results = createCall(outputVars).parseResponse(responseStream, binding);
    Map<String, String> continueMap = results.getContinue();
    assertThat(continueMap.keySet(), containsInAnyOrder("sroffset", "continue"));
    assertThat(continueMap, hasEntry("sroffset", "5"));
    assertThat(continueMap, hasEntry("continue", "-||"));
}
Also used : ResultWithContinue(org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceCall.ResultWithContinue) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputVariable(org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable) Test(org.junit.Test)

Aggregations

OutputVariable (org.wikidata.query.rdf.blazegraph.mwapi.ApiTemplate.OutputVariable)9 Test (org.junit.Test)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)7 IBindingSet (com.bigdata.bop.IBindingSet)3 ResultWithContinue (org.wikidata.query.rdf.blazegraph.mwapi.MWApiServiceCall.ResultWithContinue)2 IConstant (com.bigdata.bop.IConstant)1 JoinGroupNode (com.bigdata.rdf.sparql.ast.JoinGroupNode)1 StatementPatternNode (com.bigdata.rdf.sparql.ast.StatementPatternNode)1 VarNode (com.bigdata.rdf.sparql.ast.VarNode)1 ServiceNode (com.bigdata.rdf.sparql.ast.service.ServiceNode)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 XPath (javax.xml.xpath.XPath)1 XPathExpression (javax.xml.xpath.XPathExpression)1 URI (org.openrdf.model.URI)1 Document (org.w3c.dom.Document)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1