Reviewer 역할 검증 보고서 smoke (runtime-role-matrix-live-20260714101723-v7-reviewer-001)
This commit is contained in:
parent
55351f4c1d
commit
d090e6be83
1 changed files with 139 additions and 0 deletions
|
|
@ -0,0 +1,139 @@
|
||||||
|
package com.klaroworks.runtime.role;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for RoleMatrixRuntime.
|
||||||
|
* Tests role evaluation, permission checking, and context management.
|
||||||
|
*/
|
||||||
|
@DisplayName("RoleMatrixRuntime Tests")
|
||||||
|
public class RoleMatrixRuntimeTest {
|
||||||
|
|
||||||
|
private RoleMatrixRuntime runtime;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
runtime = new RoleMatrixRuntime();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("EvaluateRoleTests")
|
||||||
|
class EvaluateRoleTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should evaluate ADMIN role with wildcard permission")
|
||||||
|
void shouldEvaluateAdminRoleWithWildcardPermission() {
|
||||||
|
assertTrue(runtime.evaluateRole("ADMIN", "anyPermission"));
|
||||||
|
assertTrue(runtime.evaluateRole("ADMIN", "read"));
|
||||||
|
assertTrue(runtime.evaluateRole("ADMIN", "delete"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should evaluate USER role with limited permissions")
|
||||||
|
void shouldEvaluateUserRoleWithLimitedPermissions() {
|
||||||
|
assertTrue(runtime.evaluateRole("USER", "read"));
|
||||||
|
assertTrue(runtime.evaluateRole("USER", "write"));
|
||||||
|
assertFalse(runtime.evaluateRole("USER", "delete"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should return false for unknown role")
|
||||||
|
void shouldReturnFalseForUnknownRole() {
|
||||||
|
assertFalse(runtime.evaluateRole("UNKNOWN", "read"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should create nested role correctly")
|
||||||
|
void shouldCreateNestedRoleCorrectly() {
|
||||||
|
Nested.InnerRole role = RoleMatrixRuntime.createNestedRole("TEST", 25);
|
||||||
|
assertEquals("TEST", role.getRoleName());
|
||||||
|
assertEquals(25, role.getPriority());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("HasPermissionTests")
|
||||||
|
class HasPermissionTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should check permission with context set")
|
||||||
|
void shouldCheckPermissionWithContextSet() {
|
||||||
|
RoleContext context = RoleContext.SimpleRoleContext.of("user1", "ADMIN");
|
||||||
|
runtime.setContext(context);
|
||||||
|
|
||||||
|
assertTrue(runtime.hasPermission("read"));
|
||||||
|
assertTrue(runtime.hasPermission("write"));
|
||||||
|
assertTrue(runtime.hasPermission("delete"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should return false when no context set")
|
||||||
|
void shouldReturnFalseWhenNoContextSet() {
|
||||||
|
assertFalse(runtime.hasPermission("read"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should check permission based on role")
|
||||||
|
void shouldCheckPermissionBasedOnRole() {
|
||||||
|
RoleContext context = RoleContext.SimpleRoleContext.of("user1", "USER");
|
||||||
|
runtime.setContext(context);
|
||||||
|
|
||||||
|
assertTrue(runtime.hasPermission("read"));
|
||||||
|
assertTrue(runtime.hasPermission("write"));
|
||||||
|
assertFalse(runtime.hasPermission("delete"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("ContextManagementTests")
|
||||||
|
class ContextManagementTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should set and get context")
|
||||||
|
void shouldSetAndGetContext() {
|
||||||
|
RoleContext context = RoleContext.SimpleRoleContext.of("user1", "MANAGER");
|
||||||
|
runtime.setContext(context);
|
||||||
|
|
||||||
|
assertEquals(context, runtime.getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should clear context")
|
||||||
|
void shouldClearContext() {
|
||||||
|
RoleContext context = RoleContext.SimpleRoleContext.of("user1", "ADMIN");
|
||||||
|
runtime.setContext(context);
|
||||||
|
runtime.clearContext();
|
||||||
|
|
||||||
|
assertNull(runtime.getContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should check if in role")
|
||||||
|
void shouldCheckIfInRole() {
|
||||||
|
RoleContext context = RoleContext.SimpleRoleContext.of("user1", "ADMIN");
|
||||||
|
runtime.setContext(context);
|
||||||
|
|
||||||
|
assertTrue(runtime.isInRole("ADMIN"));
|
||||||
|
assertFalse(runtime.isInRole("USER"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("should check role hierarchy")
|
||||||
|
void shouldCheckRoleHierarchy() {
|
||||||
|
RoleContext context = RoleContext.SimpleRoleContext.of("user1", "ADMIN");
|
||||||
|
runtime.setContext(context);
|
||||||
|
|
||||||
|
assertTrue(runtime.isInRoleHierarchy("ADMIN"));
|
||||||
|
assertTrue(runtime.isInRoleHierarchy("MANAGER"));
|
||||||
|
assertTrue(runtime.isInRoleHierarchy("USER"));
|
||||||
|
assertTrue(runtime.isInRoleHierarchy("GUEST"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue