|
|
@@ -0,0 +1,118 @@
|
|
|
+package com.usoftchina.saas.account.controller;
|
|
|
+
|
|
|
+import com.usoftchina.saas.account.constant.AccountType;
|
|
|
+import com.usoftchina.saas.account.dto.AccountDTO;
|
|
|
+import com.usoftchina.saas.account.dto.AccountRegDTO;
|
|
|
+import com.usoftchina.saas.base.Result;
|
|
|
+import com.usoftchina.saas.test.BaseControllerTest;
|
|
|
+import com.usoftchina.saas.test.TestConstant;
|
|
|
+import org.junit.*;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.junit.runners.MethodSorters;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+import org.springframework.test.web.servlet.MvcResult;
|
|
|
+//import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest
|
|
|
+//@Transactional
|
|
|
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
|
|
+public class AccountControllerTest extends BaseControllerTest {
|
|
|
+
|
|
|
+ private final String mobile = "13500000000";
|
|
|
+
|
|
|
+ private final String password = "select111***";
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testA_register() throws Exception {
|
|
|
+ AccountRegDTO accountRegDTO = new AccountRegDTO();
|
|
|
+ accountRegDTO.setUsername(mobile);
|
|
|
+ accountRegDTO.setMobile(mobile);
|
|
|
+ accountRegDTO.setEmail("jack-ma@mxhichina.com");
|
|
|
+ accountRegDTO.setRealname("Jack Ma");
|
|
|
+ accountRegDTO.setPassword(password);
|
|
|
+ accountRegDTO.setType(AccountType.ADMIN.getType());
|
|
|
+
|
|
|
+ mockMvc.perform(requestBody("/account/register", accountRegDTO))
|
|
|
+ .andExpect(isSuccess());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testB_validByUsernameAndPwd() throws Exception {
|
|
|
+ MvcResult mvcResult = mockMvc.perform(get("/account/pwd/check")
|
|
|
+ .param("username", mobile)
|
|
|
+ .param("password", password))
|
|
|
+ .andExpect(isSuccess())
|
|
|
+ .andReturn();
|
|
|
+ Result<AccountDTO> result = result(mvcResult, AccountDTO.class);
|
|
|
+ System.out.println(result.getData());
|
|
|
+ Assert.assertEquals(result.getData().getMobile(), mobile);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testC_validByUsernameAndErrorPwd() throws Exception {
|
|
|
+ mockMvc.perform(get("/account/pwd/check")
|
|
|
+ .param("username", mobile)
|
|
|
+ .param("password", "1"))
|
|
|
+ .andExpect(isFail());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testD_getAccount() throws Exception {
|
|
|
+ AccountDTO accountDTO = getAccountDTO();
|
|
|
+ Assert.assertEquals(accountDTO.getMobile(), mobile);
|
|
|
+ }
|
|
|
+
|
|
|
+ private AccountDTO getAccountDTO() throws Exception {
|
|
|
+ MvcResult mvcResult = mockMvc.perform(get("/account")
|
|
|
+ .param("username", mobile))
|
|
|
+ .andExpect(isSuccess())
|
|
|
+ .andReturn();
|
|
|
+ Result<AccountDTO> result = result(mvcResult, AccountDTO.class);
|
|
|
+ System.out.println(result.getData());
|
|
|
+ return result.getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testE_bindCompany() throws Exception {
|
|
|
+ AccountDTO accountDTO = getAccountDTO();
|
|
|
+ mockMvc.perform(post("/account/bind/company")
|
|
|
+ .param("accountId", String.valueOf(accountDTO.getId()))
|
|
|
+ .param("companyId", String.valueOf(TestConstant.DEFAULT_COMPANY_ID)))
|
|
|
+ .andExpect(isSuccess());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testF_unbindCompany() throws Exception {
|
|
|
+ AccountDTO accountDTO = getAccountDTO();
|
|
|
+ mockMvc.perform(post("/account/unbind/company")
|
|
|
+ .param("accountId", String.valueOf(accountDTO.getId()))
|
|
|
+ .param("companyId", String.valueOf(TestConstant.DEFAULT_COMPANY_ID)))
|
|
|
+ .andExpect(isSuccess());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testG_disableAccount() throws Exception {
|
|
|
+ AccountDTO accountDTO = getAccountDTO();
|
|
|
+ mockMvc.perform(post("/account/disable")
|
|
|
+ .param("accountId", String.valueOf(accountDTO.getId())))
|
|
|
+ .andExpect(isSuccess());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testH_enableAccount() throws Exception {
|
|
|
+ AccountDTO accountDTO = getAccountDTO();
|
|
|
+ mockMvc.perform(post("/account/enable")
|
|
|
+ .param("accountId", String.valueOf(accountDTO.getId())))
|
|
|
+ .andExpect(isSuccess());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testI_deleteAccount() throws Exception {
|
|
|
+ AccountDTO accountDTO = getAccountDTO();
|
|
|
+ mockMvc.perform(post("/account/delete")
|
|
|
+ .param("accountId", String.valueOf(accountDTO.getId())))
|
|
|
+ .andExpect(isSuccess());
|
|
|
+ }
|
|
|
+}
|