Search in sources :

Example 6 with RolePermission

use of com.webank.wedatasphere.qualitis.entity.RolePermission in project Qualitis by WeBankFinTech.

the class RolePermissionDaoTest method test.

@Test
@Transactional
public void test() {
    Permission savePermission = savePermission();
    Role saveRole = saveRole();
    // 保存是否成功
    RolePermission entity = new RolePermission();
    entity.setId(UuidGenerator.generate());
    entity.setPermission(savePermission);
    entity.setRole(saveRole);
    RolePermission saveEntity = dao.saveRolePermission(entity);
    assertNotNull(saveEntity.getId());
    // 总数量大于0
    long size = dao.countAll();
    assertTrue(size > 0);
    // 分页查询有结果
    List<RolePermission> datas = dao.findAllRolePermission(0, 5);
    assertTrue(datas.size() > 0);
    // 保存到数据库的对象是否和保存的值一致
    RolePermission findByIdEntity = dao.findByUuid(saveEntity.getId());
    assertNotNull(findByIdEntity);
    assertEquals(findByIdEntity.getPermission().getUrl(), saveEntity.getPermission().getUrl());
    assertEquals(findByIdEntity.getRole().getName(), saveEntity.getRole().getName());
    RolePermission findByRoleAndPermissionEntity = dao.findByRoleAndPermission(saveRole, savePermission);
    assertNotNull(findByRoleAndPermissionEntity);
    assertEquals(findByRoleAndPermissionEntity.getPermission().getUrl(), saveEntity.getPermission().getUrl());
    assertEquals(findByRoleAndPermissionEntity.getRole().getName(), saveEntity.getRole().getName());
    // 根据username查询的数据库对象是否和保存的值一致
    List<RolePermission> findByRoleEntity = dao.findByRole(saveRole);
    assertTrue(findByRoleEntity.size() > 0);
    assertEquals(findByRoleEntity.get(0).getPermission().getUrl(), saveEntity.getPermission().getUrl());
    // 根据username查询的数据库对象是否和保存的值一致
    List<RolePermission> findByPermissionEntity = dao.findByPermission(savePermission);
    assertTrue(findByPermissionEntity.size() > 0);
    assertEquals(findByPermissionEntity.get(0).getRole().getName(), saveEntity.getRole().getName());
    // 删除后,是否还能找到对象
    dao.deleteRolePermission(saveEntity);
    RolePermission deleteEntity = dao.findByUuid(saveEntity.getId());
    assertNull(deleteEntity);
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) Permission(com.webank.wedatasphere.qualitis.entity.Permission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RolePermission (com.webank.wedatasphere.qualitis.entity.RolePermission)6 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Permission (com.webank.wedatasphere.qualitis.entity.Permission)4 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)4 Role (com.webank.wedatasphere.qualitis.entity.Role)3 RolePermissionResponse (com.webank.wedatasphere.qualitis.response.RolePermissionResponse)2 UserSpecPermission (com.webank.wedatasphere.qualitis.entity.UserSpecPermission)1 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1