use of diboot.core.test.binder.vo.EntityBinderVO in project diboot by dibo-software.
the class TestEntityBinder method testBinder.
@Test
public void testBinder() {
// 加载测试数据
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(User::getId, 1001L, 1002L);
List<User> userList = userService.getEntityList(queryWrapper);
// 自动绑定
List<EntityBinderVO> voList = Binder.convertAndBindRelations(userList, EntityBinderVO.class);
// 验证绑定结果
Assert.assertTrue(V.notEmpty(voList));
for (EntityBinderVO vo : voList) {
// 验证直接关联和通过中间表间接关联的绑定
Assert.assertEquals(vo.getDepartmentId(), vo.getDepartment().getId());
Assert.assertNotNull(vo.getDepartment().getOrgId());
// 测试绑定VO
Assert.assertNotNull(vo.getOrganizationVO());
System.out.println(JSON.stringify(vo.getOrganizationVO()));
System.out.println(JSON.stringify(vo));
}
// 单个entity接口测试
EntityBinderVO singleVO = BeanUtils.convert(userList.get(0), EntityBinderVO.class);
Binder.bindRelations(singleVO);
// 验证直接关联和通过中间表间接关联的绑定
Assert.assertEquals(singleVO.getDepartmentId(), singleVO.getDepartment().getId());
Assert.assertNotNull(singleVO.getDepartment().getOrgId());
// 测试绑定VO
Assert.assertNotNull(singleVO.getOrganizationVO());
System.out.println(JSON.stringify(singleVO.getOrganizationVO()));
System.out.println(JSON.stringify(singleVO));
}
Aggregations