solved misleading http status codes at sparql when wrongmissing model and missing query#50
Conversation
…pt to enilink SPARQL update Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
Adds a Scala/JUnit contract test suite to pin the SPARQL endpoint’s HTTP status/error-code behavior expected by linkedfactory-pod, aligning lf-pod with recent enilink SPARQL error handling changes.
Changes:
- Introduces
EnilinkSparqlContractTestcovering missing model/query/update, unknown model, unsupportedAccept, malformed SPARQL, and conflicting parameters. - Adds a small in-memory
IModelSetsetup to support the contract scenarios.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| modelSet = factory.createModelSet(MODELS.NAMESPACE_URI.appendFragment("MemoryModelSet")) | ||
| Globals.contextModelSet.default.set(Full(modelSet)) | ||
|
|
||
| val model = modelSet.createModel(sensorModel) | ||
| val em = model.getManager | ||
| em.add(new Statement( | ||
| URIs.createURI("http://example.org/sensors/temp-01"), | ||
| URIs.createURI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"), | ||
| URIs.createURI("http://example.org/vocab/Sensor") | ||
| )) | ||
| } | ||
|
|
||
| @AfterClass | ||
| def tearDown(): Unit = { | ||
| if (modelSet != null) { | ||
| modelSet.dispose() | ||
| modelSet = null | ||
| } |
There was a problem hiding this comment.
Globals.contextModelSet.default is set in setup(), but tearDown() only disposes modelSet and does not clear/reset the global. Because Full(modelSet) still holds a reference to the disposed model set, later tests can accidentally vend a disposed instance. Please reset/unset Globals.contextModelSet.default in tearDown() (e.g., set it to Empty/remove) before disposing/nulling the modelSet.
| @Test | ||
| def missingModelReturns400(): Unit = { | ||
| val req = new MockHttpServletRequest(baseUrl) { | ||
| method = "GET" | ||
| parameters = List("query" -> "SELECT ?s WHERE { ?s ?p ?o }") | ||
| headers = Map("Accept" -> List("application/sparql-results+json")) | ||
| } | ||
| assertErrorContract(execute(req), 400, "MISSING_MODEL:") | ||
| } |
There was a problem hiding this comment.
The PR description indicates these contract assertions are expected to fail until a newer enilink snapshot is released. Adding a test that is knowingly failing will break CI for this repo unless the enilink dependency version is bumped in the same PR (or the test is temporarily gated, e.g. via @Ignore / an assumption that checks the dependency capability). Please ensure the build remains green on merge by updating the dependency or gating this test until the required enilink version is available.
After update in enilink with HTTP Codes for SPARQL Endpoint, the new functionalit is tested as contract in lf-pod.
Tests should fail, until enilink is released as new snapshot and then resolve.