Search in sources :

Example 6 with Dictionary

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"));
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) CcCityInfo(diboot.core.test.binder.entity.CcCityInfo) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) BaseMapper(com.baomidou.mybatisplus.core.mapper.BaseMapper) SimpleDictionaryVO(diboot.core.test.binder.vo.SimpleDictionaryVO) EntityInfoCache(com.diboot.core.binding.parser.EntityInfoCache) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with Dictionary

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(), "离职");
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with Dictionary

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("请检查"));
    }
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) DictionaryVO(com.diboot.core.vo.DictionaryVO) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with Dictionary

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);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with Dictionary

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);
}
Also used : Dictionary(com.diboot.core.entity.Dictionary) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Dictionary (com.diboot.core.entity.Dictionary)27 Test (org.junit.Test)21 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)8 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)5 DictionaryVO (com.diboot.core.vo.DictionaryVO)5 Transactional (org.springframework.transaction.annotation.Transactional)5 BusinessException (com.diboot.core.exception.BusinessException)3 DictionaryService (com.diboot.core.service.DictionaryService)3 SimpleDictionaryVO (diboot.core.test.binder.vo.SimpleDictionaryVO)3 User (diboot.core.test.binder.entity.User)2 ArrayList (java.util.ArrayList)2 BaseMapper (com.baomidou.mybatisplus.core.mapper.BaseMapper)1 EntityInfoCache (com.diboot.core.binding.parser.EntityInfoCache)1 DynamicMemoryCacheManager (com.diboot.core.cache.DynamicMemoryCacheManager)1 IamResourcePermissionListVO (com.diboot.iam.vo.IamResourcePermissionListVO)1 IamMember (com.diboot.mobile.entity.IamMember)1 IamMemberService (com.diboot.mobile.service.IamMemberService)1 CcCityInfo (diboot.core.test.binder.entity.CcCityInfo)1 MulColJoinVO (diboot.core.test.binder.vo.MulColJoinVO)1