diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/listener/missionListenerFix/LogicDeleteInsertListener.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/listener/missionListenerFix/LogicDeleteInsertListener.java index b20484b0..8ea4f327 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/listener/missionListenerFix/LogicDeleteInsertListener.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/main/java/com/mybatisflex/test/listener/missionListenerFix/LogicDeleteInsertListener.java @@ -7,6 +7,6 @@ public class LogicDeleteInsertListener implements InsertListener { @Override public void onInsert(Object entity) { BaseLogicDelete logicDeleteEntity = (BaseLogicDelete) entity; - logicDeleteEntity.setDelete(true); + logicDeleteEntity.setDelete(false); } } diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/ListenerTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/ListenerTest.java index ac47f913..f2d3338a 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/ListenerTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/common/ListenerTest.java @@ -1,10 +1,12 @@ package com.mybatisflex.test.common; import com.mybatisflex.annotation.InsertListener; +import com.mybatisflex.core.BaseMapper; import com.mybatisflex.core.FlexGlobalConfig; import com.mybatisflex.core.exception.FlexAssert; import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.exception.locale.LocalizedFormats; +import com.mybatisflex.core.mybatis.Mappers; import com.mybatisflex.core.table.TableInfo; import com.mybatisflex.core.table.TableInfoFactory; import com.mybatisflex.core.util.CollectionUtil; @@ -44,9 +46,9 @@ class ListenerTest { //执行测试 ===> Listener列表比对 - Map, List> tempInsertListenerMap = new ConcurrentHashMap<>();//替代原本的缓存Map + Map, List> tempOnInsertListenerMap = new ConcurrentHashMap<>();//替代原本的缓存Map - List insertListeners = MapUtil.computeIfAbsent(tempInsertListenerMap, AccountMissingListenerTestModel.class, aClass -> { + List insertListeners = MapUtil.computeIfAbsent(tempOnInsertListenerMap, AccountMissingListenerTestModel.class, aClass -> { List globalListeners = FlexGlobalConfig.getDefaultConfig() .getSupportedInsertListener(AccountMissingListenerTestModel.class, CollectionUtil.isNotEmpty(tableInfo.getOnInsertListeners())); List allListeners = CollectionUtil.merge(tableInfo.getOnInsertListeners(), globalListeners); @@ -62,8 +64,21 @@ class ListenerTest { } //执行测试 ===> 插入结果比对 -// BaseMapper baseMapper = Mappers.ofEntityClass(accountMissingListenerTestModel.getClass()); -// baseMapper.insert(accountMissingListenerTestModel); + BaseMapper baseMapper = Mappers.ofEntityClass(accountMissingListenerTestModel.getClass()); + baseMapper.insert(accountMissingListenerTestModel); + AccountMissingListenerTestModel dbData = (AccountMissingListenerTestModel) baseMapper.selectOneById(accountMissingListenerTestModel.getId()); + + if (dbData.getDelete() == null || dbData.getDelete() != false) { + throw FlexExceptions.wrap("缺失的InsertListener【%s】", LogicDeleteInsertListener.class.getSimpleName()); + } + + if (dbData.getAge() == null || dbData.getAge() != 18) { + throw FlexExceptions.wrap("缺失的InsertListener【%s】", AccountAgeInsertListener.class.getSimpleName()); + } + + if (dbData.getUserName() == null || !dbData.getUserName().equals("测试缺失的监听器-userName")) { + throw FlexExceptions.wrap("缺失的InsertListener【%s】", AccountTableAnnoInsertListener.class.getSimpleName()); + } } }