1
+ package org.example.bankofhamburg.customer
2
+
3
+ import org.assertj.core.api.Assertions.assertThat
4
+
5
+ import org.junit.Test
6
+ import org.junit.runner.RunWith
7
+
8
+ import org.springframework.beans.factory.annotation.Autowired
9
+ import org.springframework.boot.test.context.SpringBootTest
10
+ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
11
+ import org.springframework.test.context.junit4.SpringRunner
12
+ import org.springframework.boot.test.web.client.TestRestTemplate
13
+ import org.springframework.util.LinkedMultiValueMap
14
+ import org.springframework.http.HttpEntity
15
+ import org.springframework.http.HttpHeaders
16
+ import org.springframework.http.HttpStatus
17
+ import org.springframework.http.MediaType
18
+
19
+
20
+ @RunWith(SpringRunner ::class )
21
+ @SpringBootTest(webEnvironment = WebEnvironment .RANDOM_PORT )
22
+ class CustomerControllerTest {
23
+
24
+ @Autowired
25
+ lateinit var restTemplate: TestRestTemplate
26
+
27
+ @Test
28
+ fun customerTest () {
29
+ val requestEntity = createEntity(" Jana" , " Müller" )
30
+ val responseEntity = this .restTemplate.postForEntity(" /customer" , requestEntity, String ::class .java)
31
+ assertThat(responseEntity.statusCodeValue).isEqualTo(HttpStatus .CREATED .value())
32
+ }
33
+
34
+ private fun createEntity (firstName : String , lastName : String ): HttpEntity <LinkedMultiValueMap <String , String >> {
35
+ val body = LinkedMultiValueMap <String , String >()
36
+ body.add(" firstName" , firstName)
37
+ body.add(" lastName" , lastName)
38
+
39
+ val headers = HttpHeaders ()
40
+ headers.contentType = MediaType .MULTIPART_FORM_DATA
41
+ return HttpEntity (body, headers)
42
+ }
43
+ }
0 commit comments