Search in sources :

Example 1 with EntityBinderVO

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));
}
Also used : User(diboot.core.test.binder.entity.User) EntityBinderVO(diboot.core.test.binder.vo.EntityBinderVO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 User (diboot.core.test.binder.entity.User)1 EntityBinderVO (diboot.core.test.binder.vo.EntityBinderVO)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1