|
|
|
@@ -1,13 +1,20 @@
|
|
|
|
|
package com.eactive.apim.portal.apps.user;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.eactive.apim.portal.apps.agreements.service.AgreementsFacade;
|
|
|
|
|
import com.eactive.apim.portal.apps.user.controller.AccountController;
|
|
|
|
|
import com.eactive.apim.portal.apps.user.dto.PasswordChangeRequestDTO;
|
|
|
|
|
import com.eactive.apim.portal.apps.user.dto.PortalOrgDTO;
|
|
|
|
|
import com.eactive.apim.portal.apps.user.service.PortalUserService;
|
|
|
|
|
import com.eactive.apim.portal.apps.user.dto.PortalUserDTO;
|
|
|
|
|
import com.eactive.apim.portal.apps.user.facade.AuthFacade;
|
|
|
|
|
import com.eactive.apim.portal.apps.user.facade.OrgRegisterFacade;
|
|
|
|
|
import com.eactive.apim.portal.apps.user.facade.UserFacade;
|
|
|
|
|
import com.eactive.apim.portal.common.user.PortalAuthenticatedUser;
|
|
|
|
|
import com.eactive.apim.portal.common.util.SecurityUtil;
|
|
|
|
|
import com.eactive.apim.portal.file.service.FileService;
|
|
|
|
|
import com.eactive.apim.portal.invitation.entity.UserInvitationEnums.InvitationStatus;
|
|
|
|
|
import com.eactive.apim.portal.invitation.repository.UserInvitationRepository;
|
|
|
|
|
import com.eactive.apim.portal.portaluser.entity.PortalUserEnums.ApprovalStatus;
|
|
|
|
|
import com.eactive.apim.portal.portaluser.entity.PortalUserEnums.RoleCode;
|
|
|
|
|
import com.eactive.apim.portal.portaluser.entity.PortalUserEnums.UserStatus;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
|
|
@@ -17,29 +24,38 @@ import org.mockito.MockedStatic;
|
|
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
|
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
import org.springframework.validation.Validator;
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyString;
|
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
|
import static org.mockito.Mockito.doThrow;
|
|
|
|
|
import static org.mockito.Mockito.mockStatic;
|
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
|
|
|
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
|
|
|
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("all")
|
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
|
|
|
class AccountControllerTest {
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private Validator validator;
|
|
|
|
|
private UserFacade userFacade;
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private PortalUserService userService;
|
|
|
|
|
private OrgRegisterFacade orgRegisterFacade;
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private FileService fileService;
|
|
|
|
|
private AgreementsFacade agreementsFacade;
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private AuthFacade authFacade;
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
private UserInvitationRepository userInvitationRepository;
|
|
|
|
|
|
|
|
|
|
@InjectMocks
|
|
|
|
|
private AccountController accountController;
|
|
|
|
@@ -52,110 +68,101 @@ class AccountControllerTest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testChangePassword() throws Exception {
|
|
|
|
|
mockMvc.perform(get("/change_password.do"))
|
|
|
|
|
void testShowChangePasswordPage() throws Exception {
|
|
|
|
|
mockMvc.perform(get("/change_password"))
|
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
|
.andExpect(view().name("apps/main/myUpdatePw"))
|
|
|
|
|
.andExpect(view().name("apps/mypage/passwordChangeEntry"))
|
|
|
|
|
.andExpect(model().attributeExists("passwordChangeRequest"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testUpdatePassword() throws Exception {
|
|
|
|
|
PasswordChangeRequestDTO dto = new PasswordChangeRequestDTO();
|
|
|
|
|
dto.setOldPassword("old");
|
|
|
|
|
dto.setNewPassword("new");
|
|
|
|
|
dto.setNewPassword2("new");
|
|
|
|
|
|
|
|
|
|
void testUpdatePasswordRedirectsToLogin() throws Exception {
|
|
|
|
|
try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) {
|
|
|
|
|
securityUtil.when(SecurityUtil::getCurrentLoginId).thenReturn("testUser");
|
|
|
|
|
|
|
|
|
|
// when(userService.findByLoginId("testUser")).thenReturn(true);
|
|
|
|
|
mockMvc.perform(post("/mypage/change_new_password")
|
|
|
|
|
.param("newPassword", "NewPass!1")
|
|
|
|
|
.param("confirmPassword", "NewPass!1"))
|
|
|
|
|
.andExpect(status().is3xxRedirection())
|
|
|
|
|
.andExpect(redirectedUrl("/login"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(post("/update_password.do")
|
|
|
|
|
.flashAttr("passwordChangeRequest", dto))
|
|
|
|
|
@Test
|
|
|
|
|
void testUpdatePasswordWithIllegalArgument() throws Exception {
|
|
|
|
|
try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) {
|
|
|
|
|
securityUtil.when(SecurityUtil::getCurrentLoginId).thenReturn("testUser");
|
|
|
|
|
doThrow(new IllegalArgumentException("invalid password"))
|
|
|
|
|
.when(userFacade).updatePassword(eq("testUser"), anyString(), anyString());
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(post("/mypage/change_new_password")
|
|
|
|
|
.param("newPassword", "NewPass!1")
|
|
|
|
|
.param("confirmPassword", "Different!1"))
|
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
|
.andExpect(view().name("apps/main/myUpdatePw"))
|
|
|
|
|
.andExpect(view().name("apps/mypage/passwordChange"))
|
|
|
|
|
.andExpect(model().attributeExists("error"))
|
|
|
|
|
.andExpect(model().attributeExists("passwordChangeRequest"));
|
|
|
|
|
|
|
|
|
|
verify(validator).validate(any(), any());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testUpdatePasswordWithErrors() throws Exception {
|
|
|
|
|
PasswordChangeRequestDTO dto = new PasswordChangeRequestDTO();
|
|
|
|
|
dto.setOldPassword("old");
|
|
|
|
|
dto.setNewPassword("new");
|
|
|
|
|
dto.setNewPassword2("different");
|
|
|
|
|
void testMypageForUser() throws Exception {
|
|
|
|
|
PortalAuthenticatedUser authenticatedUser = new PortalAuthenticatedUser();
|
|
|
|
|
authenticatedUser.setId("user-1");
|
|
|
|
|
authenticatedUser.setLoginId("testUser");
|
|
|
|
|
authenticatedUser.setRoleCode(RoleCode.ROLE_USER);
|
|
|
|
|
authenticatedUser.setUserStatus(UserStatus.ACTIVE);
|
|
|
|
|
authenticatedUser.setApprovalStatus(ApprovalStatus.COMPLETED);
|
|
|
|
|
|
|
|
|
|
doAnswer(invocation -> {
|
|
|
|
|
BindingResult bindingResult = invocation.getArgument(1);
|
|
|
|
|
bindingResult.rejectValue("newPassword2", "error.password", "Passwords do not match");
|
|
|
|
|
return null;
|
|
|
|
|
}).when(validator).validate(any(), any(BindingResult.class));
|
|
|
|
|
PortalUserDTO dto = new PortalUserDTO();
|
|
|
|
|
dto.setId("user-1");
|
|
|
|
|
dto.setLoginId("testUser");
|
|
|
|
|
dto.setUserName("테스트유저");
|
|
|
|
|
dto.setMobileNumber("01012345678");
|
|
|
|
|
dto.setEmailAddr("test@example.com");
|
|
|
|
|
dto.setRoleCode(RoleCode.ROLE_USER);
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(post("/update_password.do")
|
|
|
|
|
.flashAttr("passwordChangeRequest", dto))
|
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
|
.andExpect(view().name("apps/main/myUpdatePw"))
|
|
|
|
|
.andExpect(model().attributeExists("errors"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testMypage() {
|
|
|
|
|
try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) {
|
|
|
|
|
PortalAuthenticatedUser user = new PortalAuthenticatedUser();
|
|
|
|
|
securityUtil.when(SecurityUtil::getPortalAuthenticatedUser).thenReturn(user);
|
|
|
|
|
securityUtil.when(SecurityUtil::getPortalAuthenticatedUser).thenReturn(authenticatedUser);
|
|
|
|
|
when(userFacade.findById("user-1")).thenReturn(dto);
|
|
|
|
|
when(userInvitationRepository.findFirstByInvitationEmailAndStatus(
|
|
|
|
|
"test@example.com", InvitationStatus.PENDING))
|
|
|
|
|
.thenReturn(Optional.empty());
|
|
|
|
|
|
|
|
|
|
ModelAndView mav = accountController.mypage();
|
|
|
|
|
|
|
|
|
|
assertEquals("apps/main/myPageEnt", mav.getViewName());
|
|
|
|
|
assertEquals(user, mav.getModel().get("user"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testMyCompanyInfo() throws Exception {
|
|
|
|
|
try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) {
|
|
|
|
|
securityUtil.when(SecurityUtil::getPortalAuthenticatedUser).thenReturn(new PortalAuthenticatedUser());
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(get("/my_company_info.do"))
|
|
|
|
|
mockMvc.perform(get("/mypage"))
|
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
|
.andExpect(view().name("apps/main/myPageEntCompany"))
|
|
|
|
|
.andExpect(view().name("apps/mypage/updatePersonalUser"))
|
|
|
|
|
.andExpect(model().attributeExists("user"))
|
|
|
|
|
.andExpect(model().attribute("loginId", "testUser"))
|
|
|
|
|
.andExpect(model().attribute("hasPendingInvitation", false));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testMypageForCorporateManager() throws Exception {
|
|
|
|
|
PortalAuthenticatedUser authenticatedUser = new PortalAuthenticatedUser();
|
|
|
|
|
authenticatedUser.setId("manager-1");
|
|
|
|
|
authenticatedUser.setLoginId("manager");
|
|
|
|
|
authenticatedUser.setRoleCode(RoleCode.ROLE_CORP_MANAGER);
|
|
|
|
|
authenticatedUser.setUserStatus(UserStatus.ACTIVE);
|
|
|
|
|
authenticatedUser.setApprovalStatus(ApprovalStatus.COMPLETED);
|
|
|
|
|
|
|
|
|
|
PortalUserDTO dto = new PortalUserDTO();
|
|
|
|
|
dto.setId("manager-1");
|
|
|
|
|
dto.setLoginId("manager");
|
|
|
|
|
dto.setUserName("매니저");
|
|
|
|
|
dto.setMobileNumber("01098765432");
|
|
|
|
|
dto.setEmailAddr("manager@example.com");
|
|
|
|
|
dto.setRoleCode(RoleCode.ROLE_CORP_MANAGER);
|
|
|
|
|
|
|
|
|
|
try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) {
|
|
|
|
|
securityUtil.when(SecurityUtil::getPortalAuthenticatedUser).thenReturn(authenticatedUser);
|
|
|
|
|
when(userFacade.findById("manager-1")).thenReturn(dto);
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(get("/mypage"))
|
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
|
.andExpect(view().name("apps/mypage/updateCorporateManager"))
|
|
|
|
|
.andExpect(model().attributeExists("user"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testUpdateCompanyInfo() throws Exception {
|
|
|
|
|
PortalOrgDTO dto = new PortalOrgDTO();
|
|
|
|
|
dto.setOrgName("Test Company");
|
|
|
|
|
|
|
|
|
|
try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) {
|
|
|
|
|
securityUtil.when(SecurityUtil::getCurrentLoginId).thenReturn("testUser");
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(post("/update_my_company_info.do")
|
|
|
|
|
.flashAttr("user", dto))
|
|
|
|
|
.andExpect(status().is3xxRedirection())
|
|
|
|
|
.andExpect(redirectedUrl("/my_company_info.do"));
|
|
|
|
|
|
|
|
|
|
verify(validator).validate(eq(dto), any());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void testUpdateCompanyInfoWithErrors() throws Exception {
|
|
|
|
|
PortalOrgDTO dto = new PortalOrgDTO();
|
|
|
|
|
|
|
|
|
|
doAnswer(invocation -> {
|
|
|
|
|
BindingResult bindingResult = invocation.getArgument(1);
|
|
|
|
|
bindingResult.rejectValue("companyName", "error.companyName", "Company name is required");
|
|
|
|
|
return null;
|
|
|
|
|
}).when(validator).validate(any(), any(BindingResult.class));
|
|
|
|
|
|
|
|
|
|
mockMvc.perform(post("/update_my_company_info.do")
|
|
|
|
|
.flashAttr("user", dto))
|
|
|
|
|
.andExpect(status().isOk())
|
|
|
|
|
.andExpect(view().name("apps/main/myPageEntCompany"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|