-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBaseIntegrationController.kt
47 lines (39 loc) · 1.51 KB
/
BaseIntegrationController.kt
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
package com.example.demo.kotest.common
import com.example.demo.kotest.common.security.SecurityListenerFactory
import com.fasterxml.jackson.databind.ObjectMapper
import io.kotest.core.spec.style.BehaviorSpec
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import org.springframework.web.context.WebApplicationContext
abstract class BaseIntegrationController : BehaviorSpec() {
@Autowired
protected lateinit var webApplicationContext: WebApplicationContext
@Autowired
protected lateinit var mockMvc: MockMvc
@Autowired
protected lateinit var objectMapper: ObjectMapper
/**
* ResponseAdvice Status
*/
protected val commonStatus: Int = HttpStatus.OK.value()
/**
* ResponseAdvice Message
*/
protected val commonMessage: String = HttpStatus.OK.name
fun initialize() {
listeners(SecurityListenerFactory())
beforeSpec {
mockMvc =
MockMvcBuilders
.webAppContextSetup(webApplicationContext)
.apply<DefaultMockMvcBuilder>(SecurityMockMvcConfigurers.springSecurity())
.alwaysDo<DefaultMockMvcBuilder>(MockMvcResultHandlers.print())
.build()
}
}
}