|
@@ -1,218 +1,219 @@
|
|
|
-package com.mooctest.crowd.domain.domainobject;
|
|
|
-
|
|
|
-import com.mooctest.crowd.domain.command.AccountCommand;
|
|
|
-import com.mooctest.crowd.domain.command.LoginCommand;
|
|
|
-import com.mooctest.crowd.domain.command.ModifyPasswordCommand;
|
|
|
-import com.mooctest.crowd.domain.exception.AccountNotExistException;
|
|
|
-import com.mooctest.crowd.domain.exception.PasswordErrorException;
|
|
|
-import com.mooctest.crowd.domain.repository.AccountUTRepo;
|
|
|
-import com.mooctest.crowd.domain.repository.IAccountRepo;
|
|
|
-import org.junit.Test;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import static org.junit.Assert.*;
|
|
|
-
|
|
|
-/**
|
|
|
- * @Author: xuexb
|
|
|
- * @Date: 2019.7.5 14:25
|
|
|
- */
|
|
|
-public class AccountTest {
|
|
|
-
|
|
|
- private AccountUTRepo accountUTRepo = new AccountUTRepo();
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_true_when_login_success() throws AccountNotExistException, PasswordErrorException {
|
|
|
- // arrange
|
|
|
- LoginCommand loginCommand = this.getSuccessLoginCommand();
|
|
|
- Account account = this.getSuccessAccount();
|
|
|
- // action
|
|
|
- boolean success = account.login(loginCommand);
|
|
|
- // assert
|
|
|
- assertTrue(success);
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = AccountNotExistException.class)
|
|
|
- public void should_throw_when_account_not_exist() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- LoginCommand loginCommand = new LoginCommand();
|
|
|
- loginCommand.setMobileNum("NOT_EXIST");
|
|
|
- IAccountRepo IAccountRepo = new AccountUTRepo();
|
|
|
- Account account = IAccountRepo.getByMobileNum(loginCommand.getMobileNum());
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = PasswordErrorException.class)
|
|
|
- public void should_throw_exception_when_password_error() throws PasswordErrorException, AccountNotExistException {
|
|
|
- // arrange
|
|
|
- LoginCommand loginCommand = new LoginCommand();
|
|
|
- loginCommand.setMobileNum("EXIST_ACCOUNT");
|
|
|
- loginCommand.setPassword("ERROR_PASSWORD");
|
|
|
- IAccountRepo IAccountRepo = new AccountUTRepo();
|
|
|
- Account account = IAccountRepo.getByMobileNum(loginCommand.getMobileNum());
|
|
|
- // assert
|
|
|
- account.login(loginCommand);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_update_password_when_modify_password() throws AccountNotExistException, PasswordErrorException {
|
|
|
- // arrange
|
|
|
- ModifyPasswordCommand modifyPasswordCommand = new ModifyPasswordCommand();
|
|
|
- modifyPasswordCommand.setMobileNum("EXIST_ACCOUNT");
|
|
|
- modifyPasswordCommand.setOldPassword("PASSWORD");
|
|
|
- modifyPasswordCommand.setNewPassword("654321");
|
|
|
-
|
|
|
- Account account = accountUTRepo.getByMobileNum(modifyPasswordCommand.getMobileNum());
|
|
|
- // action
|
|
|
- boolean result = account.modifyPassword(modifyPasswordCommand);
|
|
|
- // assert
|
|
|
- assertTrue(result);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_permissions_when_account_login_success() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Account account = this.getSuccessAccount();
|
|
|
- // action
|
|
|
- List<Permission> permissions = account.distributePermission();
|
|
|
- // assert
|
|
|
- assertEquals(permissions.get(0).getId(), new Long(1));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_roles_when_account_login_success() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Account account = this.getSuccessAccount();
|
|
|
- // action
|
|
|
- List<Role> roles = account.distributeRole();
|
|
|
- // assert
|
|
|
- assertEquals(roles.get(0).getId(), new Long(1));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_account_when_view_by_account_id() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- AccountCommand accountCommand = new AccountCommand();
|
|
|
- accountCommand.setId(123L);
|
|
|
-
|
|
|
- // action
|
|
|
- Account accountUTRepoByID = accountUTRepo.getByID(accountCommand.getId());
|
|
|
- // assert
|
|
|
- assertEquals(accountUTRepoByID.getId(), accountCommand.getId());
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = AccountNotExistException.class)
|
|
|
- public void should_throw_when_view_account_not_exist_by_account_id() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- AccountCommand accountCommand = new AccountCommand();
|
|
|
- accountCommand.setId(111L);
|
|
|
- // action
|
|
|
- accountUTRepo.getByID(accountCommand.getId());
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_account_list_when_view_by_account_ids() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Long[] ids = {123L};
|
|
|
- // action
|
|
|
- List<Account> accountList = accountUTRepo.getByIDList(ids);
|
|
|
- // assert
|
|
|
- assertEquals(accountList.get(0).getId(), ids[0]);
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = AccountNotExistException.class)
|
|
|
- public void should_throw_when_view_not_exist_account_by_account_ids() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Long[] ids = {123L,111L};
|
|
|
-
|
|
|
- // action
|
|
|
- accountUTRepo.getByIDList(ids);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_false_when_add_exist_account() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Account account = this.createCorrectAccount();
|
|
|
- // action
|
|
|
- boolean result = accountUTRepo.addAccount(account);
|
|
|
- // assert
|
|
|
- assertFalse(result);
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = AccountNotExistException.class)
|
|
|
- public void should_throw_when_add_account_success() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Account account = this.createDiscorrectAccount();
|
|
|
- // action
|
|
|
- accountUTRepo.addAccount(account);
|
|
|
- }
|
|
|
- @Test
|
|
|
- public void should_return_true_when_remove_account_success() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Account account = this.createCorrectAccount();
|
|
|
- // action
|
|
|
- boolean result = accountUTRepo.removeAccount(account);
|
|
|
- // assert
|
|
|
- assertTrue(result);
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = AccountNotExistException.class)
|
|
|
- public void should_throw_when_remove_not_exist_account() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Account account = this.createDiscorrectAccount();
|
|
|
- // action
|
|
|
- accountUTRepo.removeAccount(account);
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void should_return_true_when_update_account_success() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Account account = this.createCorrectAccount();
|
|
|
- account.setPassword("UPDATE_PASSWORD");
|
|
|
- // action
|
|
|
- Account updateAccount = accountUTRepo.updateAccount(account);
|
|
|
- // assert
|
|
|
- assertEquals(updateAccount.getPassword(),account.getPassword());
|
|
|
- }
|
|
|
-
|
|
|
- @Test(expected = AccountNotExistException.class)
|
|
|
- public void should_throw_when_update_not_exist_account() throws AccountNotExistException {
|
|
|
- // arrange
|
|
|
- Account account = this.createDiscorrectAccount();
|
|
|
- // action
|
|
|
- accountUTRepo.updateAccount(account);
|
|
|
- }
|
|
|
-
|
|
|
- private LoginCommand getSuccessLoginCommand() {
|
|
|
- LoginCommand loginCommand = new LoginCommand();
|
|
|
- loginCommand.setMobileNum("EXIST_ACCOUNT");
|
|
|
- loginCommand.setPassword("PASSWORD");
|
|
|
- loginCommand.setCheckCode("123456");
|
|
|
- return loginCommand;
|
|
|
- }
|
|
|
-
|
|
|
- private Account getSuccessAccount() throws AccountNotExistException {
|
|
|
- LoginCommand loginCommand = getSuccessLoginCommand();
|
|
|
- IAccountRepo IAccountRepo = new AccountUTRepo();
|
|
|
- return IAccountRepo.getByMobileNum(loginCommand.getMobileNum());
|
|
|
- }
|
|
|
-
|
|
|
- private Account createCorrectAccount(){
|
|
|
- AccountCommand accountCommand = new AccountCommand();
|
|
|
- accountCommand.setMobileNum("EXIST_ACCOUNT");
|
|
|
- accountCommand.setPassword("PASSWORD");
|
|
|
- Account account = new Account();
|
|
|
- account.setMobileNum(accountCommand.getMobileNum());
|
|
|
- account.setPassword(accountCommand.getPassword());
|
|
|
- return account;
|
|
|
- }
|
|
|
-
|
|
|
- private Account createDiscorrectAccount(){
|
|
|
- AccountCommand accountCommand = new AccountCommand();
|
|
|
- accountCommand.setMobileNum("NOT_EXIST_ACCOUNT");
|
|
|
- accountCommand.setPassword("PASSWORD");
|
|
|
- Account account = new Account();
|
|
|
- account.setMobileNum(accountCommand.getMobileNum());
|
|
|
- account.setPassword(accountCommand.getPassword());
|
|
|
- return account;
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.mooctest.crowd.domain.domainobject;
|
|
|
+//
|
|
|
+//import com.mooctest.crowd.domain.command.AccountCommand;
|
|
|
+//import com.mooctest.crowd.domain.command.LoginCommand;
|
|
|
+//import com.mooctest.crowd.domain.command.ModifyPasswordCommand;
|
|
|
+//import com.mooctest.crowd.domain.exception.AccountNotExistException;
|
|
|
+//import com.mooctest.crowd.domain.exception.PasswordErrorException;
|
|
|
+//import com.mooctest.crowd.domain.repository.AccountUTRepo;
|
|
|
+//import com.mooctest.crowd.domain.repository.IAccountRepo;
|
|
|
+//import org.junit.Test;
|
|
|
+//
|
|
|
+//import java.util.List;
|
|
|
+//
|
|
|
+//import static org.junit.Assert.assertEquals;
|
|
|
+//import static org.junit.Assert.assertTrue;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @Author: xuexb
|
|
|
+// * @Date: 2019.7.5 14:25
|
|
|
+// */
|
|
|
+//public class AccountTest {
|
|
|
+//
|
|
|
+// private AccountUTRepo accountUTRepo = new AccountUTRepo();
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_true_when_login_success() throws AccountNotExistException, PasswordErrorException {
|
|
|
+// // arrange
|
|
|
+// LoginCommand loginCommand = this.getSuccessLoginCommand();
|
|
|
+// Account account = this.getSuccessAccount();
|
|
|
+// // action
|
|
|
+// boolean success = account.login(loginCommand);
|
|
|
+// // assert
|
|
|
+// assertTrue(success);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = AccountNotExistException.class)
|
|
|
+// public void should_throw_when_account_not_exist() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// LoginCommand loginCommand = new LoginCommand();
|
|
|
+// loginCommand.setMobileNum("NOT_EXIST");
|
|
|
+// IAccountRepo IAccountRepo = new AccountUTRepo();
|
|
|
+// Account account = IAccountRepo.getByMobileNum(loginCommand.getMobileNum());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = PasswordErrorException.class)
|
|
|
+// public void should_throw_exception_when_password_error() throws PasswordErrorException, AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// LoginCommand loginCommand = new LoginCommand();
|
|
|
+// loginCommand.setMobileNum("EXIST_ACCOUNT");
|
|
|
+// loginCommand.setPassword("ERROR_PASSWORD");
|
|
|
+// IAccountRepo IAccountRepo = new AccountUTRepo();
|
|
|
+// Account account = IAccountRepo.getByMobileNum(loginCommand.getMobileNum());
|
|
|
+// // assert
|
|
|
+// account.login(loginCommand);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_update_password_when_modify_password() throws AccountNotExistException, PasswordErrorException {
|
|
|
+// // arrange
|
|
|
+// ModifyPasswordCommand modifyPasswordCommand = new ModifyPasswordCommand();
|
|
|
+// modifyPasswordCommand.setMobileNum("EXIST_ACCOUNT");
|
|
|
+// modifyPasswordCommand.setOldPassword("PASSWORD");
|
|
|
+// modifyPasswordCommand.setNewPassword("654321");
|
|
|
+//
|
|
|
+// Account account = accountUTRepo.getByMobileNum(modifyPasswordCommand.getMobileNum());
|
|
|
+// // action
|
|
|
+// boolean result = account.modifyPassword(modifyPasswordCommand);
|
|
|
+// // assert
|
|
|
+// assertTrue(result);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_permissions_when_account_login_success() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// Account account = this.getSuccessAccount();
|
|
|
+// // action
|
|
|
+// List<Permission> permissions = account.distributePermission();
|
|
|
+// // assert
|
|
|
+// assertEquals(permissions.get(0).getId(), new Long(1));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_roles_when_account_login_success() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// Account account = this.getSuccessAccount();
|
|
|
+// // action
|
|
|
+// List<Role> roles = account.distributeRole();
|
|
|
+// // assert
|
|
|
+// assertEquals(roles.get(0).getId(), new Long(1));
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_account_when_view_by_account_id() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// AccountCommand accountCommand = new AccountCommand();
|
|
|
+// accountCommand.setId(123L);
|
|
|
+//
|
|
|
+// // action
|
|
|
+// Account accountUTRepoByID = accountUTRepo.getByID(accountCommand.getId());
|
|
|
+// // assert
|
|
|
+// assertEquals(accountUTRepoByID.getId(), accountCommand.getId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = AccountNotExistException.class)
|
|
|
+// public void should_throw_when_view_account_not_exist_by_account_id() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// AccountCommand accountCommand = new AccountCommand();
|
|
|
+// accountCommand.setId(111L);
|
|
|
+// // action
|
|
|
+// accountUTRepo.getByID(accountCommand.getId());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_account_list_when_view_by_account_ids() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// Long[] ids = {123L};
|
|
|
+// // action
|
|
|
+// List<Account> accountList = accountUTRepo.getByIDList(ids);
|
|
|
+// // assert
|
|
|
+// assertEquals(accountList.get(0).getId(), ids[0]);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = AccountNotExistException.class)
|
|
|
+// public void should_throw_when_view_not_exist_account_by_account_ids() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// Long[] ids = {123L,111L};
|
|
|
+//
|
|
|
+// // action
|
|
|
+// accountUTRepo.getByIDList(ids);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_false_when_add_exist_account(){
|
|
|
+// // arrange
|
|
|
+// Account account = this.createCorrectAccount();
|
|
|
+// // action
|
|
|
+// Account resultAccount = accountUTRepo.addAccount(account);
|
|
|
+// // assert
|
|
|
+// assertEquals(resultAccount.getMobileNum(),account.getMobileNum());
|
|
|
+// }
|
|
|
+//
|
|
|
+//// @Test(expected = AccountNotExistException.class)
|
|
|
+//// public void should_throw_when_add_account_success() throws AccountNotExistException {
|
|
|
+//// // arrange
|
|
|
+//// Account account = this.createDiscorrectAccount();
|
|
|
+//// // action
|
|
|
+//// accountUTRepo.addAccount(account);
|
|
|
+//// }
|
|
|
+// @Test
|
|
|
+// public void should_return_true_when_remove_account_success() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// Account account = this.createCorrectAccount();
|
|
|
+// // action
|
|
|
+// boolean result = accountUTRepo.removeAccount(account);
|
|
|
+// // assert
|
|
|
+// assertTrue(result);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = AccountNotExistException.class)
|
|
|
+// public void should_throw_when_remove_not_exist_account() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// Account account = this.createDiscorrectAccount();
|
|
|
+// // action
|
|
|
+// accountUTRepo.removeAccount(account);
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test
|
|
|
+// public void should_return_true_when_update_account_success() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// Account account = this.createCorrectAccount();
|
|
|
+// account.setPassword("UPDATE_PASSWORD");
|
|
|
+// // action
|
|
|
+// Account updateAccount = accountUTRepo.updateAccount(account);
|
|
|
+// // assert
|
|
|
+// assertEquals(updateAccount.getPassword(),account.getPassword());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Test(expected = AccountNotExistException.class)
|
|
|
+// public void should_throw_when_update_not_exist_account() throws AccountNotExistException {
|
|
|
+// // arrange
|
|
|
+// Account account = this.createDiscorrectAccount();
|
|
|
+// // action
|
|
|
+// accountUTRepo.updateAccount(account);
|
|
|
+// }
|
|
|
+//
|
|
|
+// private LoginCommand getSuccessLoginCommand() {
|
|
|
+// LoginCommand loginCommand = new LoginCommand();
|
|
|
+// loginCommand.setMobileNum("EXIST_ACCOUNT");
|
|
|
+// loginCommand.setPassword("PASSWORD");
|
|
|
+// loginCommand.setCheckCode("123456");
|
|
|
+// return loginCommand;
|
|
|
+// }
|
|
|
+//
|
|
|
+// private Account getSuccessAccount() throws AccountNotExistException {
|
|
|
+// LoginCommand loginCommand = getSuccessLoginCommand();
|
|
|
+// IAccountRepo IAccountRepo = new AccountUTRepo();
|
|
|
+// return IAccountRepo.getByMobileNum(loginCommand.getMobileNum());
|
|
|
+// }
|
|
|
+//
|
|
|
+// private Account createCorrectAccount(){
|
|
|
+// AccountCommand accountCommand = new AccountCommand();
|
|
|
+// accountCommand.setMobileNum("EXIST_ACCOUNT");
|
|
|
+// accountCommand.setPassword("PASSWORD");
|
|
|
+// Account account = new Account();
|
|
|
+// account.setMobileNum(accountCommand.getMobileNum());
|
|
|
+// account.setPassword(accountCommand.getPassword());
|
|
|
+// return account;
|
|
|
+// }
|
|
|
+//
|
|
|
+// private Account createDiscorrectAccount(){
|
|
|
+// AccountCommand accountCommand = new AccountCommand();
|
|
|
+// accountCommand.setMobileNum("NOT_EXIST_ACCOUNT");
|
|
|
+// accountCommand.setPassword("PASSWORD");
|
|
|
+// Account account = new Account();
|
|
|
+// account.setMobileNum(accountCommand.getMobileNum());
|
|
|
+// account.setPassword(accountCommand.getPassword());
|
|
|
+// return account;
|
|
|
+// }
|
|
|
+//}
|