Skip to content

Commit 2898c4a

Browse files
#38, tests for delete
1 parent defc710 commit 2898c4a

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/main/scala/org/dbpedia/databus/ApiImpl.scala

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,8 @@ class ApiImpl(config: Config) extends DatabusApi {
117117
override def getGraph(repo: String, path: String, prefix: Option[String])(request: javax.servlet.http.HttpServletRequest): scala.util.Try[String] =
118118
readGraph(repo, path, prefix)(request)
119119

120-
override def getGraphMapException404(e: Throwable)(request: javax.servlet.http.HttpServletRequest): Option[org.dbpedia.databus.swagger.model.OperationFailure] = e match {
121-
case _: FileNotFoundException => Some(OperationFailure(e.getMessage))
122-
case _: NoSuchFileException => Some(OperationFailure(e.getMessage))
123-
case _: RepositoryNotFoundException => Some(OperationFailure("File not found."))
124-
case _: MissingObjectException => Some(OperationFailure("File not found."))
125-
case _: UnsupportedFormatException => Some(OperationFailure(e.getMessage))
126-
case _ => None
127-
}
128-
120+
override def getGraphMapException404(e: Throwable)(request: javax.servlet.http.HttpServletRequest): Option[org.dbpedia.databus.swagger.model.OperationFailure] =
121+
getFileMapException404(e)(request)
129122
override def shaclValidate(dataid: Array[Byte], shacl: Array[Byte])(request: HttpServletRequest): Try[String] = {
130123
val outLang = getLangFromAcceptHeader(request).flatMap(rdf).getOrElse(DefaultFormat)
131124
setResponseHeaders(Map("Content-Type" -> outLang.lang.getContentType.toHeaderString))(request)
@@ -148,6 +141,7 @@ class ApiImpl(config: Config) extends DatabusApi {
148141
case _: FileNotFoundException => Some(OperationFailure(e.getMessage))
149142
case _: NoSuchFileException => Some(OperationFailure(e.getMessage))
150143
case _: RepositoryNotFoundException => Some(OperationFailure("File not found."))
144+
case _: ArrayIndexOutOfBoundsException => Some(OperationFailure("File not found"))
151145
case _: MissingObjectException => Some(OperationFailure("File not found."))
152146
case _: UnsupportedFormatException => Some(OperationFailure(e.getMessage))
153147
case _ => None

src/main/scala/org/dbpedia/databus/SparqlClient.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class HttpVirtClient(virtUri: Uri, virtUser: String, virtPass: String) extends S
8282
case Right(s) =>
8383
Success(s)
8484
}
85-
re.flatMap(_ => trans(Map.empty))
85+
// todo fix this if work with real virtuoso is needed
86+
re.flatMap(_ => trans(Map("s" -> 1)))
8687
}
8788

8889
}

src/test/scala/org/dbpedia/databus/DatabusScalatraTest.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,34 @@ class DatabusScalatraTest extends ScalatraFlatSpec with BeforeAndAfter {
186186

187187
}
188188

189+
"File delete" should "work" in {
190+
191+
val file = "group.jsonld"
192+
val bytes = Files.readAllBytes(Paths.get(getClass.getClassLoader.getResource(file).getFile))
193+
194+
post(s"/databus/document/save?repo=kuckuck&path=pa/for_delete/$file", bytes) {
195+
status should equal(200)
196+
}
197+
198+
get(s"/databus/document/read?repo=kuckuck&path=pa/for_delete/$file") {
199+
bodyBytes should equal(bytes)
200+
status should equal(200)
201+
}
202+
203+
delete(s"/databus/document/delete?repo=kuckuck&path=pa/for_delete/$file") {
204+
status should equal(200)
205+
}
206+
207+
get(s"/databus/document/read?repo=kuckuck&path=pa/for_delete/$file") {
208+
status should equal(404)
209+
}
210+
211+
delete(s"/databus/document/delete?repo=kuckuck&path=pa/for_delete/$file") {
212+
status should equal(200)
213+
}
214+
215+
}
216+
189217
"Shacl validation" should "report problems in input with newlines in IRIs" in {
190218

191219
val file = "newline_in_iri.jsonld"

0 commit comments

Comments
 (0)