-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBeanValidationContainerConstraintsApplicationTests.kt
38 lines (33 loc) · 1.35 KB
/
BeanValidationContainerConstraintsApplicationTests.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
package com.example.beanvalidationcontainerconstraints
import org.hamcrest.Matchers.hasSize
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.http.MediaType
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import org.springframework.test.web.servlet.result.MockMvcResultHandlers
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
@RunWith(SpringRunner::class)
@SpringBootTest
@AutoConfigureMockMvc
class BeanValidationContainerConstraintsApplicationTests {
@Autowired lateinit var mockMvc: MockMvc
@Test
fun `should fail with two validation errors`() {
mockMvc.perform(post("/samples")
.contentType(MediaType.APPLICATION_JSON)
.content("""
{
"name": "",
"someMap": { "some": "" }
}""".trimIndent()))
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isBadRequest)
.andExpect(jsonPath("errors", hasSize<String>(2)))
}
}