diff --git a/.forge/role-developer-001-attempt-1-run-13e76c4f33b3.md b/.forge/role-developer-001-attempt-1-run-13e76c4f33b3.md new file mode 100644 index 0000000..a74b22b --- /dev/null +++ b/.forge/role-developer-001-attempt-1-run-13e76c4f33b3.md @@ -0,0 +1,3 @@ +# role-developer-001-attempt-1-run-13e76c4f33b3 + +Forge 이슈 작업 브랜치 `forge/role-developer-001-attempt-1-run-13e76c4f33b3`. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f0d9494 --- /dev/null +++ b/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.2.5 + + + + com.example + demo + 0.0.1-SNAPSHOT + demo + Minimal Spring Boot Application + + + 17 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + \ No newline at end of file diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java new file mode 100644 index 0000000..2a9bdbe --- /dev/null +++ b/src/main/java/com/example/demo/DemoApplication.java @@ -0,0 +1,12 @@ +package com.example.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } +} diff --git a/src/main/java/com/example/demo/controller/HelloController.java b/src/main/java/com/example/demo/controller/HelloController.java new file mode 100644 index 0000000..b012da0 --- /dev/null +++ b/src/main/java/com/example/demo/controller/HelloController.java @@ -0,0 +1,18 @@ +package com.example.demo.controller; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + + @GetMapping("/hello") + public ResponseEntity hello(@RequestParam(required = false) String name) { + String message = (name != null && !name.isBlank()) + ? "Hello, " + name + "!" + : "Hello, World!"; + return ResponseEntity.ok(message); + } +} diff --git a/src/test/java/com/example/demo/DemoApplicationTests.java b/src/test/java/com/example/demo/DemoApplicationTests.java new file mode 100644 index 0000000..0a84dc8 --- /dev/null +++ b/src/test/java/com/example/demo/DemoApplicationTests.java @@ -0,0 +1,15 @@ +package com.example.demo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@TestPropertySource(properties = {"spring.main.allow-bean-definition-overriding=true"}) +class DemoApplicationTests { + + @Test + void contextLoads() { + // Verify Spring context loads successfully + } +} diff --git a/src/test/java/com/example/demo/controller/HelloControllerTest.java b/src/test/java/com/example/demo/controller/HelloControllerTest.java new file mode 100644 index 0000000..3861132 --- /dev/null +++ b/src/test/java/com/example/demo/controller/HelloControllerTest.java @@ -0,0 +1,38 @@ +package com.example.demo.controller; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(HelloController.class) +class HelloControllerTest { + + @Autowired + private MockMvc mockMvc; + + @Test + void hello_withoutName_returnsDefaultMessage() throws Exception { + mockMvc.perform(get("/hello")) + .andExpect(status().isOk()) + .andExpect(content().string("Hello, World!")); + } + + @Test + void hello_withName_returnsPersonalizedMessage() throws Exception { + mockMvc.perform(get("/hello").param("name", "Spring")) + .andExpect(status().isOk()) + .andExpect(content().string("Hello, Spring!")); + } + + @Test + void hello_withBlankName_returnsDefaultMessage() throws Exception { + mockMvc.perform(get("/hello").param("name", " ")) + .andExpect(status().isOk()) + .andExpect(content().string("Hello, World!")); + } +}