CI - 단위테스트 안정화 및 e2e 분리 워크플로 도입
eapim-portal CI / build (push) Has been cancelled
eapim-portal Test / test (push) Has been cancelled

- AccountControllerTest 현 컨트롤러 API 기준 재작성
- Selenium 4종·SignupFileTest @Tag("e2e") 부여
- BaseWebTest headless 옵션, e2e 워크플로 신설

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rinjae
2026-06-12 20:21:01 +09:00
parent 7fdd70dbc7
commit 815c329e3c
9 changed files with 183 additions and 97 deletions
+60
View File
@@ -0,0 +1,60 @@
name: eapim-portal E2E Test
# 수동 트리거 전용. e2e 태그가 붙은 Selenium/통합 테스트만 실행.
# 요구 인프라:
# - Chrome + libgbm/libxkbcommon-x11 (Selenium 4종)
# - Oracle JDBC 또는 testcontainers (SignupFileTest)
# 미설치 환경에서는 SessionNotCreated/DB 에러로 일부 케이스가 실패할 수 있음.
on:
workflow_dispatch:
jobs:
e2e:
runs-on: [self-hosted, linux, eapim-portal]
env:
JAVA_HOME: /apps/opts/jdk8
defaults:
run:
working-directory: eapim-portal
steps:
- name: Checkout eapim-portal (this branch)
uses: http://172.30.1.50:3000/actions/checkout@v4
with:
path: eapim-portal
- name: Checkout elink-portal-common (master, dependency)
working-directory: ${{ github.workspace }}
run: |
rm -rf elink-portal-common
git clone --depth=1 --branch master \
http://oauth2:${{ secrets.CI_TOKEN }}@172.30.1.50:3000/djb-eapim/elink-portal-common.git \
elink-portal-common
- name: Checkout elink-online-core-jpa (master, dependency)
working-directory: ${{ github.workspace }}
run: |
mkdir -p eapim-online
rm -rf eapim-online/elink-online-core-jpa
git clone --depth=1 --branch master \
http://oauth2:${{ secrets.CI_TOKEN }}@172.30.1.50:3000/djb-eapim/elink-online-core-jpa.git \
eapim-online/elink-online-core-jpa
- name: Verify toolchain
run: |
java -version
gradle --version
- name: Gradle e2e test
run: gradle test --no-daemon -PincludeE2E=true
- name: Upload test results
if: always()
uses: http://172.30.1.50:3000/actions/upload-artifact@v3
with:
name: eapim-portal-e2e-${{ github.sha }}
path: |
eapim-portal/build/reports/tests/test/
eapim-portal/build/test-results/test/
if-no-files-found: warn
+7 -1
View File
@@ -158,7 +158,13 @@ processResources {
}
test {
useJUnitPlatform()
useJUnitPlatform {
if (project.hasProperty('includeE2E') && project.includeE2E.toBoolean()) {
includeTags 'e2e'
} else {
excludeTags 'e2e'
}
}
enabled = true
}
@@ -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"));
}
}
@@ -40,6 +40,9 @@ public abstract class BaseWebTest {
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--remote-allow-origins=*");
options.addArguments("--headless=new");
options.addArguments("--disable-gpu");
options.addArguments("--window-size=1280,800");
ChromeDriverService service = new ChromeDriverService.Builder()
.usingAnyFreePort()
@@ -8,6 +8,7 @@ import java.io.FileWriter;
import java.io.IOException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By;
@@ -17,6 +18,7 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
@SuppressWarnings("all")
@Tag("e2e")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class PortalOrgRegistrationRetainTest extends BaseWebTest {
@@ -8,6 +8,7 @@ import java.io.FileWriter;
import java.io.IOException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By;
@@ -17,6 +18,7 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
@SuppressWarnings("all")
@Tag("e2e")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class PortalOrgRegistrationTest extends BaseWebTest {
@@ -7,6 +7,7 @@ import io.github.bonigarcia.wdm.WebDriverManager;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By;
@@ -14,6 +15,7 @@ import org.openqa.selenium.WebElement;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("e2e")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class PortalUserRegisterFieldTest extends BaseWebTest{
@@ -7,6 +7,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import com.eactive.apim.portal.PortalApplication;
import java.util.Objects;
import javax.servlet.http.Cookie;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -17,6 +18,7 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
@SuppressWarnings("all")
@Tag("e2e")
@SpringBootTest(classes = PortalApplication.class)
@ActiveProfiles({"dev", "unittest"})
@AutoConfigureMockMvc
@@ -7,12 +7,14 @@ import java.nio.file.Paths;
import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.TestFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
@SuppressWarnings("all")
@Tag("e2e")
class SignupPageTest extends BaseWebTest {
private final String USER_ID_FILE = "user_id_counter.txt";