@@ -8,9 +8,11 @@ import org.springframework.boot.test.web.client.TestRestTemplate
88import org.springframework.http.HttpMethod
99import org.springframework.http.HttpStatus
1010import org.springframework.http.ResponseEntity
11+
1112abstract class IntegrationTestBase {
1213 @Autowired
1314 lateinit var testRestTemplate: TestRestTemplate
15+
1416 @Test
1517 fun testIndexComponent () {
1618 val expectedHtml =
@@ -37,6 +39,9 @@ abstract class IntegrationTestBase {
3739 <div>
3840 <h2>This is the SimpleViewComponent</h2>
3941 <div>Hello World</div>
42+ <div>
43+ <input id="helloWorld" name="helloWorld" value="Hello World">
44+ </div>
4045 </div>
4146 """ .trimIndent()
4247 assertEndpointReturns(" /simple" , expectedHtml)
@@ -45,34 +50,35 @@ abstract class IntegrationTestBase {
4550 @Test
4651 fun testLayoutComponent () {
4752 // language=html
48- val expectedHtml =
49- """
53+ val expectedHtml = """
5054 <html>
5155 <nav>This is a Navbar</nav>
5256 <body>
5357 <div><h2>This is the SimpleViewComponent</h2>
54- <div>Hello World</div></div></body>
55- <footer>This is a footer</footer></html>
58+ <div>Hello World</div>
59+ <div>
60+ <input id="helloWorld" name="helloWorld" value="Hello World">
61+ </div>
62+ </div>
63+ </body>
64+ <footer>This is a footer</footer>
65+ </html>
5666 """ .trimIndent()
5767 assertEndpointReturns(" /layout" , expectedHtml)
5868 }
5969
6070 fun assertEndpointReturns (url : String , expectedHtml : String ) {
61- val response: ResponseEntity <String > = this .testRestTemplate
62- .exchange(url, HttpMethod .GET , null , String ::class .java)
63- assertThat(response.statusCode)
64- .isEqualTo(HttpStatus .OK )
71+ val response: ResponseEntity <String > =
72+ this .testRestTemplate.exchange(url, HttpMethod .GET , null , String ::class .java)
73+ assertThat(response.statusCode).isEqualTo(HttpStatus .OK )
6574 Assertions .assertEquals(
6675 expectedHtml.rmWhitespaceBetweenHtmlTags(), response.body?.rmWhitespaceBetweenHtmlTags()
6776 )
6877 }
6978
7079 fun String.rmWhitespaceBetweenHtmlTags (): String {
7180 // Replace whitespace between > and word
72- return this .replace(" (?<=>)(\\ s*)(?=\\ w)" .toRegex(), " " )
73- .replace(" (?<=\\ w)(\\ s*)(?=<)" .toRegex(), " " )
74- .replace(" (?<=>)(\\ s*)(?=<)" .toRegex(), " " )
75- .replace(" \r\n " ," \n " )
76- .trim()
81+ return this .replace(" (?<=>)(\\ s*)(?=\\ w)" .toRegex(), " " ).replace(" (?<=\\ w)(\\ s*)(?=<)" .toRegex(), " " )
82+ .replace(" (?<=>)(\\ s*)(?=<)" .toRegex(), " " ).replace(" \r\n " , " \n " ).trim()
7783 }
7884}
0 commit comments