From 68815b1fda7eed0dbafdaf237d208c6a107a265d Mon Sep 17 00:00:00 2001 From: wangziqi Date: Fri, 31 Jul 2026 13:35:25 +0800 Subject: [PATCH] test(education): activate entitlement fixtures transactionally --- ...nEntitlementPostgreSqlIntegrationTest.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/commercialization/EducationEntitlementPostgreSqlIntegrationTest.java b/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/commercialization/EducationEntitlementPostgreSqlIntegrationTest.java index 3b041e46..e57a4a0e 100644 --- a/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/commercialization/EducationEntitlementPostgreSqlIntegrationTest.java +++ b/yudao-module-education/src/test/java/cn/iocoder/yudao/module/education/service/commercialization/EducationEntitlementPostgreSqlIntegrationTest.java @@ -10,7 +10,8 @@ import cn.iocoder.yudao.module.education.test.PostgreSqlDbIntegrationTest; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; import org.springframework.context.annotation.Import; -import org.springframework.jdbc.core.JdbcTemplate; +import javax.sql.DataSource; +import java.sql.Connection; import java.time.LocalDateTime; import static cn.iocoder.yudao.module.education.enums.ErrorCodeConstants.ENTITLEMENT_IDEMPOTENCY_CONFLICT; import static org.junit.jupiter.api.Assertions.*; @@ -24,7 +25,7 @@ class EducationEntitlementPostgreSqlIntegrationTest extends PostgreSqlDbIntegrat @Resource EducationEntitlementMapper entitlementMapper; @Resource EducationEntitlementEventMapper eventMapper; @Resource EducationResourceProductBindingMapper bindingMapper; - @Resource JdbcTemplate jdbcTemplate; + @Resource DataSource dataSource; @BeforeEach void setUp() { TenantContextHolder.setTenantId(10L); @@ -33,18 +34,22 @@ class EducationEntitlementPostgreSqlIntegrationTest extends PostgreSqlDbIntegrat ContentNodeDO node = new ContentNodeDO(); node.setId(101L); node.setTenantId(10L); node.setScope("TENANT_OWNED"); node.setEntryId(100L); node.setName("Paid node"); node.setNodeType("category"); node.setDepth(0); node.setIsLeaf(true); node.setIsSelectable(true); node.setIsHidden(true); node.setIsActive(false); node.setPublicationStatus("DRAFT"); node.setAuthoringVersion(0); nodeMapper.insert(node); - jdbcTemplate.execute(""" - DO $activate$ - BEGIN - UPDATE education_content_node - SET publication_status='ACTIVE', is_active=true, is_hidden=false, authoring_version=1 - WHERE id=101 AND tenant_id=10; - INSERT INTO education_content_node_lifecycle_audit - (tenant_id,node_id,authoring_version,actor_id,from_status,to_status) - VALUES (10,101,1,7,'DRAFT','ACTIVE'); - END - $activate$; - """); + try (Connection connection = dataSource.getConnection(); var statement = connection.createStatement()) { + statement.execute(""" + DO $activate$ + BEGIN + UPDATE education_content_node + SET publication_status='ACTIVE', is_active=true, is_hidden=false, authoring_version=1 + WHERE id=101 AND tenant_id=10; + INSERT INTO education_content_node_lifecycle_audit + (tenant_id,node_id,authoring_version,actor_id,from_status,to_status) + VALUES (10,101,1,7,'DRAFT','ACTIVE'); + END + $activate$; + """); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } QuestionCollectionDO collection = new QuestionCollectionDO(); collection.setId(102L); collection.setTenantId(10L); collection.setScope("TENANT_OWNED"); collection.setEntryId(100L); collection.setNodeId(101L); collection.setName("Paid collection"); collection.setCollectionType("MANUAL"); collection.setQuestionCount(0); collection.setAccessMode("PAID"); collection.setAccessRules("{\"label\":\"descriptive only\"}");