mirror of https://gitee.com/stylefeng/roses
【8.3.0】【scanner】【test】测试数组的解析
parent
4bb806bbb8
commit
44ddcd16ea
|
@ -37,6 +37,18 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!--测试需要的包-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
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.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.factory.ClassMetaFactory;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.pojo.SimpleObject;
|
||||
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;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 测试
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/7 14:25
|
||||
*/
|
||||
public class TestArray {
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
AdvancedClassTypeUtil.TEMP_SCAN_PACKAGE_LIST = ListUtil.of("cn.stylefeng");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleArray() {
|
||||
Type type = new TypeReference<List<String>>() {
|
||||
}.getType();
|
||||
|
||||
FieldMetadata fieldMetadata = ClassMetaFactory.beginCreateFieldMetadata(type, IdUtil.fastSimpleUUID());
|
||||
|
||||
String jsonString = JSON.toJSONString(fieldMetadata, JSONWriter.Feature.PrettyFormat);
|
||||
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectArray() {
|
||||
Type type = new TypeReference<List<SimpleObject>>() {
|
||||
}.getType();
|
||||
|
||||
FieldMetadata fieldMetadata = ClassMetaFactory.beginCreateFieldMetadata(type, IdUtil.fastSimpleUUID());
|
||||
|
||||
String jsonString = JSON.toJSONString(fieldMetadata, JSONWriter.Feature.PrettyFormat);
|
||||
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenArray() {
|
||||
Type type = new TypeReference<ResponseData<List<SimpleObject>>>() {
|
||||
}.getType();
|
||||
|
||||
FieldMetadata fieldMetadata = ClassMetaFactory.beginCreateFieldMetadata(type, IdUtil.fastSimpleUUID());
|
||||
|
||||
String jsonString = JSON.toJSONString(fieldMetadata, JSONWriter.Feature.PrettyFormat);
|
||||
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiArray() {
|
||||
Type type = new TypeReference<Set<List<List<SimpleObject>>>>() {
|
||||
}.getType();
|
||||
|
||||
FieldMetadata fieldMetadata = ClassMetaFactory.beginCreateFieldMetadata(type, IdUtil.fastSimpleUUID());
|
||||
|
||||
String jsonString = JSON.toJSONString(fieldMetadata, JSONWriter.Feature.PrettyFormat);
|
||||
|
||||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package cn.stylefeng.roses.kernel.scanner.api.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 递归调用的测试
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/5 15:28
|
||||
*/
|
||||
@Data
|
||||
public class CircularObject {
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ChineseDescription("用户id")
|
||||
@NotNull(message = "用户id不能为空")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@ChineseDescription("用户名")
|
||||
@NotEmpty(message = "用户名不能为空")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
@ChineseDescription("年龄")
|
||||
@NotNull(message = "年龄不能为空")
|
||||
private Integer age;
|
||||
|
||||
/**
|
||||
* 用户分数
|
||||
*/
|
||||
@ChineseDescription("用户分数")
|
||||
@NotNull(message = "用户分数不能为空")
|
||||
private BigDecimal userScore;
|
||||
|
||||
/**
|
||||
* 递归列表
|
||||
*/
|
||||
@ChineseDescription("递归列表")
|
||||
@NotEmpty(message = "递归列表")
|
||||
private List<CircularObject> circularObjectList;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package cn.stylefeng.roses.kernel.scanner.api.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 我的请求类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/4 15:53
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ExtendsSimpleObject extends SimpleObject {
|
||||
|
||||
/**
|
||||
* 单位地址
|
||||
*/
|
||||
@ChineseDescription("单位地址")
|
||||
private String companyAddress;
|
||||
|
||||
/**
|
||||
* 工作项列表
|
||||
*/
|
||||
@ChineseDescription("工作项列表")
|
||||
private List<WorkItem> workItemList;
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
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;
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package cn.stylefeng.roses.kernel.scanner.api.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 一个基本的对象
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/5 10:32
|
||||
*/
|
||||
@Data
|
||||
public class SimpleObject {
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@ChineseDescription("用户id")
|
||||
@NotNull(message = "用户id不能为空")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@ChineseDescription("用户名")
|
||||
@NotEmpty(message = "用户名不能为空")
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
@ChineseDescription("年龄")
|
||||
@NotNull(message = "年龄不能为空")
|
||||
private Integer age;
|
||||
|
||||
/**
|
||||
* 用户分数
|
||||
*/
|
||||
@ChineseDescription("用户分数")
|
||||
@NotNull(message = "用户分数不能为空")
|
||||
private BigDecimal userScore;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@ChineseDescription("列表")
|
||||
@NotEmpty(message = "列表不能为空")
|
||||
private List<String> mySimpleList;
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package cn.stylefeng.roses.kernel.scanner.api.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 工作项
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/5 10:35
|
||||
*/
|
||||
@Data
|
||||
public class WorkItem {
|
||||
|
||||
/**
|
||||
* 键
|
||||
*/
|
||||
@ChineseDescription("键")
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 值
|
||||
*/
|
||||
@ChineseDescription("值")
|
||||
private Object value;
|
||||
|
||||
}
|
Loading…
Reference in New Issue