system微服务api模块、枚举单元测试完善

This commit is contained in:
gaoqr
2025-12-12 10:06:43 +08:00
parent 96cb488f5d
commit 3d0e42f4eb
4 changed files with 105 additions and 13 deletions
@@ -1,7 +1,6 @@
package com.cf.imes.module.system.api.user;
import com.cf.imes.framework.common.pojo.CommonResult;
import com.cf.imes.framework.common.util.collection.CollectionUtils;
import com.cf.imes.module.system.api.user.dto.AdminUserRespDTO;
import com.cf.imes.module.system.api.user.dto.OrganAdminUserRespDTO;
import com.cf.imes.module.system.enums.ApiConstants;
@@ -15,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@FeignClient(name = ApiConstants.NAME) // TODO 晨丰:fallbackFactory =
@@ -44,17 +42,6 @@ public interface AdminUserApi {
@Parameter(name = "postIds", description = "岗位编号数组", example = "2,3", required = true)
CommonResult<List<AdminUserRespDTO>> getUserListByPostIds(@RequestParam("postIds") Collection<Long> postIds);
/**
* 获得用户 Map
*
* @param ids 用户编号数组
* @return 用户 Map
*/
default Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids) {
List<AdminUserRespDTO> users = getUserList(ids).getCheckedData();
return CollectionUtils.convertMap(users, AdminUserRespDTO::getId);
}
@GetMapping(PREFIX + "/valid")
@Operation(summary = "校验用户们是否有效")
@Parameter(name = "ids", description = "用户编号数组", example = "3,5", required = true)
@@ -0,0 +1,59 @@
package com.cf.imes.module.system.api.organ;
import com.cf.imes.module.system.api.organ.dto.OrgStatisticsIsLapseRespDTO;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link OrgStatisticsIsLapseRespDTO} 的单元测试
*/
public class OrgStatisticsIsLapseRespDTOTest {
private OrgStatisticsIsLapseRespDTO dto(String date, int status) {
return OrgStatisticsIsLapseRespDTO.builder()
.date(date)
.orgStatus(status)
.build();
}
@Test
void testCompareDifferentYear() {
// 年份大 > 小
assertTrue(dto("2023-01-02", 1).compareTo(dto("2022-01-02", 1)) > 0);
}
@Test
void testCompareDifferentMonth() {
// 月份大 > 小
assertTrue(dto("2023-05-01", 1).compareTo(dto("2023-03-01", 1)) > 0);
}
@Test
void testCompareDifferentWeek() {
// 周 大 > 小
assertTrue(dto("2023-05-02", 1).compareTo(dto("2023-05-01", 1)) > 0);
// 相同周 状态小 < 大
assertTrue(dto("2023-05-02", 1).compareTo(dto("2023-05-02", 2)) < 0);
}
@Test
void testBothWithoutWeek() {
// 都不带周 状态大 > 小
assertTrue(dto("2023-05", 2).compareTo(dto("2023-05", 1)) > 0);
}
@Test
void testOneWithoutMonth() {
// 前不带月, 状态小 < 大
assertTrue(dto("2023", 1).compareTo(dto("2023-05", 2)) < 0);
// 后不带月, 状态大 > 小
assertTrue(dto("2023-05", 2).compareTo(dto("2023", 1)) > 0);
}
@Test
void testOneWithoutWeek() {
// 前不带周, 状态小 < 大
assertTrue(dto("2023-05", 1).compareTo(dto("2023-05-02", 2)) < 0);
// 后不带周, 状态大 > 小
assertTrue(dto("2023-05-02", 2).compareTo(dto("2023-05", 1)) > 0);
}
}
@@ -0,0 +1,21 @@
package com.cf.imes.module.system.api.permission.dto;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* {@link com.cf.imes.module.system.api.permission.dto.DeptDataPermissionRespDTO} 的单元测试
*
* @author Gqr
* @since 2025/12/12 9:47
*/
public class DeptDataPermissionRespDTOTest {
@Test
void test() {
DeptDataPermissionRespDTO deptDataPermissionRespDTO = new DeptDataPermissionRespDTO();
assertEquals(deptDataPermissionRespDTO.getAll(), false);
assertEquals(deptDataPermissionRespDTO.getSelf(), false);
assertEquals(deptDataPermissionRespDTO.getDeptIds().size(), 0);
}
}
@@ -0,0 +1,25 @@
package com.cf.imes.module.system.enums.token;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link TokenConfigAppTypeEnum} 的单元测试
*/
public class TokenConfigAppTypeEnumTest {
@Test
public void testEnumValues() {
// 测试枚举值是否正确
assertEquals(1, TokenConfigAppTypeEnum.WEBCAD.getType());
assertEquals("WebCAD", TokenConfigAppTypeEnum.WEBCAD.getName());
}
@Test
public void testFromType() {
// 测试 fromType 方法
assertEquals(TokenConfigAppTypeEnum.WEBCAD, TokenConfigAppTypeEnum.fromType(1));
assertNull(TokenConfigAppTypeEnum.fromType(99)); // 不存在的类型
assertNull(TokenConfigAppTypeEnum.fromType(null)); // null值
}
}