test(biz): 使用雪花ID替换硬编码ID值
- 在LcBuildingMapperTest中引入IdUtil生成雪花ID - 替换所有手动设置的实体ID为自动生成的雪花ID - 更新selectById和deleteById方法调用以使用实际插入的ID - 移除对固定ID值的依赖,提高测试稳定性 - 统一测试数据ID生成方式,增强代码可维护性
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.jeelowcode.module.biz.mapper;
|
package com.jeelowcode.module.biz.mapper;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.jeelowcode.module.biz.entity.LcBuildingEntity;
|
import com.jeelowcode.module.biz.entity.LcBuildingEntity;
|
||||||
import com.jeelowcode.tool.framework.test.core.ut.BaseDbUnitTest;
|
import com.jeelowcode.tool.framework.test.core.ut.BaseDbUnitTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -24,7 +25,7 @@ public class LcBuildingMapperTest extends BaseDbUnitTest {
|
|||||||
public void testInsert() {
|
public void testInsert() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcBuildingEntity entity = new LcBuildingEntity();
|
LcBuildingEntity entity = new LcBuildingEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setBuildingId("BUILDING_001");
|
entity.setBuildingId("BUILDING_001");
|
||||||
entity.setBuildingName("测试楼宇");
|
entity.setBuildingName("测试楼宇");
|
||||||
entity.setCampusId("CAMPUS_001");
|
entity.setCampusId("CAMPUS_001");
|
||||||
@@ -42,7 +43,7 @@ public class LcBuildingMapperTest extends BaseDbUnitTest {
|
|||||||
assertEquals(1, insertCount);
|
assertEquals(1, insertCount);
|
||||||
|
|
||||||
// 验证插入结果
|
// 验证插入结果
|
||||||
LcBuildingEntity result = lcBuildingMapper.selectById(1L);
|
LcBuildingEntity result = lcBuildingMapper.selectById(entity.getId());
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals("测试楼宇", result.getBuildingName());
|
assertEquals("测试楼宇", result.getBuildingName());
|
||||||
assertEquals("测试园区", result.getCampusName());
|
assertEquals("测试园区", result.getCampusName());
|
||||||
@@ -52,7 +53,7 @@ public class LcBuildingMapperTest extends BaseDbUnitTest {
|
|||||||
public void testSelectList() {
|
public void testSelectList() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcBuildingEntity entity1 = new LcBuildingEntity();
|
LcBuildingEntity entity1 = new LcBuildingEntity();
|
||||||
entity1.setId(1L);
|
entity1.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity1.setBuildingId("BUILDING_001");
|
entity1.setBuildingId("BUILDING_001");
|
||||||
entity1.setBuildingName("测试楼宇1");
|
entity1.setBuildingName("测试楼宇1");
|
||||||
entity1.setCampusId("CAMPUS_001");
|
entity1.setCampusId("CAMPUS_001");
|
||||||
@@ -67,7 +68,7 @@ public class LcBuildingMapperTest extends BaseDbUnitTest {
|
|||||||
lcBuildingMapper.insert(entity1);
|
lcBuildingMapper.insert(entity1);
|
||||||
|
|
||||||
LcBuildingEntity entity2 = new LcBuildingEntity();
|
LcBuildingEntity entity2 = new LcBuildingEntity();
|
||||||
entity2.setId(2L);
|
entity2.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity2.setBuildingId("BUILDING_002");
|
entity2.setBuildingId("BUILDING_002");
|
||||||
entity2.setBuildingName("测试楼宇2");
|
entity2.setBuildingName("测试楼宇2");
|
||||||
entity2.setCampusId("CAMPUS_001");
|
entity2.setCampusId("CAMPUS_001");
|
||||||
@@ -86,14 +87,13 @@ public class LcBuildingMapperTest extends BaseDbUnitTest {
|
|||||||
|
|
||||||
// 验证查询结果
|
// 验证查询结果
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(2, result.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate() {
|
public void testUpdate() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcBuildingEntity entity = new LcBuildingEntity();
|
LcBuildingEntity entity = new LcBuildingEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setBuildingId("BUILDING_001");
|
entity.setBuildingId("BUILDING_001");
|
||||||
entity.setBuildingName("测试楼宇");
|
entity.setBuildingName("测试楼宇");
|
||||||
entity.setCampusId("CAMPUS_001");
|
entity.setCampusId("CAMPUS_001");
|
||||||
@@ -113,7 +113,7 @@ public class LcBuildingMapperTest extends BaseDbUnitTest {
|
|||||||
assertEquals(1, updateCount);
|
assertEquals(1, updateCount);
|
||||||
|
|
||||||
// 验证更新结果
|
// 验证更新结果
|
||||||
LcBuildingEntity result = lcBuildingMapper.selectById(1L);
|
LcBuildingEntity result = lcBuildingMapper.selectById(entity.getId());
|
||||||
assertEquals("更新后的楼宇名称", result.getBuildingName());
|
assertEquals("更新后的楼宇名称", result.getBuildingName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ public class LcBuildingMapperTest extends BaseDbUnitTest {
|
|||||||
public void testDelete() {
|
public void testDelete() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcBuildingEntity entity = new LcBuildingEntity();
|
LcBuildingEntity entity = new LcBuildingEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setBuildingId("BUILDING_001");
|
entity.setBuildingId("BUILDING_001");
|
||||||
entity.setBuildingName("测试楼宇");
|
entity.setBuildingName("测试楼宇");
|
||||||
entity.setCampusId("CAMPUS_001");
|
entity.setCampusId("CAMPUS_001");
|
||||||
@@ -136,11 +136,11 @@ public class LcBuildingMapperTest extends BaseDbUnitTest {
|
|||||||
lcBuildingMapper.insert(entity);
|
lcBuildingMapper.insert(entity);
|
||||||
|
|
||||||
// 执行删除
|
// 执行删除
|
||||||
int deleteCount = lcBuildingMapper.deleteById(1L);
|
int deleteCount = lcBuildingMapper.deleteById(entity.getId());
|
||||||
assertEquals(1, deleteCount);
|
assertEquals(1, deleteCount);
|
||||||
|
|
||||||
// 验证删除结果
|
// 验证删除结果
|
||||||
LcBuildingEntity result = lcBuildingMapper.selectById(1L);
|
LcBuildingEntity result = lcBuildingMapper.selectById(entity.getId());
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.jeelowcode.module.biz.mapper;
|
package com.jeelowcode.module.biz.mapper;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.jeelowcode.module.biz.entity.LcPowerEnvDeviceEntity;
|
import com.jeelowcode.module.biz.entity.LcPowerEnvDeviceEntity;
|
||||||
import com.jeelowcode.tool.framework.test.core.ut.BaseDbUnitTest;
|
import com.jeelowcode.tool.framework.test.core.ut.BaseDbUnitTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -23,7 +24,7 @@ public class LcPowerEnvDeviceMapperTest extends BaseDbUnitTest {
|
|||||||
public void testInsert() {
|
public void testInsert() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity();
|
LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setDeviceUid("DEVICE_UID_001");
|
entity.setDeviceUid("DEVICE_UID_001");
|
||||||
entity.setDeviceCode("DEVICE_CODE_001");
|
entity.setDeviceCode("DEVICE_CODE_001");
|
||||||
entity.setDeviceTypeCode("TYPE_001");
|
entity.setDeviceTypeCode("TYPE_001");
|
||||||
@@ -46,7 +47,7 @@ public class LcPowerEnvDeviceMapperTest extends BaseDbUnitTest {
|
|||||||
assertEquals(1, insertCount);
|
assertEquals(1, insertCount);
|
||||||
|
|
||||||
// 验证插入结果
|
// 验证插入结果
|
||||||
LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(1L);
|
LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(entity.getId());
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals("DEVICE_UID_001", result.getDeviceUid());
|
assertEquals("DEVICE_UID_001", result.getDeviceUid());
|
||||||
assertEquals("温度传感器", result.getDeviceTypeName());
|
assertEquals("温度传感器", result.getDeviceTypeName());
|
||||||
@@ -56,7 +57,7 @@ public class LcPowerEnvDeviceMapperTest extends BaseDbUnitTest {
|
|||||||
public void testSelectById() {
|
public void testSelectById() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity();
|
LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setDeviceUid("DEVICE_UID_001");
|
entity.setDeviceUid("DEVICE_UID_001");
|
||||||
entity.setDeviceCode("DEVICE_CODE_001");
|
entity.setDeviceCode("DEVICE_CODE_001");
|
||||||
entity.setDeviceTypeCode("TYPE_001");
|
entity.setDeviceTypeCode("TYPE_001");
|
||||||
@@ -76,7 +77,7 @@ public class LcPowerEnvDeviceMapperTest extends BaseDbUnitTest {
|
|||||||
lcPowerEnvDeviceMapper.insert(entity);
|
lcPowerEnvDeviceMapper.insert(entity);
|
||||||
|
|
||||||
// 执行查询
|
// 执行查询
|
||||||
LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(1L);
|
LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(entity.getId());
|
||||||
|
|
||||||
// 验证查询结果
|
// 验证查询结果
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
@@ -89,7 +90,7 @@ public class LcPowerEnvDeviceMapperTest extends BaseDbUnitTest {
|
|||||||
public void testUpdate() {
|
public void testUpdate() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity();
|
LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setDeviceUid("DEVICE_UID_001");
|
entity.setDeviceUid("DEVICE_UID_001");
|
||||||
entity.setDeviceCode("DEVICE_CODE_001");
|
entity.setDeviceCode("DEVICE_CODE_001");
|
||||||
entity.setDeviceTypeCode("TYPE_001");
|
entity.setDeviceTypeCode("TYPE_001");
|
||||||
@@ -114,7 +115,7 @@ public class LcPowerEnvDeviceMapperTest extends BaseDbUnitTest {
|
|||||||
assertEquals(1, updateCount);
|
assertEquals(1, updateCount);
|
||||||
|
|
||||||
// 验证更新结果
|
// 验证更新结果
|
||||||
LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(1L);
|
LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(entity.getId());
|
||||||
assertEquals("湿度传感器", result.getDeviceTypeName());
|
assertEquals("湿度传感器", result.getDeviceTypeName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ public class LcPowerEnvDeviceMapperTest extends BaseDbUnitTest {
|
|||||||
public void testDelete() {
|
public void testDelete() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity();
|
LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setDeviceUid("DEVICE_UID_001");
|
entity.setDeviceUid("DEVICE_UID_001");
|
||||||
entity.setDeviceCode("DEVICE_CODE_001");
|
entity.setDeviceCode("DEVICE_CODE_001");
|
||||||
entity.setDeviceTypeCode("TYPE_001");
|
entity.setDeviceTypeCode("TYPE_001");
|
||||||
@@ -142,11 +143,11 @@ public class LcPowerEnvDeviceMapperTest extends BaseDbUnitTest {
|
|||||||
lcPowerEnvDeviceMapper.insert(entity);
|
lcPowerEnvDeviceMapper.insert(entity);
|
||||||
|
|
||||||
// 执行删除
|
// 执行删除
|
||||||
int deleteCount = lcPowerEnvDeviceMapper.deleteById(1L);
|
int deleteCount = lcPowerEnvDeviceMapper.deleteById(entity.getId());
|
||||||
assertEquals(1, deleteCount);
|
assertEquals(1, deleteCount);
|
||||||
|
|
||||||
// 验证删除结果
|
// 验证删除结果
|
||||||
LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(1L);
|
LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(entity.getId());
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.jeelowcode.module.biz.mapper;
|
package com.jeelowcode.module.biz.mapper;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.jeelowcode.module.biz.entity.LcPowerEnvMonitorMetricEntity;
|
import com.jeelowcode.module.biz.entity.LcPowerEnvMonitorMetricEntity;
|
||||||
import com.jeelowcode.tool.framework.test.core.ut.BaseDbUnitTest;
|
import com.jeelowcode.tool.framework.test.core.ut.BaseDbUnitTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@@ -23,7 +24,7 @@ public class LcPowerEnvMonitorMetricMapperTest extends BaseDbUnitTest {
|
|||||||
public void testInsert() {
|
public void testInsert() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity();
|
LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setDeviceUid("DEVICE_UID_001");
|
entity.setDeviceUid("DEVICE_UID_001");
|
||||||
entity.setMetadataUid("METADATA_UID_001");
|
entity.setMetadataUid("METADATA_UID_001");
|
||||||
entity.setMetadataCode("METADATA_CODE_001");
|
entity.setMetadataCode("METADATA_CODE_001");
|
||||||
@@ -49,7 +50,7 @@ public class LcPowerEnvMonitorMetricMapperTest extends BaseDbUnitTest {
|
|||||||
assertEquals(1, insertCount);
|
assertEquals(1, insertCount);
|
||||||
|
|
||||||
// 验证插入结果
|
// 验证插入结果
|
||||||
LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(1L);
|
LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(entity.getId());
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals("DEVICE_UID_001", result.getDeviceUid());
|
assertEquals("DEVICE_UID_001", result.getDeviceUid());
|
||||||
assertEquals("26.5", result.getMetricValue());
|
assertEquals("26.5", result.getMetricValue());
|
||||||
@@ -60,7 +61,7 @@ public class LcPowerEnvMonitorMetricMapperTest extends BaseDbUnitTest {
|
|||||||
public void testSelectById() {
|
public void testSelectById() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity();
|
LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setDeviceUid("DEVICE_UID_001");
|
entity.setDeviceUid("DEVICE_UID_001");
|
||||||
entity.setMetadataUid("METADATA_UID_001");
|
entity.setMetadataUid("METADATA_UID_001");
|
||||||
entity.setMetadataCode("METADATA_CODE_001");
|
entity.setMetadataCode("METADATA_CODE_001");
|
||||||
@@ -83,7 +84,7 @@ public class LcPowerEnvMonitorMetricMapperTest extends BaseDbUnitTest {
|
|||||||
lcPowerEnvMonitorMetricMapper.insert(entity);
|
lcPowerEnvMonitorMetricMapper.insert(entity);
|
||||||
|
|
||||||
// 执行查询
|
// 执行查询
|
||||||
LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(1L);
|
LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(entity.getId());
|
||||||
|
|
||||||
// 验证查询结果
|
// 验证查询结果
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
@@ -96,7 +97,7 @@ public class LcPowerEnvMonitorMetricMapperTest extends BaseDbUnitTest {
|
|||||||
public void testUpdate() {
|
public void testUpdate() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity();
|
LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setDeviceUid("DEVICE_UID_001");
|
entity.setDeviceUid("DEVICE_UID_001");
|
||||||
entity.setMetadataUid("METADATA_UID_001");
|
entity.setMetadataUid("METADATA_UID_001");
|
||||||
entity.setMetadataCode("METADATA_CODE_001");
|
entity.setMetadataCode("METADATA_CODE_001");
|
||||||
@@ -124,7 +125,7 @@ public class LcPowerEnvMonitorMetricMapperTest extends BaseDbUnitTest {
|
|||||||
assertEquals(1, updateCount);
|
assertEquals(1, updateCount);
|
||||||
|
|
||||||
// 验证更新结果
|
// 验证更新结果
|
||||||
LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(1L);
|
LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(entity.getId());
|
||||||
assertEquals("27.8", result.getMetricValue());
|
assertEquals("27.8", result.getMetricValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +133,7 @@ public class LcPowerEnvMonitorMetricMapperTest extends BaseDbUnitTest {
|
|||||||
public void testDelete() {
|
public void testDelete() {
|
||||||
// 准备数据
|
// 准备数据
|
||||||
LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity();
|
LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity();
|
||||||
entity.setId(1L);
|
entity.setId(IdUtil.getSnowflakeNextId());
|
||||||
entity.setDeviceUid("DEVICE_UID_001");
|
entity.setDeviceUid("DEVICE_UID_001");
|
||||||
entity.setMetadataUid("METADATA_UID_001");
|
entity.setMetadataUid("METADATA_UID_001");
|
||||||
entity.setMetadataCode("METADATA_CODE_001");
|
entity.setMetadataCode("METADATA_CODE_001");
|
||||||
@@ -155,11 +156,11 @@ public class LcPowerEnvMonitorMetricMapperTest extends BaseDbUnitTest {
|
|||||||
lcPowerEnvMonitorMetricMapper.insert(entity);
|
lcPowerEnvMonitorMetricMapper.insert(entity);
|
||||||
|
|
||||||
// 执行删除
|
// 执行删除
|
||||||
int deleteCount = lcPowerEnvMonitorMetricMapper.deleteById(1L);
|
int deleteCount = lcPowerEnvMonitorMetricMapper.deleteById(entity.getId());
|
||||||
assertEquals(1, deleteCount);
|
assertEquals(1, deleteCount);
|
||||||
|
|
||||||
// 验证删除结果
|
// 验证删除结果
|
||||||
LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(1L);
|
LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(entity.getId());
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user