feat: 1、Vo包装识别增强 2、去除 位置&类型 的色块
All checks were successful
序列化结构检查 / serialization-schema-check (push) Has been skipped
All checks were successful
序列化结构检查 / serialization-schema-check (push) Has been skipped
This commit is contained in:
@@ -40,6 +40,41 @@ class SchemaDifferTest {
|
||||
assertEquals(2, moved, "dbName 与 linkList[].id 均应迁移");
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectsWrapperRemovalAndUpwardMoves() {
|
||||
TypeSchema oldS = new TypeSchema("CacheEnvelope");
|
||||
oldS.add(new FieldSchema("vo", JsonType.OBJECT, "TenantVO"));
|
||||
oldS.add(new FieldSchema("vo.dbName", JsonType.STRING, "String"));
|
||||
oldS.add(new FieldSchema("vo.linkList", JsonType.ARRAY, "List"));
|
||||
oldS.add(new FieldSchema("vo.linkList[]", JsonType.OBJECT, "TenantLinkModel"));
|
||||
oldS.add(new FieldSchema("vo.linkList[].id", JsonType.STRING, "String"));
|
||||
|
||||
TypeSchema newS = new TypeSchema("TenantVO");
|
||||
newS.add(new FieldSchema("dbName", JsonType.STRING, "String"));
|
||||
newS.add(new FieldSchema("linkList", JsonType.ARRAY, "List"));
|
||||
newS.add(new FieldSchema("linkList[]", JsonType.OBJECT, "TenantLinkModel"));
|
||||
newS.add(new FieldSchema("linkList[].id", JsonType.STRING, "String"));
|
||||
|
||||
List<SchemaChange> changes = new SchemaDiffer().diff(oldS, newS);
|
||||
List<ChangeType> types = changes.stream().map(SchemaChange::getChangeType).collect(Collectors.toList());
|
||||
|
||||
assertTrue(types.contains(ChangeType.WRAPPER_REMOVED), "应检测到包装层删除");
|
||||
assertTrue(types.contains(ChangeType.FIELD_PATH_MOVED), "应检测到字段上提迁移");
|
||||
assertTrue(types.stream().noneMatch(t -> t == ChangeType.FIELD_ADDED),
|
||||
"上提字段不应再被当成新增");
|
||||
assertTrue(types.stream().noneMatch(t -> t == ChangeType.FIELD_REMOVED),
|
||||
"上提字段不应再被当成删除");
|
||||
|
||||
SchemaChange wrapper = changes.stream()
|
||||
.filter(c -> c.getChangeType() == ChangeType.WRAPPER_REMOVED)
|
||||
.findFirst()
|
||||
.orElseThrow(IllegalStateException::new);
|
||||
assertEquals("vo", wrapper.getFieldPath());
|
||||
|
||||
long moved = changes.stream().filter(c -> c.getChangeType() == ChangeType.FIELD_PATH_MOVED).count();
|
||||
assertEquals(2, moved, "vo.dbName / vo.linkList[].id 均应上提");
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectsTypeChange() {
|
||||
TypeSchema oldS = new TypeSchema("A");
|
||||
|
||||
Reference in New Issue
Block a user