/
VersionRouteITSpec.scala
91 lines (74 loc) · 2.49 KB
/
VersionRouteITSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Copyright © 2021 - 2022 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors.
* SPDX-License-Identifier: Apache-2.0
*/
package org.knora.webapi.it
import java.util.NoSuchElementException
import akka.http.scaladsl.model._
import com.typesafe.config.{Config, ConfigFactory}
import org.knora.webapi.ITKnoraLiveSpec
import spray.json._
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.languageFeature.postfixOps
object VersionRouteITSpec {
val config: Config = ConfigFactory.parseString(
"""
|akka.loglevel = "DEBUG"
|akka.stdout-loglevel = "DEBUG"
""".stripMargin)
}
/**
* End-to-End (E2E) test specification for testing route rejections.
*/
class VersionRouteITSpec extends ITKnoraLiveSpec(VersionRouteITSpec.config) {
private def getJsonResponse: JsObject = {
val request = Get(baseApiUrl + s"/version")
val response: HttpResponse = singleAwaitingRequest(request)
val responseBody: String =
Await.result(response.entity.toStrict(10.seconds).map(_.data.decodeString("UTF-8")), 10.seconds)
val responseBodyJson = responseBody.parseJson.asJsObject
responseBodyJson
}
private def checkNonEmpty(field: String): Boolean = {
val responseBodyJson = getJsonResponse
var result = false
try {
val value = responseBodyJson.fields(field).toString().replaceAll("\"", "")
result = !value.equals("")
} catch {
case nse: NoSuchElementException => result = false
}
result
}
"The Version Route" should {
"return 'OK'" in {
val request = Get(baseApiUrl + s"/version")
val response: HttpResponse = singleAwaitingRequest(request)
response.status should be(StatusCodes.OK)
}
"return 'version' as name" in {
val responseBodyJson = getJsonResponse
val value = responseBodyJson.fields("name").toString().replaceAll("\"", "")
assert(value.equals("version"))
}
"contain nonempty value for key 'webapi'" in {
assert(checkNonEmpty("webapi"))
}
"contain nonempty value for key 'scala'" in {
assert(checkNonEmpty("scala"))
}
"contain nonempty value for key 'akkaHttp'" in {
assert(checkNonEmpty("akkaHttp"))
}
"contain nonempty value for key 'sipi'" in {
assert(checkNonEmpty("sipi"))
}
"contain nonempty value for key 'fuseki'" in {
assert(checkNonEmpty("fuseki"))
}
"fail for nonexisting key 'fail'" in {
assert(!checkNonEmpty("fail"))
}
}
}