-
Notifications
You must be signed in to change notification settings - Fork 300
Expand file tree
/
Copy pathHttpSpec.scala
More file actions
50 lines (41 loc) · 2.21 KB
/
HttpSpec.scala
File metadata and controls
50 lines (41 loc) · 2.21 KB
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
package tv.codely
import akka.http.scaladsl.model._
import akka.http.scaladsl.testkit.ScalatestRouteTest
import akka.util.ByteString
import com.typesafe.config.ConfigFactory
import org.scalatest.{Matchers, WordSpec}
import org.scalatest.concurrent.ScalaFutures
import tv.codely.mooc.api.{EntryPointDependencyContainer, Routes}
import tv.codely.mooc.user.infrastructure.dependency_injection.UserModuleDependencyContainer
import tv.codely.mooc.video.infrastructure.dependency_injection.VideoModuleDependencyContainer
import tv.codely.shared.infrastructure.bus.rabbitmq.RabbitMqConfig
import tv.codely.shared.infrastructure.dependency_injection.SharedModuleDependencyContainer
import tv.codely.shared.infrastructure.doobie.{DoobieDbConnection, JdbcConfig}
abstract class HttpSpec extends WordSpec with Matchers with ScalaFutures with ScalatestRouteTest {
private val actorSystemName = "cqrs-ddd-scala-example-acceptance-test"
private val appConfig = ConfigFactory.load("application")
private val dbConfig = JdbcConfig(appConfig.getConfig("acceptance-tests-database"))
private val publisherConfig = RabbitMqConfig(appConfig.getConfig("message-publisher"))
private val sharedDependencies = new SharedModuleDependencyContainer(actorSystemName, dbConfig, publisherConfig)
protected val userDependencies = new UserModuleDependencyContainer(
sharedDependencies.doobieDbConnection,
sharedDependencies.messagePublisher
)
protected val videoDependencies = new VideoModuleDependencyContainer(
sharedDependencies.doobieDbConnection,
sharedDependencies.messagePublisher,
sharedDependencies.logger
)(sharedDependencies.executionContext)
private val routes = new Routes(new EntryPointDependencyContainer(userDependencies, videoDependencies))
protected val doobieDbConnection: DoobieDbConnection = sharedDependencies.doobieDbConnection
protected def posting[T](path: String, request: String)(body: ⇒ T): T =
HttpRequest(
method = HttpMethods.POST,
uri = path,
entity = HttpEntity(
MediaTypes.`application/json`,
ByteString(request)
)
) ~> routes.all ~> check(body)
protected def getting[T](path: String)(body: ⇒ T): T = Get(path) ~> routes.all ~> check(body)
}