From d090e6be83ff4ea729dec3512352b538b7e0994f Mon Sep 17 00:00:00 2001 From: forge-bot Date: Tue, 14 Jul 2026 10:32:07 +0000 Subject: [PATCH] =?UTF-8?q?Reviewer=20=EC=97=AD=ED=95=A0=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EB=B3=B4=EA=B3=A0=EC=84=9C=20smoke=20(runtime-role?= =?UTF-8?q?-matrix-live-20260714101723-v7-reviewer-001)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runtime/role/RoleMatrixRuntimeTest.java | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/test/java/com/klaroworks/runtime/role/RoleMatrixRuntimeTest.java diff --git a/src/test/java/com/klaroworks/runtime/role/RoleMatrixRuntimeTest.java b/src/test/java/com/klaroworks/runtime/role/RoleMatrixRuntimeTest.java new file mode 100644 index 0000000..f01371c --- /dev/null +++ b/src/test/java/com/klaroworks/runtime/role/RoleMatrixRuntimeTest.java @@ -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")); + } + } +}