diff --git a/.forge/runtime-role-matrix-live-20260714112301-v11-developer-001-attempt-1-run-9c63dd5c6aca.md b/.forge/runtime-role-matrix-live-20260714112301-v11-developer-001-attempt-1-run-9c63dd5c6aca.md new file mode 100644 index 0000000..4d87ca5 --- /dev/null +++ b/.forge/runtime-role-matrix-live-20260714112301-v11-developer-001-attempt-1-run-9c63dd5c6aca.md @@ -0,0 +1,3 @@ +# runtime-role-matrix-live-20260714112301-v11-developer-001-attempt-1-run-9c63dd5c6aca + +Forge 이슈 작업 브랜치 `forge/runtime-role-matrix-live-20260714112301-v11-developer-001-attempt-1-run-9c63dd5c6aca`. diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f5c3824 --- /dev/null +++ b/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 3.2.5 + + + + com.example + runtime-role-matrix-live + 1.0.0-SNAPSHOT + jar + + + 17 + + + + + org.springframework.boot + spring-boot-starter + + + 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/RoleService.java b/src/main/java/com/example/demo/RoleService.java new file mode 100644 index 0000000..c87d474 --- /dev/null +++ b/src/main/java/com/example/demo/RoleService.java @@ -0,0 +1,24 @@ +package com.example.demo; + +import org.springframework.stereotype.Service; + +@Service +public class RoleService { + + public String getRoleName(String roleId) { + if (roleId == null || roleId.isBlank()) { + return "UNKNOWN"; + } + return switch (roleId.toUpperCase()) { + case "ADMIN" -> "Administrator"; + case "DEVELOPER" -> "Developer"; + case "VIEWER" -> "Viewer"; + default -> "Role: " + roleId; + }; + } + + public boolean isValidRole(String roleId) { + return roleId != null && !roleId.isBlank() && + roleId.matches("^[A-Z_]+$"); + } +} diff --git a/src/test/java/com/example/demo/RoleServiceTest.java b/src/test/java/com/example/demo/RoleServiceTest.java new file mode 100644 index 0000000..4507ad4 --- /dev/null +++ b/src/test/java/com/example/demo/RoleServiceTest.java @@ -0,0 +1,49 @@ +package com.example.demo; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +class RoleServiceTest { + + @Autowired + private RoleService roleService; + + @Test + void getRoleName_returnsAdministratorForAdmin() { + assertEquals("Administrator", roleService.getRoleName("ADMIN")); + } + + @Test + void getRoleName_returnsDeveloperForDeveloper() { + assertEquals("Developer", roleService.getRoleName("DEVELOPER")); + } + + @Test + void getRoleName_returnsUnknownForNull() { + assertEquals("UNKNOWN", roleService.getRoleName(null)); + } + + @Test + void getRoleName_returnsUnknownForBlank() { + assertEquals("UNKNOWN", roleService.getRoleName(" ")); + } + + @Test + void isValidRole_returnsTrueForValidRoles() { + assertTrue(roleService.isValidRole("ADMIN")); + assertTrue(roleService.isValidRole("DEVELOPER")); + assertTrue(roleService.isValidRole("ROLE_VIEWER")); + } + + @Test + void isValidRole_returnsFalseForInvalidRoles() { + assertFalse(roleService.isValidRole(null)); + assertFalse(roleService.isValidRole("")); + assertFalse(roleService.isValidRole("admin")); + assertFalse(roleService.isValidRole("ADMIN123")); + } +}