diff --git a/jeelowcode-admin/src/test/java/com/jeelowcode/test/mapper/LcBuildingMapperTest.java b/jeelowcode-admin/src/test/java/com/jeelowcode/test/mapper/LcBuildingMapperTest.java new file mode 100644 index 0000000..7006f53 --- /dev/null +++ b/jeelowcode-admin/src/test/java/com/jeelowcode/test/mapper/LcBuildingMapperTest.java @@ -0,0 +1,147 @@ +package com.jeelowcode.test.mapper; + +import com.jeelowcode.module.biz.entity.LcBuildingEntity; +import com.jeelowcode.module.biz.mapper.LcBuildingMapper; +import com.jeelowcode.tool.framework.test.core.ut.BaseDbUnitTest; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * {@link LcBuildingMapper} 的单元测试类 + */ +@Import(LcBuildingMapper.class) +public class LcBuildingMapperTest extends BaseDbUnitTest { + + @Resource + private LcBuildingMapper lcBuildingMapper; + + @Test + public void testInsert() { + // 准备数据 + LcBuildingEntity entity = new LcBuildingEntity(); + entity.setId(1L); + entity.setBuildingId("BUILDING_001"); + entity.setBuildingName("测试楼宇"); + entity.setCampusId("CAMPUS_001"); + entity.setCampusName("测试园区"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + + // 执行插入 + int insertCount = lcBuildingMapper.insert(entity); + assertEquals(1, insertCount); + + // 验证插入结果 + LcBuildingEntity result = lcBuildingMapper.selectById(1L); + assertNotNull(result); + assertEquals("测试楼宇", result.getBuildingName()); + assertEquals("测试园区", result.getCampusName()); + } + + @Test + public void testSelectList() { + // 准备数据 + LcBuildingEntity entity1 = new LcBuildingEntity(); + entity1.setId(1L); + entity1.setBuildingId("BUILDING_001"); + entity1.setBuildingName("测试楼宇1"); + entity1.setCampusId("CAMPUS_001"); + entity1.setCampusName("测试园区1"); + entity1.setTenantId(1L); + entity1.setCreateUser(1L); + entity1.setCreateTime(LocalDateTime.now()); + entity1.setCreateDept(1L); + entity1.setUpdateUser(1L); + entity1.setUpdateTime(LocalDateTime.now()); + entity1.setIsDeleted(0); + lcBuildingMapper.insert(entity1); + + LcBuildingEntity entity2 = new LcBuildingEntity(); + entity2.setId(2L); + entity2.setBuildingId("BUILDING_002"); + entity2.setBuildingName("测试楼宇2"); + entity2.setCampusId("CAMPUS_001"); + entity2.setCampusName("测试园区1"); + entity2.setTenantId(1L); + entity2.setCreateUser(1L); + entity2.setCreateTime(LocalDateTime.now()); + entity2.setCreateDept(1L); + entity2.setUpdateUser(1L); + entity2.setUpdateTime(LocalDateTime.now()); + entity2.setIsDeleted(0); + lcBuildingMapper.insert(entity2); + + // 执行查询 + List result = lcBuildingMapper.selectList(null); + + // 验证查询结果 + assertNotNull(result); + assertEquals(2, result.size()); + } + + @Test + public void testUpdate() { + // 准备数据 + LcBuildingEntity entity = new LcBuildingEntity(); + entity.setId(1L); + entity.setBuildingId("BUILDING_001"); + entity.setBuildingName("测试楼宇"); + entity.setCampusId("CAMPUS_001"); + entity.setCampusName("测试园区"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + lcBuildingMapper.insert(entity); + + // 执行更新 + entity.setBuildingName("更新后的楼宇名称"); + int updateCount = lcBuildingMapper.updateById(entity); + assertEquals(1, updateCount); + + // 验证更新结果 + LcBuildingEntity result = lcBuildingMapper.selectById(1L); + assertEquals("更新后的楼宇名称", result.getBuildingName()); + } + + @Test + public void testDelete() { + // 准备数据 + LcBuildingEntity entity = new LcBuildingEntity(); + entity.setId(1L); + entity.setBuildingId("BUILDING_001"); + entity.setBuildingName("测试楼宇"); + entity.setCampusId("CAMPUS_001"); + entity.setCampusName("测试园区"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + lcBuildingMapper.insert(entity); + + // 执行删除 + int deleteCount = lcBuildingMapper.deleteById(1L); + assertEquals(1, deleteCount); + + // 验证删除结果 + LcBuildingEntity result = lcBuildingMapper.selectById(1L); + assertNull(result); + } +} \ No newline at end of file diff --git a/jeelowcode-admin/src/test/java/com/jeelowcode/test/mapper/LcPowerEnvDeviceMapperTest.java b/jeelowcode-admin/src/test/java/com/jeelowcode/test/mapper/LcPowerEnvDeviceMapperTest.java new file mode 100644 index 0000000..dc9b8da --- /dev/null +++ b/jeelowcode-admin/src/test/java/com/jeelowcode/test/mapper/LcPowerEnvDeviceMapperTest.java @@ -0,0 +1,153 @@ +package com.jeelowcode.test.mapper; + +import com.jeelowcode.module.biz.entity.LcPowerEnvDeviceEntity; +import com.jeelowcode.module.biz.mapper.LcPowerEnvDeviceMapper; +import com.jeelowcode.tool.framework.test.core.ut.BaseDbUnitTest; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * {@link LcPowerEnvDeviceMapper} 的单元测试类 + */ +@Import(LcPowerEnvDeviceMapper.class) +public class LcPowerEnvDeviceMapperTest extends BaseDbUnitTest { + + @Resource + private LcPowerEnvDeviceMapper lcPowerEnvDeviceMapper; + + @Test + public void testInsert() { + // 准备数据 + LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity(); + entity.setId(1L); + entity.setDeviceUid("DEVICE_UID_001"); + entity.setDeviceCode("DEVICE_CODE_001"); + entity.setDeviceTypeCode("TYPE_001"); + entity.setDeviceTypeName("温度传感器"); + entity.setBuildingId("BUILDING_001"); + entity.setBuildingName("测试楼宇"); + entity.setCampusId("CAMPUS_001"); + entity.setCampusName("测试园区"); + entity.setMonitorData("{\"temperature\": 25.6}"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + + // 执行插入 + int insertCount = lcPowerEnvDeviceMapper.insert(entity); + assertEquals(1, insertCount); + + // 验证插入结果 + LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(1L); + assertNotNull(result); + assertEquals("DEVICE_UID_001", result.getDeviceUid()); + assertEquals("温度传感器", result.getDeviceTypeName()); + } + + @Test + public void testSelectById() { + // 准备数据 + LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity(); + entity.setId(1L); + entity.setDeviceUid("DEVICE_UID_001"); + entity.setDeviceCode("DEVICE_CODE_001"); + entity.setDeviceTypeCode("TYPE_001"); + entity.setDeviceTypeName("温度传感器"); + entity.setBuildingId("BUILDING_001"); + entity.setBuildingName("测试楼宇"); + entity.setCampusId("CAMPUS_001"); + entity.setCampusName("测试园区"); + entity.setMonitorData("{\"temperature\": 25.6}"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + lcPowerEnvDeviceMapper.insert(entity); + + // 执行查询 + LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(1L); + + // 验证查询结果 + assertNotNull(result); + assertEquals("DEVICE_UID_001", result.getDeviceUid()); + assertEquals("温度传感器", result.getDeviceTypeName()); + assertEquals("测试楼宇", result.getBuildingName()); + } + + @Test + public void testUpdate() { + // 准备数据 + LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity(); + entity.setId(1L); + entity.setDeviceUid("DEVICE_UID_001"); + entity.setDeviceCode("DEVICE_CODE_001"); + entity.setDeviceTypeCode("TYPE_001"); + entity.setDeviceTypeName("温度传感器"); + entity.setBuildingId("BUILDING_001"); + entity.setBuildingName("测试楼宇"); + entity.setCampusId("CAMPUS_001"); + entity.setCampusName("测试园区"); + entity.setMonitorData("{\"temperature\": 25.6}"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + lcPowerEnvDeviceMapper.insert(entity); + + // 执行更新 + entity.setDeviceTypeName("湿度传感器"); + int updateCount = lcPowerEnvDeviceMapper.updateById(entity); + assertEquals(1, updateCount); + + // 验证更新结果 + LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(1L); + assertEquals("湿度传感器", result.getDeviceTypeName()); + } + + @Test + public void testDelete() { + // 准备数据 + LcPowerEnvDeviceEntity entity = new LcPowerEnvDeviceEntity(); + entity.setId(1L); + entity.setDeviceUid("DEVICE_UID_001"); + entity.setDeviceCode("DEVICE_CODE_001"); + entity.setDeviceTypeCode("TYPE_001"); + entity.setDeviceTypeName("温度传感器"); + entity.setBuildingId("BUILDING_001"); + entity.setBuildingName("测试楼宇"); + entity.setCampusId("CAMPUS_001"); + entity.setCampusName("测试园区"); + entity.setMonitorData("{\"temperature\": 25.6}"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + lcPowerEnvDeviceMapper.insert(entity); + + // 执行删除 + int deleteCount = lcPowerEnvDeviceMapper.deleteById(1L); + assertEquals(1, deleteCount); + + // 验证删除结果 + LcPowerEnvDeviceEntity result = lcPowerEnvDeviceMapper.selectById(1L); + assertNull(result); + } +} \ No newline at end of file diff --git a/jeelowcode-admin/src/test/java/com/jeelowcode/test/mapper/LcPowerEnvMonitorMetricMapperTest.java b/jeelowcode-admin/src/test/java/com/jeelowcode/test/mapper/LcPowerEnvMonitorMetricMapperTest.java new file mode 100644 index 0000000..b3102a0 --- /dev/null +++ b/jeelowcode-admin/src/test/java/com/jeelowcode/test/mapper/LcPowerEnvMonitorMetricMapperTest.java @@ -0,0 +1,166 @@ +package com.jeelowcode.test.mapper; + +import com.jeelowcode.module.biz.entity.LcPowerEnvMonitorMetricEntity; +import com.jeelowcode.module.biz.mapper.LcPowerEnvMonitorMetricMapper; +import com.jeelowcode.tool.framework.test.core.ut.BaseDbUnitTest; +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.Import; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +import static org.junit.jupiter.api.Assertions.*; + +/** + * {@link LcPowerEnvMonitorMetricMapper} 的单元测试类 + */ +@Import(LcPowerEnvMonitorMetricMapper.class) +public class LcPowerEnvMonitorMetricMapperTest extends BaseDbUnitTest { + + @Resource + private LcPowerEnvMonitorMetricMapper lcPowerEnvMonitorMetricMapper; + + @Test + public void testInsert() { + // 准备数据 + LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity(); + entity.setId(1L); + entity.setDeviceUid("DEVICE_UID_001"); + entity.setMetadataUid("METADATA_UID_001"); + entity.setMetadataCode("METADATA_CODE_001"); + entity.setMetadataName("温度"); + entity.setPropertyCode("PROPERTY_TEMP"); + entity.setPropertyName("温度值"); + entity.setUnitCode("℃"); + entity.setValueType(1); + entity.setValueTypeName("数值型"); + entity.setPointType(1); + entity.setPointTypeName("模拟量"); + entity.setMetricValue("26.5"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + + // 执行插入 + int insertCount = lcPowerEnvMonitorMetricMapper.insert(entity); + assertEquals(1, insertCount); + + // 验证插入结果 + LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(1L); + assertNotNull(result); + assertEquals("DEVICE_UID_001", result.getDeviceUid()); + assertEquals("26.5", result.getMetricValue()); + assertEquals("℃", result.getUnitCode()); + } + + @Test + public void testSelectById() { + // 准备数据 + LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity(); + entity.setId(1L); + entity.setDeviceUid("DEVICE_UID_001"); + entity.setMetadataUid("METADATA_UID_001"); + entity.setMetadataCode("METADATA_CODE_001"); + entity.setMetadataName("温度"); + entity.setPropertyCode("PROPERTY_TEMP"); + entity.setPropertyName("温度值"); + entity.setUnitCode("℃"); + entity.setValueType(1); + entity.setValueTypeName("数值型"); + entity.setPointType(1); + entity.setPointTypeName("模拟量"); + entity.setMetricValue("26.5"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + lcPowerEnvMonitorMetricMapper.insert(entity); + + // 执行查询 + LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(1L); + + // 验证查询结果 + assertNotNull(result); + assertEquals("温度", result.getMetadataName()); + assertEquals("温度值", result.getPropertyName()); + assertEquals(1, result.getValueType()); + } + + @Test + public void testUpdate() { + // 准备数据 + LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity(); + entity.setId(1L); + entity.setDeviceUid("DEVICE_UID_001"); + entity.setMetadataUid("METADATA_UID_001"); + entity.setMetadataCode("METADATA_CODE_001"); + entity.setMetadataName("温度"); + entity.setPropertyCode("PROPERTY_TEMP"); + entity.setPropertyName("温度值"); + entity.setUnitCode("℃"); + entity.setValueType(1); + entity.setValueTypeName("数值型"); + entity.setPointType(1); + entity.setPointTypeName("模拟量"); + entity.setMetricValue("26.5"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + lcPowerEnvMonitorMetricMapper.insert(entity); + + // 执行更新 + entity.setMetricValue("27.8"); + int updateCount = lcPowerEnvMonitorMetricMapper.updateById(entity); + assertEquals(1, updateCount); + + // 验证更新结果 + LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(1L); + assertEquals("27.8", result.getMetricValue()); + } + + @Test + public void testDelete() { + // 准备数据 + LcPowerEnvMonitorMetricEntity entity = new LcPowerEnvMonitorMetricEntity(); + entity.setId(1L); + entity.setDeviceUid("DEVICE_UID_001"); + entity.setMetadataUid("METADATA_UID_001"); + entity.setMetadataCode("METADATA_CODE_001"); + entity.setMetadataName("温度"); + entity.setPropertyCode("PROPERTY_TEMP"); + entity.setPropertyName("温度值"); + entity.setUnitCode("℃"); + entity.setValueType(1); + entity.setValueTypeName("数值型"); + entity.setPointType(1); + entity.setPointTypeName("模拟量"); + entity.setMetricValue("26.5"); + entity.setTenantId(1L); + entity.setCreateUser(1L); + entity.setCreateTime(LocalDateTime.now()); + entity.setCreateDept(1L); + entity.setUpdateUser(1L); + entity.setUpdateTime(LocalDateTime.now()); + entity.setIsDeleted(0); + lcPowerEnvMonitorMetricMapper.insert(entity); + + // 执行删除 + int deleteCount = lcPowerEnvMonitorMetricMapper.deleteById(1L); + assertEquals(1, deleteCount); + + // 验证删除结果 + LcPowerEnvMonitorMetricEntity result = lcPowerEnvMonitorMetricMapper.selectById(1L); + assertNull(result); + } +} \ No newline at end of file