Search in sources :

Example 16 with GeneralDictAccessor

use of org.mx.dal.service.GeneralDictAccessor in project main by JohnPeng739.

the class TestRole method testRoleCrud.

@Test
public void testRoleCrud() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    RoleManageService roleService = context.getBean(RoleManageService.class);
    assertNotNull(service);
    try {
        assertEquals(0, service.count(Role.class));
        // insert
        testInsertRole(service, roleService);
        // edit
        testEditRole(service, roleService);
        // delete
        testDeleteRole(service);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Role(org.mx.comps.rbac.dal.entity.Role) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) RoleManageService(org.mx.comps.rbac.service.RoleManageService) Test(org.junit.Test)

Example 17 with GeneralDictAccessor

use of org.mx.dal.service.GeneralDictAccessor in project main by JohnPeng739.

the class TestUser method testAllocateAccount.

@Test
public void testAllocateAccount() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    UserManageService userService = context.getBean(UserManageService.class);
    assertNotNull(service);
    AccountManageService accountManageService = context.getBean(AccountManageService.class);
    assertNotNull(accountManageService);
    try {
        testInsertUser(service, userService);
        testEditUser(service, userService);
        assertEquals(3, service.count(User.class));
        User john = service.getById(joshId, User.class);
        assertNotNull(john);
        assertEquals(0, service.count(Account.class));
        // 用户不存在
        AccountManageService.AccountInfo accountInfo = AccountManageService.AccountInfo.valueOf("john---", "password", "desc", "", "asdfasd", Arrays.asList(), true);
        try {
            userService.allocateAccount(accountInfo);
            fail("here need a exception");
        } catch (UserInterfaceRbacErrorException ex) {
            assertEquals(UserInterfaceRbacErrorException.RbacErrors.USER_NOT_FOUND.getErrorCode(), ex.getErrorCode());
        }
        // 正常创建
        accountInfo = AccountManageService.AccountInfo.valueOf("John.Peng", "edmund!@#123", "desc", "", john.getId(), Arrays.asList(), true);
        Account account = userService.allocateAccount(accountInfo);
        assertNotNull(account);
        assertEquals(3, service.count(User.class));
        assertEquals(1, service.count(Account.class));
        account = service.getByCode("John.Peng", Account.class);
        assertNotNull(account);
        assertNotNull(account.getOwner());
        assertEquals(john, account.getOwner());
        assertEquals(DigestUtils.md5("edmund!@#123"), account.getPassword());
        assertEquals(john.getFullName(), account.getName());
        assertEquals("desc", account.getDesc());
        assertEquals(0, account.getRoles().size());
        // 账户已存在
        try {
            userService.allocateAccount(accountInfo);
            fail("here need a exception");
        } catch (UserInterfaceRbacErrorException ex) {
            assertEquals(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_HAS_EXIST.getErrorCode(), ex.getErrorCode());
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) User(org.mx.comps.rbac.dal.entity.User) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) AccountManageService(org.mx.comps.rbac.service.AccountManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) UserManageService(org.mx.comps.rbac.service.UserManageService) UserInterfaceRbacErrorException(org.mx.comps.rbac.error.UserInterfaceRbacErrorException) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)17 Test (org.junit.Test)16 User (org.mx.comps.rbac.dal.entity.User)10 UserManageService (org.mx.comps.rbac.service.UserManageService)10 UserInterfaceRbacErrorException (org.mx.comps.rbac.error.UserInterfaceRbacErrorException)8 Account (org.mx.comps.rbac.dal.entity.Account)7 AccountManageService (org.mx.comps.rbac.service.AccountManageService)7 Role (org.mx.comps.rbac.dal.entity.Role)6 RoleManageService (org.mx.comps.rbac.service.RoleManageService)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 ParseException (java.text.ParseException)3 Privilege (org.mx.comps.rbac.dal.entity.Privilege)3 DepartmentManageService (org.mx.comps.rbac.service.DepartmentManageService)3 Department (org.mx.comps.rbac.dal.entity.Department)2 Date (java.util.Date)1 Accredit (org.mx.comps.rbac.dal.entity.Accredit)1 LoginHistory (org.mx.comps.rbac.dal.entity.LoginHistory)1 AccreditManageService (org.mx.comps.rbac.service.AccreditManageService)1 GeneralAccessor (org.mx.dal.service.GeneralAccessor)1 SessionDataStore (org.mx.dal.session.SessionDataStore)1