Search in sources :

Example 1 with EntityListSimpleVO

use of diboot.core.test.binder.vo.EntityListSimpleVO in project diboot by dibo-software.

the class TestEntityListBinder method testSimpleBinder.

/**
 * 验证直接关联的绑定
 */
@Test
public void testSimpleBinder() {
    // 加载测试数据
    LambdaQueryWrapper<Department> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(Department::getId, 10001L, 10003L);
    List<Department> entityList = departmentService.list(queryWrapper);
    // 自动绑定
    List<EntityListSimpleVO> voList = Binder.convertAndBindRelations(entityList, EntityListSimpleVO.class);
    // 验证绑定结果
    Assert.assertTrue(V.notEmpty(voList));
    for (EntityListSimpleVO vo : voList) {
        // 验证直接关联的绑定
        Assert.assertTrue(V.notEmpty(vo.getChildren()));
        System.out.println(JSON.stringify(vo));
        Assert.assertTrue(V.notEmpty(vo.getChildrenNames()));
        for (int i = 0; i < vo.getChildren().size(); i++) {
            Department dept = vo.getChildren().get(i);
            Assert.assertTrue(dept.getName().equals(vo.getChildrenNames().get(i)));
        }
    }
}
Also used : Department(diboot.core.test.binder.entity.Department) EntityListSimpleVO(diboot.core.test.binder.vo.EntityListSimpleVO) 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 Department (diboot.core.test.binder.entity.Department)1 EntityListSimpleVO (diboot.core.test.binder.vo.EntityListSimpleVO)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1