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());
}
}
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);
}
Aggregations