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));
}
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));
}
}
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);
}
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);
}
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));
}
Aggregations