Search in sources :

Example 11 with UserManageService

use of org.mx.comps.rbac.service.UserManageService 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)

Example 12 with UserManageService

use of org.mx.comps.rbac.service.UserManageService in project main by JohnPeng739.

the class TestUser method testEditUser.

public static void testEditUser(GeneralDictAccessor service, UserManageService userService) {
    UserManageService.UserInfo userInfo = UserManageService.UserInfo.valueOf("josh", "", "peng", User.Sex.MALE, "", -1, "", "", true, "original desc.");
    User josh = userService.saveUser(userInfo);
    joshId = josh.getId();
    assertNotNull(josh);
    assertNotNull(josh.getId());
    assertEquals(service.count(User.class), 3);
    userInfo = UserManageService.UserInfo.valueOf(josh.getFirstName(), josh.getMiddleName(), josh.getLastName(), josh.getSex(), josh.getId(), -1, "", "", false, "new desc.");
    josh = userService.saveUser(userInfo);
    assertNotNull(josh);
    assertNotNull(josh.getId());
    assertEquals(service.count(User.class), 2);
    assertEquals(josh.getDesc(), "new desc.");
    assertEquals(service.count(User.class, true), 2);
    assertEquals(service.count(User.class, false), 3);
    userInfo = UserManageService.UserInfo.valueOf(josh.getFirstName(), josh.getMiddleName(), josh.getLastName(), josh.getSex(), josh.getId(), -1, "", "", true, josh.getDesc());
    userService.saveUser(userInfo);
    assertEquals(service.count(User.class), 3);
    assertEquals(service.count(User.class, true), 3);
    assertEquals(service.count(User.class, false), 3);
}
Also used : User(org.mx.comps.rbac.dal.entity.User) UserManageService(org.mx.comps.rbac.service.UserManageService)

Aggregations

UserManageService (org.mx.comps.rbac.service.UserManageService)12 User (org.mx.comps.rbac.dal.entity.User)11 Test (org.junit.Test)10 GeneralDictAccessor (org.mx.dal.service.GeneralDictAccessor)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 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 ParseException (java.text.ParseException)3 Role (org.mx.comps.rbac.dal.entity.Role)3 RoleManageService (org.mx.comps.rbac.service.RoleManageService)3 Department (org.mx.comps.rbac.dal.entity.Department)2 DepartmentManageService (org.mx.comps.rbac.service.DepartmentManageService)2 SimpleDateFormat (java.text.SimpleDateFormat)1 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 UserInterfaceSystemErrorException (org.mx.error.UserInterfaceSystemErrorException)1