Developer 역할 Spring 골격 smoke #4
5 changed files with 131 additions and 0 deletions
|
|
@ -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`.
|
||||
43
pom.xml
Normal file
43
pom.xml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.5</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>runtime-role-matrix-live</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
12
src/main/java/com/example/demo/DemoApplication.java
Normal file
12
src/main/java/com/example/demo/DemoApplication.java
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
24
src/main/java/com/example/demo/RoleService.java
Normal file
24
src/main/java/com/example/demo/RoleService.java
Normal file
|
|
@ -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_]+$");
|
||||
}
|
||||
}
|
||||
49
src/test/java/com/example/demo/RoleServiceTest.java
Normal file
49
src/test/java/com/example/demo/RoleServiceTest.java
Normal file
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue