use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class BaseServiceTest method testCache.
@Test
public void testCache() {
EntityInfoCache entityInfoCache = BindingCacheManager.getEntityInfoByClass(Dictionary.class);
Assert.assertTrue(entityInfoCache != null);
Assert.assertTrue(entityInfoCache.getDeletedColumn().equals("is_deleted"));
entityInfoCache = BindingCacheManager.getEntityInfoByClass(CcCityInfo.class);
Assert.assertTrue(entityInfoCache != null);
Assert.assertTrue(entityInfoCache.getIdColumn().equals("id"));
Assert.assertTrue(entityInfoCache.getDeletedColumn() == null);
BaseMapper baseMapper = BindingCacheManager.getMapperByTable("user_role");
Assert.assertTrue(baseMapper != null);
Class<?> entityClass = BindingCacheManager.getEntityClassBySimpleName("Dictionary");
Assert.assertTrue(entityClass != null && entityClass.getName().equals(Dictionary.class.getName()));
// 测试PropInfo缓存
QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", "GENDER").eq("item_value", "F");
Dictionary dictionary = dictionaryService.getSingleEntity(queryWrapper);
DictionaryVO dictionaryVO = RelationsBinder.convertAndBind(dictionary, DictionaryVO.class);
Assert.assertTrue(dictionaryVO.getPrimaryKeyVal().equals(dictionary.getId()));
Assert.assertTrue(ContextHelper.getIdFieldName(dictionaryVO.getClass()).equals("id"));
}
use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class BeanUtilsTest method testBindProp.
@Test
public void testBindProp() {
List<Dictionary> dictionaryList = new ArrayList<>();
for (long id = 1001; id < 1005; id++) {
Dictionary dictionary1 = new Dictionary();
dictionary1.setId(id);
dictionaryList.add(dictionary1);
}
Map<String, String> map = new HashMap<>();
map.put("1001", "在职");
map.put("1002", "在职");
map.put("1003", "离职");
BeanUtils.bindPropValueOfList(Dictionary::setItemName, dictionaryList, Dictionary::getId, map);
Assert.assertEquals(dictionaryList.get(0).getItemName(), "在职");
Assert.assertEquals(dictionaryList.get(2).getItemName(), "离职");
Map<Long, String> map2 = new HashMap<>();
map2.put(1001L, "在职");
map2.put(1002L, "在职");
map2.put(1003L, "离职");
BeanUtils.bindPropValueOfList("itemName", dictionaryList, "id", map2);
Assert.assertEquals(dictionaryList.get(0).getItemName(), "在职");
Assert.assertEquals(dictionaryList.get(2).getItemName(), "离职");
}
use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class BeanUtilsTest method testBuildTree.
@Test
public void testBuildTree() {
List<Dictionary> dictionaryList = new ArrayList<>();
for (long id = 1001; id <= 1005; id++) {
Dictionary dictionary1 = new Dictionary();
dictionary1.setId(id);
dictionary1.setParentId(1L);
dictionaryList.add(dictionary1);
}
Dictionary parent = new Dictionary();
parent.setId(1L);
parent.setParentId(0L);
dictionaryList.add(parent);
// 正常数据
List<DictionaryVO> list = BeanUtils.convertList(dictionaryList, DictionaryVO.class);
list = BeanUtils.buildTree(list);
Assert.assertEquals(list.size(), 1);
Assert.assertEquals(list.get(0).getChildren().size(), 5);
list = BeanUtils.convertList(dictionaryList, DictionaryVO.class);
list = BeanUtils.buildTree(list, 0, "parentId", "children");
Assert.assertEquals(list.size(), 1);
Assert.assertEquals(list.get(0).getChildren().size(), 5);
// 异常数据告警
Dictionary dict2 = new Dictionary();
dict2.setId(1L);
dict2.setParentId(1L);
dictionaryList.add(dict2);
list = BeanUtils.convertList(dictionaryList, DictionaryVO.class);
try {
list = BeanUtils.buildTree(list);
Assert.assertTrue(false);
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("请检查"));
}
}
use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class BeanUtilsTest method testLambdaDistinct.
@Test
public void testLambdaDistinct() {
List<Dictionary> dictionaryList = new ArrayList<>();
for (long id = 1001; id <= 1005; id++) {
Dictionary dictionary1 = new Dictionary();
dictionary1.setId(id);
dictionaryList.add(dictionary1);
}
for (long id = 1003; id <= 1007; id++) {
Dictionary dictionary1 = new Dictionary();
dictionary1.setId(id);
dictionaryList.add(dictionary1);
}
List<Dictionary> dictionaryList2 = BeanUtils.distinctByKey(dictionaryList, Dictionary::getId);
Assert.assertEquals(dictionaryList2.size(), 7);
}
use of com.diboot.core.entity.Dictionary in project diboot by dibo-software.
the class BeanUtilsTest method testCollect.
@Test
public void testCollect() {
List<Dictionary> dictionaryList = new ArrayList<>();
for (long id = 1001; id < 1005; id++) {
Dictionary dictionary1 = new Dictionary();
dictionary1.setId(id);
dictionaryList.add(dictionary1);
}
List<Long> metaIdList = BeanUtils.collectToList(dictionaryList, Dictionary::getId);
Assert.assertTrue(metaIdList.size() == 4);
}
Aggregations