Search in sources :

Example 1 with GeneralDictAccessor

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

the class TestAccount method testChangePassword.

@Test
public void testChangePassword() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    AccountManageService accountService = context.getBean(AccountManageService.class);
    assertNotNull(service);
    UserManageService userManageService = context.getBean(UserManageService.class);
    assertNotNull(userManageService);
    try {
        TestUser.testInsertUser(service, userManageService);
        TestUser.testEditUser(service, userManageService);
        assertEquals(3, service.count(User.class));
        testInsertAccount(service, accountService);
        testEditAccount(service, accountService);
        assertEquals(3, service.count(Account.class));
        Account account1 = service.getById(account1Id, Account.class);
        assertNotNull(account1);
        assertEquals(DigestUtils.md5("password"), account1.getPassword());
        accountService.changePassword(account1.getId(), "password", "new password");
        account1 = service.getById(account1Id, Account.class);
        assertNotNull(account1);
        assertEquals(DigestUtils.md5("new password"), account1.getPassword());
        Account account3 = service.getById(account3Id, Account.class);
        assertNotNull(account3);
        assertEquals(DigestUtils.md5("ds110119"), account3.getPassword());
        accountService.changePassword(account3.getId(), "ds110119", "new password");
        account3 = service.getById(account3Id, Account.class);
        assertNotNull(account3);
        assertEquals(DigestUtils.md5("new password"), account3.getPassword());
    } 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) 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) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 2 with GeneralDictAccessor

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

the class TestAccount method testAccountCrud.

@Test
public void testAccountCrud() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    AccountManageService accountService = context.getBean(AccountManageService.class);
    assertNotNull(service);
    UserManageService userManageService = context.getBean(UserManageService.class);
    assertNotNull(userManageService);
    try {
        TestUser.testInsertUser(service, userManageService);
        TestUser.testEditUser(service, userManageService);
        assertEquals(0, service.count(Account.class));
        // insert
        testInsertAccount(service, accountService);
        // edit
        testEditAccount(service, accountService);
        // delete
        testDeleteAccount(service);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : Account(org.mx.comps.rbac.dal.entity.Account) 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) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 3 with GeneralDictAccessor

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

the class TestAccount method testLoginAndLogout.

@Test
public void testLoginAndLogout() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    AccountManageService accountService = context.getBean(AccountManageService.class);
    assertNotNull(service);
    UserManageService userManageService = context.getBean(UserManageService.class);
    assertNotNull(userManageService);
    try {
        TestUser.testInsertUser(service, userManageService);
        TestUser.testEditUser(service, userManageService);
        assertEquals(3, service.count(User.class));
        testInsertAccount(service, accountService);
        testEditAccount(service, accountService);
        assertEquals(3, service.count(Account.class));
        // 测试正常流程
        LoginHistory login = accountService.login("account1", "password", false);
        assertNotNull(login);
        Account account1 = service.getById(account1Id, Account.class);
        assertNotNull(account1);
        assertEquals(account1, login.getAccount());
        // 测试用户重复登录
        login = accountService.login("account1", "password", true);
        assertNotNull(login);
        assertEquals(account1, login.getAccount());
        try {
            accountService.login("account1", "password", false);
        } catch (UserInterfaceRbacErrorException ex) {
            assertEquals(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_ALREADY_LOGINED.getErrorCode(), ex.getErrorCode());
        }
        // 测试正常登出
        login = accountService.logout(account1.getId());
        assertNotNull(login);
        assertEquals(account1, login.getAccount());
        // 测试用户不存在
        try {
            accountService.login("abc", "adasd", false);
        } catch (UserInterfaceRbacErrorException ex) {
            assertEquals(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_NOT_FOUND.getErrorMessage(), ex.getErrorMessage());
        }
        // 测试密码不正确
        try {
            accountService.login("account1", "adfasd", false);
        } catch (UserInterfaceRbacErrorException ex) {
            assertEquals(UserInterfaceRbacErrorException.RbacErrors.ACCOUNT_PASSWORD_NOT_MATCHED.getErrorMessage(), ex.getErrorMessage());
        }
    } 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) LoginHistory(org.mx.comps.rbac.dal.entity.LoginHistory) 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) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Example 4 with GeneralDictAccessor

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

the class TestDepartment method testDepartmentCrud.

@Test
public void testDepartmentCrud() {
    GeneralDictAccessor service = context.getBean("generalDictAccessor", GeneralDictAccessor.class);
    assertNotNull(service);
    DepartmentManageService departService = context.getBean(DepartmentManageService.class);
    assertNotNull(service);
    try {
        assertEquals(service.count(User.class), 0);
        // insert
        testInsertDepartment(service, departService);
        // edit
        testEditDepartment(service, departService);
        // delete
        testDeleteDepartment(service);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail(ex.getMessage());
    }
}
Also used : User(org.mx.comps.rbac.dal.entity.User) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) Test(org.junit.Test)

Example 5 with GeneralDictAccessor

use of org.mx.dal.service.GeneralDictAccessor 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());
    }
}
Also used : Department(org.mx.comps.rbac.dal.entity.Department) User(org.mx.comps.rbac.dal.entity.User) DepartmentManageService(org.mx.comps.rbac.service.DepartmentManageService) GeneralDictAccessor(org.mx.dal.service.GeneralDictAccessor) UserManageService(org.mx.comps.rbac.service.UserManageService) 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