diff --git a/src/main/java/com/eactive/eai/common/inflow/InflowControlManager.java b/src/main/java/com/eactive/eai/common/inflow/InflowControlManager.java index f200d3e..b44d5ac 100644 --- a/src/main/java/com/eactive/eai/common/inflow/InflowControlManager.java +++ b/src/main/java/com/eactive/eai/common/inflow/InflowControlManager.java @@ -371,6 +371,10 @@ public class InflowControlManager implements Lifecycle, Bucket { return groupIds; } + public CustomGroupBucket getGroupBucket(String groupId) { + return groupBucketList.get(groupId); + } + private CustomBucket makeBucketUsingInflowVO(InflowTargetVO inflowTarget) { if (InflowControlManager.isInflowTarget(inflowTarget)) { LocalBucketBuilder builder = Bucket4j.builder(); diff --git a/src/test/java/com/eactive/eai/common/inflow/InflowControlManagerTest.java b/src/test/java/com/eactive/eai/common/inflow/InflowControlManagerTest.java index 60fae8b..01e1a79 100644 --- a/src/test/java/com/eactive/eai/common/inflow/InflowControlManagerTest.java +++ b/src/test/java/com/eactive/eai/common/inflow/InflowControlManagerTest.java @@ -1,7 +1,10 @@ package com.eactive.eai.common.inflow; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.domain.EntityScan; @@ -21,21 +24,37 @@ import com.eactive.eai.data.jpa.BaseRepositoryImpl; @EnableJpaRepositories(repositoryBaseClass = BaseRepositoryImpl.class, basePackages = { "com.eactive.eai.common.inflow" }) @EntityScan({ "com.eactive.eai.data.entity.onl.inflow" }) -@Sql({ "/com/eactive/eai/common/inflow/init_tseaifr09.sql", "/com/eactive/eai/common/inflow/init_tseaifr11.sql" }) +@Sql({ + "/com/eactive/eai/common/inflow/init_tseaifr09.sql", + "/com/eactive/eai/common/inflow/init_tseaifr11.sql", + "/com/eactive/eai/common/inflow/init_inflow_control_group.sql", + "/com/eactive/eai/common/inflow/init_inflow_control_group_mapping.sql" +}) class InflowControlManagerTest { @Autowired InflowControlManager inflowControlManager; + @BeforeEach + void setUp() throws LifecycleException { + if (!inflowControlManager.isStarted()) { + inflowControlManager.start(); + } + } + @Test - void testStart() throws LifecycleException { - // given - - // when - inflowControlManager.start(); - - // then + void testStart() { assertTrue(inflowControlManager.isStarted()); } + @Test + void testGetGroupBucket_existingGroup_returnsNotNull() { + assertNotNull(inflowControlManager.getGroupBucket("test-group-001")); + } + + @Test + void testGetGroupBucket_unknownGroup_returnsNull() { + assertNull(inflowControlManager.getGroupBucket("non-existent-group")); + } + } diff --git a/src/test/resources/com/eactive/eai/common/inflow/init_inflow_control_group.sql b/src/test/resources/com/eactive/eai/common/inflow/init_inflow_control_group.sql new file mode 100644 index 0000000..d55aeb7 --- /dev/null +++ b/src/test/resources/com/eactive/eai/common/inflow/init_inflow_control_group.sql @@ -0,0 +1,2 @@ +INSERT INTO inflow_control_group (group_id, group_name, threshold, threshold_per_second, threshold_time_unit, use_yn) VALUES + ('test-group-001', '테스트 그룹', 100, 10, 'MIN', '1'); diff --git a/src/test/resources/com/eactive/eai/common/inflow/init_inflow_control_group_mapping.sql b/src/test/resources/com/eactive/eai/common/inflow/init_inflow_control_group_mapping.sql new file mode 100644 index 0000000..c5b93a1 --- /dev/null +++ b/src/test/resources/com/eactive/eai/common/inflow/init_inflow_control_group_mapping.sql @@ -0,0 +1,2 @@ +INSERT INTO inflow_control_group_mapping (interface_id, group_id, use_yn) VALUES + ('FASSFEP00000004S2', 'test-group-001', '1');