mirror of https://gitee.com/stylefeng/roses
【8.3.0】【scanner】【test】测试为空对象的解析
parent
581ee10805
commit
cac851f055
|
@ -0,0 +1,42 @@
|
|||
package cn.stylefeng.roses.kernel.scanner.api;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.factory.ClassMetaFactory;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.pojo.EmptyObject;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.pojo.resource.FieldMetadata;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.util.AdvancedClassTypeUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* 测试为空对象
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/7 14:57
|
||||
*/
|
||||
public class TestEmptyObject {
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
AdvancedClassTypeUtil.TEMP_SCAN_PACKAGE_LIST = ListUtil.of("cn.stylefeng");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyObj() {
|
||||
Type type = new TypeReference<EmptyObject>() {
|
||||
}.getType();
|
||||
|
||||
FieldMetadata fieldMetadata = ClassMetaFactory.beginCreateFieldMetadata(type, IdUtil.fastSimpleUUID());
|
||||
|
||||
String jsonString = JSON.toJSONString(fieldMetadata, JSONWriter.Feature.PrettyFormat);
|
||||
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package cn.stylefeng.roses.kernel.scanner.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 为空的对象
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/7 14:56
|
||||
*/
|
||||
@Data
|
||||
public class EmptyObject {
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.scanner.api.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 一个基本的对象
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/5 10:32
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class MyRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ChineseDescription("用户id")
|
||||
@NotNull(message = "用户id不能为空", groups = add.class)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@ChineseDescription("用户名")
|
||||
@NotEmpty(message = "用户名不能为空", groups = add.class)
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
@ChineseDescription("年龄")
|
||||
@NotNull(message = "年龄不能为空", groups = edit.class)
|
||||
private Integer age;
|
||||
|
||||
/**
|
||||
* 用户分数
|
||||
*/
|
||||
@ChineseDescription("用户分数")
|
||||
@NotNull(message = "用户分数不能为空", groups = edit.class)
|
||||
private BigDecimal userScore;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@ChineseDescription("列表")
|
||||
@NotEmpty(message = "列表不能为空", groups = {add.class, edit.class})
|
||||
private List<String> mySimpleList;
|
||||
}
|
Loading…
Reference in New Issue