Search in sources :

Example 1 with User

use of diboot.core.test.binder.entity.User in project diboot by dibo-software.

the class TestDictBinder method testBinder.

@Test
public void testBinder() {
    // 加载测试数据
    LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(User::getId, 1001L, 1002L);
    List<User> userList = userService.getEntityList(queryWrapper);
    // 自动绑定
    List<UserVO> voList = Binder.convertAndBindRelations(userList, UserVO.class);
    // 验证绑定结果
    Assert.assertTrue(V.notEmpty(voList));
    for (UserVO vo : voList) {
        // 验证直接关联和通过中间表间接关联的绑定
        Assert.assertNotNull(vo.getGenderLabel());
        System.out.println(JSON.stringify(vo));
    }
    // 单个entity接口测试
    UserVO singleVO = BeanUtils.convert(userList.get(1), UserVO.class);
    Binder.bindRelations(singleVO);
    // 验证直接关联和通过中间表间接关联的绑定
    Assert.assertNotNull(singleVO.getGenderLabel());
    System.out.println(JSON.stringify(singleVO));
}
Also used : User(diboot.core.test.binder.entity.User) UserVO(diboot.core.test.binder.vo.UserVO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with User

use of diboot.core.test.binder.entity.User in project diboot by dibo-software.

the class TestEntityListBinder method testComplexBinder.

/**
 * 验证通过中间表间接关联的绑定
 */
@Test
public void testComplexBinder() {
    // 加载测试数据
    LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(User::getId, 1001L, 1002L);
    List<User> userList = userService.getEntityList(queryWrapper);
    // 自动绑定
    List<EntityListComplexVO> voList = Binder.convertAndBindRelations(userList, EntityListComplexVO.class);
    // 验证绑定结果
    Assert.assertTrue(V.notEmpty(voList));
    for (EntityListComplexVO vo : voList) {
        // 验证通过中间表间接关联的绑定
        Assert.assertTrue(V.notEmpty(vo.getRoleList()));
        System.out.println(JSON.stringify(vo));
    }
}
Also used : User(diboot.core.test.binder.entity.User) EntityListComplexVO(diboot.core.test.binder.vo.EntityListComplexVO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with User

use of diboot.core.test.binder.entity.User in project diboot by dibo-software.

the class TestJoinQuery method testDynamicSqlQueryWithMiddleTable.

/**
 * 测试有中间表的动态sql join
 */
@Test
public void testDynamicSqlQueryWithMiddleTable() {
    // 初始化DTO,测试不涉及关联的情况
    UserDTO dto = new UserDTO();
    dto.setDeptName("研发组");
    dto.setDeptId(10002L);
    // builder直接查询,不分页 3条结果
    List<User> builderResultList = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(User.class);
    Assert.assertTrue(builderResultList.size() == 2);
    dto.setOrgName("苏州帝博");
    builderResultList = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(User.class);
    Assert.assertTrue(builderResultList.size() == 2);
    dto.setOrgName("");
    builderResultList = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(User.class);
    Assert.assertTrue(builderResultList.size() == 2);
    List<String> roleCodes = new ArrayList<>();
    roleCodes.add("ADMIN");
    roleCodes.add("OTHER");
    dto.setRoleCodes(roleCodes);
    builderResultList = QueryBuilder.toDynamicJoinQueryWrapper(dto).queryList(User.class);
    Assert.assertTrue(builderResultList.size() == 1);
}
Also used : User(diboot.core.test.binder.entity.User) UserDTO(diboot.core.test.binder.dto.UserDTO) ArrayList(java.util.ArrayList) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with User

use of diboot.core.test.binder.entity.User in project diboot by dibo-software.

the class BaseServiceTest method testGet.

@Test
public void testGet() {
    // 查询总数
    long count = dictionaryService.getEntityListCount(null);
    Assert.assertTrue(count > 0);
    // 查询list
    List<Dictionary> dictionaryList = dictionaryService.getEntityList(null);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    Assert.assertTrue(dictionaryList.size() == count);
    // 第一页数据
    List<Dictionary> pageList = dictionaryService.getEntityList(null, new Pagination());
    Assert.assertTrue(pageList.size() > 0 && pageList.size() <= BaseConfig.getPageSize());
    // 查询单个记录
    Long id = dictionaryList.get(0).getId();
    Dictionary first = dictionaryService.getEntity(id);
    Assert.assertTrue(first != null);
    // 只查询第一条记录对应type类型的
    LambdaQueryWrapper<Dictionary> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Dictionary::getType, first.getType());
    dictionaryList = dictionaryService.getEntityList(queryWrapper);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    // 结果type值一致
    dictionaryList.stream().forEach(m -> {
        Assert.assertTrue(m.getType().equals(first.getType()));
    });
    // 根据id集合去批量查询
    List<Long> ids = BeanUtils.collectIdToList(dictionaryList);
    dictionaryList = dictionaryService.getEntityListByIds(ids);
    Assert.assertTrue(V.notEmpty(dictionaryList));
    // 获取map
    List<Map<String, Object>> mapList = dictionaryService.getMapList(null, new Pagination());
    Assert.assertTrue(mapList.size() > 0 && mapList.size() <= BaseConfig.getPageSize());
    List<Long> userIds = Arrays.asList(1001L, 1002L);
    Map<Long, String> id2NameMap = userService.getId2NameMap(userIds, User::getUsername);
    Assert.assertTrue(id2NameMap != null);
    Assert.assertTrue(id2NameMap.get(1001) != null);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) User(diboot.core.test.binder.entity.User) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with User

use of diboot.core.test.binder.entity.User in project diboot by dibo-software.

the class BeanUtilsTest method testDateCopy.

@Test
public void testDateCopy() {
    // User user1 = new User().setUsername("test").setGender("").setBirthdate(new Date()).setLocalDatetime(LocalDate.now());
    User user2 = new User();
    Map<String, Object> map = new HashMap<>();
    map.put("username", "test");
    map.put("birthdate", "1980-10-12");
    map.put("localDatetime", new Date());
    BeanUtils.bindProperties(user2, map);
    Assert.assertTrue(user2.getLocalDatetime() != null);
    System.out.println(JSON.stringify(user2));
}
Also used : User(diboot.core.test.binder.entity.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (diboot.core.test.binder.entity.User)10 Test (org.junit.Test)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)5 Dictionary (com.diboot.core.entity.Dictionary)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 JsonResult (com.diboot.core.vo.JsonResult)1 Pagination (com.diboot.core.vo.Pagination)1 PagingJsonResult (com.diboot.core.vo.PagingJsonResult)1 UserDTO (diboot.core.test.binder.dto.UserDTO)1 Department (diboot.core.test.binder.entity.Department)1 EntityBinderVO (diboot.core.test.binder.vo.EntityBinderVO)1 EntityListComplexVO (diboot.core.test.binder.vo.EntityListComplexVO)1 UserVO (diboot.core.test.binder.vo.UserVO)1 List (java.util.List)1