From f096425d4ab1cdf11a170937a849b9a0bc756e94 Mon Sep 17 00:00:00 2001 From: Sergio Freire Date: Sat, 8 Nov 2025 19:22:19 +0000 Subject: [PATCH 1/2] make IndexController render a proper HTML page, LH compliant --- .../springboot/boundary/IndexController.java | 6 +- src/main/resources/templates/greeting.html | 62 ++++++++++++++++--- src/main/resources/templates/index.html | 57 +++++++++++++++++ .../springboot/IndexControllerIT.java | 6 +- .../springboot/IndexControllerMockedIT.java | 4 +- 5 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 src/main/resources/templates/index.html diff --git a/src/main/java/com/sergiofreire/xray/tutorials/springboot/boundary/IndexController.java b/src/main/java/com/sergiofreire/xray/tutorials/springboot/boundary/IndexController.java index 34cc009..e0f6fc5 100644 --- a/src/main/java/com/sergiofreire/xray/tutorials/springboot/boundary/IndexController.java +++ b/src/main/java/com/sergiofreire/xray/tutorials/springboot/boundary/IndexController.java @@ -1,14 +1,14 @@ package com.sergiofreire.xray.tutorials.springboot.boundary; +import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -@RestController +@Controller public class IndexController { @GetMapping("/") public String index() { - return "Welcome to this amazing website!"; + return "index"; } } \ No newline at end of file diff --git a/src/main/resources/templates/greeting.html b/src/main/resources/templates/greeting.html index 9e5138f..d1dce5b 100644 --- a/src/main/resources/templates/greeting.html +++ b/src/main/resources/templates/greeting.html @@ -1,10 +1,58 @@ - - - - Getting Started: Serving Web Content - + + + + + + + + + + Hello Page + + + + + + + + + + + -

+

+

Hello!

+

Hello, Guest!

+
+ + + - \ No newline at end of file + diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..a93cac4 --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,57 @@ + + + + + + + + + + Hello Page + + + + + + + + + + + + + +
+

Welcome to this amazing website!

+
+ + + + + diff --git a/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerIT.java b/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerIT.java index 5f0025a..5a71ba0 100644 --- a/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerIT.java +++ b/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerIT.java @@ -4,6 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import static org.assertj.core.api.Assertions.assertThat; @@ -18,6 +20,8 @@ class IndexControllerIT { void getWelcomeMessage() throws Exception { ResponseEntity response = template.getForEntity("/", String.class); - assertThat(response.getBody()).isEqualTo("Welcome to this amazing website!"); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_HTML); + assertThat(response.getBody()).contains("Welcome to this amazing website!"); } } \ No newline at end of file diff --git a/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerMockedIT.java b/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerMockedIT.java index 300a780..9415300 100644 --- a/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerMockedIT.java +++ b/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerMockedIT.java @@ -1,6 +1,6 @@ package com.sergiofreire.xray.tutorials.springboot; -import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.containsString; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.junit.jupiter.api.Test; @@ -30,6 +30,6 @@ class IndexControllerMockedIT { void getWelcomeMessage() throws Exception { mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.TEXT_PLAIN)) .andExpect(status().isOk()) - .andExpect(content().string(equalTo("Welcome to this amazing website!"))); + .andExpect(content().string(containsString("Welcome to this amazing website!"))); } } \ No newline at end of file From 833d1a685af27a4cd0568505ef43674ddb30ddba Mon Sep 17 00:00:00 2001 From: Sergio Freire Date: Sat, 8 Nov 2025 19:25:56 +0000 Subject: [PATCH 2/2] bump deps --- pom.xml | 14 +++++++------- .../tutorials/springboot/IndexControllerIT.java | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index e239db9..0f06641 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.2 + 3.5.7 com.sergiofreire.xray.tutorials @@ -19,12 +19,12 @@ ${java.version} ${java.version} - 5.10.2 - 0.7.3 - 0.8.0 - 3.2.5 - 3.2.5 - 0.8.13 + 5.14.1 + 0.9.0 + 0.9.0 + 3.5.4 + 3.5.4 + 0.8.14 ${project.build.directory}/jacoco-output/jacoco-unit-tests.exec ${project.build.directory}/jacoco-output/jacoco-it-tests.exec ${project.build.directory}/jacoco-output/merged.exec diff --git a/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerIT.java b/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerIT.java index 5a71ba0..378814f 100644 --- a/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerIT.java +++ b/src/test/java/com/sergiofreire/xray/tutorials/springboot/IndexControllerIT.java @@ -5,7 +5,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import static org.assertj.core.api.Assertions.assertThat; @@ -21,7 +20,8 @@ void getWelcomeMessage() throws Exception { ResponseEntity response = template.getForEntity("/", String.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(response.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_HTML); + assertThat(response.getHeaders().getContentType()).toString().equals("text/html;charset=UTF-8"); + // che assertThat(response.getBody()).contains("Welcome to this amazing website!"); } } \ No newline at end of file