use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class TestAccount method testEditAccount.
public static void testEditAccount(GeneralDictAccessor service, AccountManageService accountService) {
User john = service.getById(TestUser.johnId, User.class);
assertNotNull(john);
AccountManageService.AccountInfo accountInfo = AccountManageService.AccountInfo.valueOf("account3", "", "description account.", "", TestUser.johnId, Arrays.asList(), true);
Account account3 = accountService.saveAccount(accountInfo);
assertEquals(3, service.count(Account.class));
assertNotNull(account3);
assertNotNull(account3.getId());
account3Id = account3.getId();
assertEquals("description account.", account3.getDesc());
assertEquals(john.getFullName(), account3.getName());
assertEquals(john, account3.getOwner());
accountInfo = AccountManageService.AccountInfo.valueOf(account3.getCode(), "", "new desc.", account3.getId(), TestUser.johnId, Arrays.asList(), false);
account3 = accountService.saveAccount(accountInfo);
assertEquals(2, service.count(Account.class));
assertEquals(2, service.count(Account.class, true));
assertEquals(3, service.count(Account.class, false));
assertNotNull(account3);
assertEquals("new desc.", account3.getDesc());
assertFalse(account3.isValid());
account3 = service.getByCode("account3", Account.class);
assertNotNull(account3);
assertEquals("new desc.", account3.getDesc());
assertFalse(account3.isValid());
accountInfo = AccountManageService.AccountInfo.valueOf(account3.getCode(), "", account3.getDesc(), account3.getId(), TestUser.johnId, Arrays.asList(), true);
accountService.saveAccount(accountInfo);
assertEquals(3, service.count(Account.class));
assertEquals(3, service.count(Account.class, true));
assertEquals(3, service.count(Account.class, false));
account3 = service.getById(account3Id, Account.class);
assertNotNull(account3);
assertTrue(account3.isValid());
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class TestDepartment method testDepartmentManager.
@Test
public void testDepartmentManager() {
GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
assertNotNull(service);
DepartmentManageService departService = context.getBean(DepartmentManageService.class);
assertNotNull(service);
UserManageService userManageService = context.getBean(UserManageService.class);
assertNotNull(userManageService);
try {
TestUser.testInsertUser(service, userManageService);
TestUser.testEditUser(service, userManageService);
testInsertDepartment(service, departService);
testEditDepartment(service, departService);
assertEquals(3, service.count(User.class));
assertEquals(3, service.count(Department.class));
Department depart1 = service.getById(depart1Id, Department.class);
assertNotNull(depart1);
assertTrue(depart1.isValid());
assertNull(depart1.getManager());
User john = service.getById(TestUser.johnId, User.class);
assertNotNull(john);
assertTrue(john.isValid());
DepartmentManageService.DepartInfo departInfo = DepartmentManageService.DepartInfo.valueOf(depart1.getCode(), depart1.getName(), depart1.getDesc(), depart1.getId(), john.getId(), Arrays.asList(), true);
depart1 = departService.saveDepartment(departInfo);
assertEquals(3, service.count(Department.class));
assertNotNull(depart1);
depart1 = service.getById(depart1Id, Department.class);
assertNotNull(depart1);
assertNotNull(depart1.getManager());
assertEquals(john, depart1.getManager());
departInfo = DepartmentManageService.DepartInfo.valueOf(depart1.getCode(), depart1.getName(), depart1.getDesc(), depart1.getId(), null, Arrays.asList(), true);
departService.saveDepartment(departInfo);
depart1 = service.getById(depart1Id, Department.class);
assertEquals(3, service.count(Department.class));
assertNull(depart1.getManager());
} catch (Exception ex) {
ex.printStackTrace();
fail(ex.getMessage());
}
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class TestUser method testDeleteUser.
private void testDeleteUser(GeneralDictAccessor service) {
List<User> users = service.list(User.class);
int userNum = users.size();
for (User user : users) {
service.remove(user);
assertEquals(service.count(User.class), --userNum);
assertEquals(service.count(User.class, false), users.size());
}
userNum = users.size();
for (User user : users) {
service.remove(user, false);
assertEquals(service.count(User.class, false), --userNum);
}
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class TestUser method testInsertUser.
public static void testInsertUser(GeneralDictAccessor service, UserManageService userService) throws ParseException {
long birthday = new SimpleDateFormat("yyyy-MM-dd").parse("1973-09-18").getTime();
UserManageService.UserInfo userInfo = UserManageService.UserInfo.valueOf("喜", "明", "彭", User.Sex.MALE, "", birthday, "", "manager", true, "This is John.Peng.");
User john = userService.saveUser(userInfo);
assertEquals(1, service.count(User.class));
johnId = john.getId();
assertNotNull(john);
assertNotNull(john.getId());
assertEquals(john.getFullName(), "彭 明喜");
assertEquals(john.getLastName(), "彭");
assertEquals(john.getStation(), "manager");
assertEquals(john.getSex(), User.Sex.MALE);
assertEquals(john.getDesc(), "This is John.Peng.");
assertEquals(birthday, john.getBirthday().getTime());
assertTrue(john.getCreatedTime() > 0);
assertTrue(john.getUpdatedTime() > 0);
assertEquals(john.getOperator(), "admin");
assertTrue(john.isValid());
assertEquals(service.count(User.class), 1);
john = service.getById(john.getId(), User.class);
assertNotNull(john);
assertNotNull(john.getId());
assertEquals(john.getFullName(), "彭 明喜");
assertEquals(john.getLastName(), "彭");
assertEquals(john.getStation(), "manager");
assertEquals(john.getSex(), User.Sex.MALE);
assertEquals(john.getDesc(), "This is John.Peng.");
assertEquals(birthday, john.getBirthday().getTime());
assertTrue(john.getCreatedTime() > 0);
assertTrue(john.getUpdatedTime() > 0);
assertEquals(john.getOperator(), "admin");
assertTrue(john.isValid());
assertEquals(service.count(User.class), 1);
assertEquals(service.count(User.class, true), 1);
assertEquals(service.count(User.class, false), 1);
userInfo = UserManageService.UserInfo.valueOf("joy", "", "peng", User.Sex.FEMALE);
User joy = userService.saveUser(userInfo);
joyId = joy.getId();
assertEquals(2, service.count(User.class));
assertNotNull(joy);
assertNotNull(joy.getId());
assertEquals(joy.getFullName(), "peng joy");
joy = service.getById(joy.getId(), User.class);
assertNotNull(joy);
assertNotNull(joy.getId());
assertEquals(joy.getFullName(), "peng joy");
}
use of org.mx.comps.rbac.dal.entity.User in project main by JohnPeng739.
the class TestUser method testUserDepartment.
@Test
public void testUserDepartment() {
GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
assertNotNull(service);
UserManageService userService = context.getBean(UserManageService.class);
assertNotNull(service);
DepartmentManageService departManageService = context.getBean(DepartmentManageService.class);
assertNotNull(departManageService);
try {
TestDepartment.testInsertDepartment(service, departManageService);
TestDepartment.testEditDepartment(service, departManageService);
testInsertUser(service, userService);
testEditUser(service, userService);
assertEquals(3, service.count(Department.class));
assertEquals(3, service.count(User.class));
User joy = service.getById(joyId, User.class);
assertNotNull(joy);
assertNull(joy.getDepartment());
User josh = service.getById(joshId, User.class);
assertNotNull(josh);
assertNull(josh.getDepartment());
Department depart1 = service.getById(TestDepartment.depart1Id, Department.class);
assertNotNull(depart1);
UserManageService.UserInfo userInfo = UserManageService.UserInfo.valueOf(joy.getFirstName(), joy.getMiddleName(), joy.getLastName(), joy.getSex(), joy.getId(), 0, depart1.getId(), joy.getStation(), joy.isValid(), joy.getDesc());
userService.saveUser(userInfo);
joy = service.getById(joyId, User.class);
assertNotNull(joy);
assertNotNull(joy.getDepartment());
assertEquals(depart1, joy.getDepartment());
depart1 = service.getById(TestDepartment.depart1Id, Department.class);
assertNotNull(depart1);
assertEquals(1, depart1.getEmployees().size());
assertEquals(new HashSet<>(Arrays.asList(joy)), depart1.getEmployees());
userInfo = UserManageService.UserInfo.valueOf(josh.getFirstName(), josh.getMiddleName(), josh.getLastName(), josh.getSex(), josh.getId(), 0, depart1.getId(), josh.getStation(), josh.isValid(), josh.getDesc());
userService.saveUser(userInfo);
josh = service.getById(joshId, User.class);
assertNotNull(josh);
assertNotNull(josh.getDepartment());
assertEquals(depart1, josh.getDepartment());
depart1 = service.getById(TestDepartment.depart1Id, Department.class);
assertNotNull(depart1);
assertEquals(2, depart1.getEmployees().size());
assertEquals(new HashSet<>(Arrays.asList(joy, josh)), depart1.getEmployees());
userInfo = UserManageService.UserInfo.valueOf(joy.getFirstName(), joy.getMiddleName(), joy.getLastName(), joy.getSex(), joy.getId(), 0, null, joy.getStation(), joy.isValid(), joy.getDesc());
userService.saveUser(userInfo);
joy = service.getById(joyId, User.class);
assertNotNull(joy);
assertNull(joy.getDepartment());
depart1 = service.getById(TestDepartment.depart1Id, Department.class);
assertNotNull(depart1);
assertEquals(1, depart1.getEmployees().size());
assertEquals(new HashSet<>(Arrays.asList(josh)), depart1.getEmployees());
} catch (Exception ex) {
ex.printStackTrace();
fail(ex.getMessage());
}
}
Aggregations