Skip to content

Commit

Permalink
#38, tests for delete
Browse files Browse the repository at this point in the history
  • Loading branch information
manonthegithub committed Jun 25, 2024
1 parent defc710 commit 2898c4a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/main/scala/org/dbpedia/databus/ApiImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,8 @@ class ApiImpl(config: Config) extends DatabusApi {
override def getGraph(repo: String, path: String, prefix: Option[String])(request: javax.servlet.http.HttpServletRequest): scala.util.Try[String] =
readGraph(repo, path, prefix)(request)

override def getGraphMapException404(e: Throwable)(request: javax.servlet.http.HttpServletRequest): Option[org.dbpedia.databus.swagger.model.OperationFailure] = e match {
case _: FileNotFoundException => Some(OperationFailure(e.getMessage))
case _: NoSuchFileException => Some(OperationFailure(e.getMessage))
case _: RepositoryNotFoundException => Some(OperationFailure("File not found."))
case _: MissingObjectException => Some(OperationFailure("File not found."))
case _: UnsupportedFormatException => Some(OperationFailure(e.getMessage))
case _ => None
}

override def getGraphMapException404(e: Throwable)(request: javax.servlet.http.HttpServletRequest): Option[org.dbpedia.databus.swagger.model.OperationFailure] =
getFileMapException404(e)(request)
override def shaclValidate(dataid: Array[Byte], shacl: Array[Byte])(request: HttpServletRequest): Try[String] = {
val outLang = getLangFromAcceptHeader(request).flatMap(rdf).getOrElse(DefaultFormat)
setResponseHeaders(Map("Content-Type" -> outLang.lang.getContentType.toHeaderString))(request)
Expand All @@ -148,6 +141,7 @@ class ApiImpl(config: Config) extends DatabusApi {
case _: FileNotFoundException => Some(OperationFailure(e.getMessage))
case _: NoSuchFileException => Some(OperationFailure(e.getMessage))
case _: RepositoryNotFoundException => Some(OperationFailure("File not found."))
case _: ArrayIndexOutOfBoundsException => Some(OperationFailure("File not found"))
case _: MissingObjectException => Some(OperationFailure("File not found."))
case _: UnsupportedFormatException => Some(OperationFailure(e.getMessage))
case _ => None
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/org/dbpedia/databus/SparqlClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class HttpVirtClient(virtUri: Uri, virtUser: String, virtPass: String) extends S
case Right(s) =>
Success(s)
}
re.flatMap(_ => trans(Map.empty))
// todo fix this if work with real virtuoso is needed
re.flatMap(_ => trans(Map("s" -> 1)))
}

}
Expand Down
28 changes: 28 additions & 0 deletions src/test/scala/org/dbpedia/databus/DatabusScalatraTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,34 @@ class DatabusScalatraTest extends ScalatraFlatSpec with BeforeAndAfter {

}

"File delete" should "work" in {

val file = "group.jsonld"
val bytes = Files.readAllBytes(Paths.get(getClass.getClassLoader.getResource(file).getFile))

post(s"/databus/document/save?repo=kuckuck&path=pa/for_delete/$file", bytes) {
status should equal(200)
}

get(s"/databus/document/read?repo=kuckuck&path=pa/for_delete/$file") {
bodyBytes should equal(bytes)
status should equal(200)
}

delete(s"/databus/document/delete?repo=kuckuck&path=pa/for_delete/$file") {
status should equal(200)
}

get(s"/databus/document/read?repo=kuckuck&path=pa/for_delete/$file") {
status should equal(404)
}

delete(s"/databus/document/delete?repo=kuckuck&path=pa/for_delete/$file") {
status should equal(200)
}

}

"Shacl validation" should "report problems in input with newlines in IRIs" in {

val file = "newline_in_iri.jsonld"
Expand Down

0 comments on commit 2898c4a

Please sign in to comment.