/
SalsahSpec.scala
73 lines (62 loc) · 2.73 KB
/
SalsahSpec.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
/*
* Copyright © 2015-2019 the contributors (see Contributors.md).
*
* This file is part of Knora.
*
* Knora is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Knora is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with Knora. If not, see <http://www.gnu.org/licenses/>.
*/
package org.knora.salsah.browser
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.client.RequestBuilding
import akka.http.scaladsl.model._
import akka.stream.Materializer
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import org.knora.salsah.SettingsImpl
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
import scala.concurrent.duration._
import scala.concurrent.{Await, ExecutionContextExecutor}
/**
* An abstract base class for Selenium tests of the SALSAH user interface.
*/
abstract class SalsahSpec extends AnyWordSpecLike with Matchers with RequestBuilding {
implicit private val system = ActorSystem()
protected val settings = new SettingsImpl(ConfigFactory.load())
implicit private val timeout = Timeout(180.seconds)
implicit private val dispatcher = system.dispatcher
implicit protected val ec: ExecutionContextExecutor = dispatcher
implicit protected val materializer = Materializer.matFromSystem(system)
/**
* Loads test data and populates the ontology cache.
*
* @param rdfDataObjectsJsonList a JSON array specifying data files to be loaded into the triplestore.
*/
protected def loadTestData(rdfDataObjectsJsonList: String): Unit = {
val request = Post(settings.webapiUrl + "/admin/store/ResetTriplestoreContent", HttpEntity(ContentTypes.`application/json`, rdfDataObjectsJsonList))
singleAwaitingRequest(request, 300.seconds)
}
/**
* Makes a single HTTP request, waits for the result and chekcs that the response is HTTP 200 (OK)
* @param request the request to send.
* @param duration the max wait time.
*/
def singleAwaitingRequest(request: HttpRequest, duration: Duration = 3.seconds): HttpResponse = {
val responseFuture = Http().singleRequest(request)
val response = Await.result(responseFuture, duration)
assert(response.status == StatusCodes.OK)
response
}
}