Skip to content

Commit

Permalink
Print query result source URL
Browse files Browse the repository at this point in the history
  • Loading branch information
wschella authored and rubensworks committed Feb 13, 2019
1 parent 3ecd178 commit a3fc0c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/testcase/sparql/QueryResultBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class QueryResultBindings implements IQueryResultBindings {
// At this point, the keys are equal, so we check if the actual count is not more than the expected count
for (const key in countedBindingsActual) {
if (countedBindingsActual[key] > countedBindingsExpected[key]) {
// The actual value contains *more* occurences for this binding than allowed
// The actual value contains *more* occurrences for this binding than allowed
return false;
}
}
Expand Down
53 changes: 32 additions & 21 deletions lib/testcase/sparql/TestCaseQueryEvaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {stringToTerm} from "rdf-string";
import {mapTerms, QuadTermName} from "rdf-terms";
import {SparqlJsonParser} from "sparqljson-parse";
import {SparqlXmlParser} from "sparqlxml-parse";
import {Util} from "../../Util";
import {Util, IFetchResponse} from "../../Util";
import {ITestCaseData} from "../ITestCase";
import {ITestCaseHandler} from "../ITestCaseHandler";
import {IQueryEngine, IQueryResult, IQueryResultBindings} from "./IQueryEngine";
Expand Down Expand Up @@ -223,19 +223,33 @@ export class TestCaseQueryEvaluationHandler implements ITestCaseHandler<TestCase
(value: RDF.Term, key: QuadTermName) => key === 'graph' ? dataGraph : value));
}
const queryResponse = await Util.fetchCached(resource.property.result.value, cachePath);
return new TestCaseQueryEvaluation(testCaseData,
await stringifyStream((await Util.fetchCached(action.property.query.value, cachePath)).body),
queryData,
await TestCaseQueryEvaluationHandler.parseQueryResult(
Util.identifyContentType(queryResponse.url, queryResponse.headers),
queryResponse.url, queryResponse.body),
laxCardinality,
dataUri,
dataGraph);
return new TestCaseQueryEvaluation(
testCaseData,
{
dataGraph,
dataUri,
laxCardinality,
queryData,
queryResult: await TestCaseQueryEvaluationHandler.parseQueryResult(
Util.identifyContentType(queryResponse.url, queryResponse.headers),
queryResponse.url, queryResponse.body),
queryString: await stringifyStream((await Util.fetchCached(action.property.query.value, cachePath)).body),
resultSource: queryResponse,
});
}

}

export interface ITestCaseQueryEvaluationProps {
queryString: string;
queryData: RDF.Quad[];
queryResult: IQueryResult;
laxCardinality: boolean;
resultSource: IFetchResponse;
dataGraph?: RDF.NamedNode;
dataUri?: string;
}

export class TestCaseQueryEvaluation implements ITestCaseSparql {
public readonly type = "sparql";
public readonly approval: string;
Expand All @@ -249,18 +263,13 @@ export class TestCaseQueryEvaluation implements ITestCaseSparql {
public readonly queryData: RDF.Quad[];
public readonly queryResult: IQueryResult;
public readonly laxCardinality: boolean;
public readonly dataUri: string;
public readonly dataGraph: RDF.NamedNode;
public readonly dataUri?: string;
public readonly dataGraph?: RDF.NamedNode;
public readonly resultSource: IFetchResponse;

constructor(testCaseData: ITestCaseData, queryString: string, queryData: RDF.Quad[],
queryResult: IQueryResult, laxCardinality: boolean, dataUri: string, dataGraph: RDF.NamedNode) {
constructor(testCaseData: ITestCaseData, props: ITestCaseQueryEvaluationProps) {
Object.assign(this, testCaseData);
this.queryString = queryString;
this.queryData = queryData;
this.queryResult = queryResult;
this.laxCardinality = laxCardinality;
this.dataUri = dataUri;
this.dataGraph = dataGraph;
Object.assign(this, props);
}

public async test(engine: IQueryEngine, injectArguments: any): Promise<void> {
Expand All @@ -269,10 +278,12 @@ export class TestCaseQueryEvaluation implements ITestCaseSparql {
if (!await this.queryResult.equals(result, this.laxCardinality)) {
throw new Error(`Invalid query evaluation
Query: ${this.queryString}
Query:\n\n${this.queryString}
Data: ${this.dataUri || 'none'}${dataGraphInfo}
Result Source: ${this.resultSource.url}
Expected: ${this.queryResult.toString()}
Got: \n ${result.toString()}
Expand Down

0 comments on commit a3fc0c4

Please sign in to comment.