8 Commits

Author SHA1 Message Date
rinjae 67ec6d2103 Jenkinsfile.deploy 추가
eapim-portal CI / build (push) Has been cancelled
eapim-portal Test / test (push) Has been cancelled
2026-06-18 11:12:57 +09:00
rinjae b024f8e86f Jenkinsfile.test-build 업데이트
eapim-portal CI / build (push) Has been cancelled
eapim-portal Test / test (push) Has been cancelled
2026-06-18 11:09:38 +09:00
rinjae fd16300553 Jenkinsfile.test-build 추가
eapim-portal CI / build (push) Has been cancelled
eapim-portal Test / test (push) Has been cancelled
2026-06-18 10:51:00 +09:00
Rinjae 815c329e3c 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>
2026-06-12 20:21:01 +09:00
Rinjae 7fdd70dbc7 ci - checkout step 이름·주석 정리
- 자신 모듈은 this branch, 의존은 master 명시
- step 이름과 주석으로 의도 가시화

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-12 19:50:58 +09:00
Rinjae 3dd9edc849 eapim-portal CI 테스트 워크플로 추가 2026-06-12 19:40:20 +09:00
Rinjae 6cff96f40a CI - systemd 유닛 동기화 및 리로드 단계 제거 2026-06-12 18:45:55 +09:00
Rinjae a97609d533 Gitea Generic Package 업로드 워크플로 추가
- WAR 파일 Gitea Generic Package 업로드 단계 추가
- 패키지 버전 및 업로드 실패 시 오류 처리 로직 포함
2026-06-12 18:43:18 +09:00
13 changed files with 570 additions and 109 deletions
+40 -12
View File
@@ -23,12 +23,14 @@ jobs:
working-directory: eapim-portal working-directory: eapim-portal
steps: steps:
- name: Checkout eapim-portal (trigger SHA) - name: Checkout eapim-portal (this branch)
# ref 미지정 — 트리거된 브랜치/commit(github.sha) 그대로 빌드.
uses: http://172.30.1.50:3000/actions/checkout@v4 uses: http://172.30.1.50:3000/actions/checkout@v4
with: with:
path: eapim-portal path: eapim-portal
- name: Checkout elink-portal-common (master) - name: Checkout elink-portal-common (master, dependency)
# 의존 모듈은 항상 master 고정.
working-directory: ${{ github.workspace }} working-directory: ${{ github.workspace }}
run: | run: |
rm -rf elink-portal-common rm -rf elink-portal-common
@@ -36,7 +38,8 @@ jobs:
http://oauth2:${{ secrets.CI_TOKEN }}@172.30.1.50:3000/djb-eapim/elink-portal-common.git \ http://oauth2:${{ secrets.CI_TOKEN }}@172.30.1.50:3000/djb-eapim/elink-portal-common.git \
elink-portal-common elink-portal-common
- name: Checkout elink-online-core-jpa (master) - name: Checkout elink-online-core-jpa (master, dependency)
# 의존 모듈은 항상 master 고정.
working-directory: ${{ github.workspace }} working-directory: ${{ github.workspace }}
run: | run: |
mkdir -p eapim-online mkdir -p eapim-online
@@ -62,6 +65,40 @@ jobs:
eapim-portal/build/libs/eapim-portal-boot.war eapim-portal/build/libs/eapim-portal-boot.war
if-no-files-found: error if-no-files-found: error
- name: Publish WAR to Gitea Generic Package
working-directory: ${{ github.workspace }}
env:
GITEA_URL: http://172.30.1.50:3000
PKG_OWNER: djb-eapim
PKG_NAME: eapim-portal
run: |
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
VERSION="$(TZ=Asia/Seoul date +%Y-%m-%d-%H%M)-${SHORT_SHA}"
BASE="$GITEA_URL/api/packages/$PKG_OWNER/generic/$PKG_NAME/$VERSION"
echo "package version: $VERSION"
echo "endpoint base : $BASE"
for WAR in eapim-portal.war eapim-portal-boot.war; do
SRC="eapim-portal/build/libs/$WAR"
if [ ! -f "$SRC" ]; then
echo "::error::missing artifact: $SRC"
exit 1
fi
HTTP=$(curl -sS -o "/tmp/pkg-upload-$WAR.log" -w '%{http_code}' \
--user "oauth2:${{ secrets.CI_TOKEN }}" \
--upload-file "$SRC" \
"$BASE/$WAR")
if [ "$HTTP" != "201" ] && [ "$HTTP" != "200" ]; then
echo "::error::upload failed for $WAR (HTTP $HTTP)"
cat "/tmp/pkg-upload-$WAR.log" || true
exit 1
fi
echo " uploaded: $WAR (HTTP $HTTP)"
done
echo "published: $GITEA_URL/$PKG_OWNER/-/packages/generic/$PKG_NAME/$VERSION"
- name: Stop tomcat (pre-clean) - name: Stop tomcat (pre-clean)
working-directory: ${{ github.workspace }} working-directory: ${{ github.workspace }}
run: | run: |
@@ -86,15 +123,6 @@ jobs:
cp eapim-portal/build/libs/eapim-portal.war "$DEPLOY_DIR/ROOT.war" cp eapim-portal/build/libs/eapim-portal.war "$DEPLOY_DIR/ROOT.war"
ls -la "$DEPLOY_DIR" ls -la "$DEPLOY_DIR"
- name: Refresh systemd unit
working-directory: ${{ github.workspace }}
run: |
# repo 의 unit 파일을 사용자 systemd 디렉터리로 sync (정의 변경 자동 반영)
install -m 0644 \
eapim-portal/deploy/systemd/eapim-portal.service \
"$HOME/.config/systemd/user/eapim-portal.service"
systemctl --user daemon-reload
- name: Start tomcat and readiness probe (timeout 120s) - name: Start tomcat and readiness probe (timeout 120s)
working-directory: ${{ github.workspace }} working-directory: ${{ github.workspace }}
run: | run: |
+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
+63
View File
@@ -0,0 +1,63 @@
name: eapim-portal Test
on:
push:
branches:
- master
- develop
- stage
- feats/ci-test
jobs:
test:
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)
# ref 미지정 — 트리거된 브랜치/commit(github.sha) 그대로 빌드.
uses: http://172.30.1.50:3000/actions/checkout@v4
with:
path: eapim-portal
- name: Checkout elink-portal-common (master, dependency)
# 의존 모듈은 항상 master 고정.
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)
# 의존 모듈은 항상 master 고정.
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 test
run: gradle test --no-daemon
- name: Upload test results
# 실패해도 결과 리포트는 올려서 원인 분석 가능하게.
if: always()
uses: http://172.30.1.50:3000/actions/upload-artifact@v3
with:
name: eapim-portal-test-${{ github.sha }}
path: |
eapim-portal/build/reports/tests/test/
eapim-portal/build/test-results/test/
if-no-files-found: warn
+182
View File
@@ -0,0 +1,182 @@
pipeline {
agent { label 'djb-vm' }
parameters {
string(name: 'BRANCH', defaultValue: 'master', description: 'Branch to deploy')
}
options {
timestamps()
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
}
environment {
JAVA_HOME = '/apps/opts/jdk8'
JAVA_HOME_TOMCAT = '/apps/opts/jdk17'
GRADLE_HOME = '/apps/opts/gradle-8.7'
GRADLE_USER_HOME = '/apps/opts/gradle-home'
NODE_HOME = '/apps/opts/node-v24'
PATH = "/apps/opts/jdk8/bin:/apps/opts/gradle-8.7/bin:/apps/opts/node-v24/bin:/apps/opts/bin:${env.PATH}"
GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new'
CATALINA_BASE = '/prod/eapim/devportal'
CATALINA_HOME = '/prod/eapim/apache-tomcat-9.0.116'
CATALINA_PID = '/prod/eapim/devportal/temp/catalina.pid'
DEPLOY_HTTP_PORT = '39130'
}
stages {
stage('Checkout') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: "*/${params.BRANCH}"]],
userRemoteConfigs: [[url: 'ssh://git@172.30.1.50:2222/djb-eapim/eapim-portal.git']]
])
}
}
stage('Checkout dependencies') {
steps {
sh '''
set -eu
cd "$WORKSPACE/.."
if [ ! -d elink-portal-common/.git ]; then
git clone --depth=1 --branch master \
ssh://git@172.30.1.50:2222/djb-eapim/elink-portal-common.git \
elink-portal-common
else
git -C elink-portal-common fetch --depth=1 origin master
git -C elink-portal-common reset --hard origin/master
git -C elink-portal-common clean -fdx
fi
mkdir -p eapim-online
if [ ! -d eapim-online/elink-online-core-jpa/.git ]; then
git clone --depth=1 --branch master \
ssh://git@172.30.1.50:2222/djb-eapim/elink-online-core-jpa.git \
eapim-online/elink-online-core-jpa
else
git -C eapim-online/elink-online-core-jpa fetch --depth=1 origin master
git -C eapim-online/elink-online-core-jpa reset --hard origin/master
git -C eapim-online/elink-online-core-jpa clean -fdx
fi
'''
}
}
stage('Verify toolchain') {
steps {
sh '''
set -eu
java -version
gradle --version
'''
}
}
stage('Build WAR') {
steps {
sh 'gradle clean build -x test --no-daemon'
}
post {
success {
sh '''
set -eu
cd build/libs
sha1sum eapim-portal.war eapim-portal-boot.war > SHA1SUMS
sha256sum eapim-portal.war eapim-portal-boot.war > SHA256SUMS
'''
archiveArtifacts artifacts: 'build/libs/eapim-portal.war,build/libs/eapim-portal-boot.war,build/libs/SHA1SUMS,build/libs/SHA256SUMS', fingerprint: true
}
}
}
stage('Stop Tomcat') {
steps {
sh '''
set +e
systemctl --user stop eapim-portal 2>/dev/null
if [ -f "$CATALINA_PID" ] && kill -0 "$(cat "$CATALINA_PID")" 2>/dev/null; then
JAVA_HOME="$JAVA_HOME_TOMCAT" "$CATALINA_HOME/bin/shutdown.sh" 30 -force || true
for i in $(seq 1 30); do
[ -f "$CATALINA_PID" ] && kill -0 "$(cat "$CATALINA_PID")" 2>/dev/null || break
sleep 1
done
fi
rm -f "$CATALINA_PID"
'''
}
}
stage('Deploy ROOT.war') {
steps {
sh '''
set -eu
DEPLOY_DIR="$CATALINA_BASE/webapps"
rm -rf "$DEPLOY_DIR/ROOT" "$DEPLOY_DIR/ROOT.war"
cp build/libs/eapim-portal.war "$DEPLOY_DIR/ROOT.war"
ls -la "$DEPLOY_DIR"
'''
}
}
stage('Start Tomcat and readiness') {
steps {
sh '''
set -eu
LOG="$CATALINA_BASE/logs/catalina.$(date +%Y-%m-%d).log"
BEFORE=0
[ -f "$LOG" ] && BEFORE=$(stat -c %s "$LOG")
systemctl --user start eapim-portal
DEADLINE=$(($(date +%s) + 120))
LIVE_OK=0
STATUS=000
while [ "$(date +%s)" -lt "$DEADLINE" ]; do
if [ "$LIVE_OK" = "0" ]; then
LIVE=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 3 \
"http://localhost:$DEPLOY_HTTP_PORT/health" 2>/dev/null || echo "000")
if [ "$LIVE" = "200" ]; then
echo "Liveness OK (/health)"
LIVE_OK=1
fi
fi
if [ "$LIVE_OK" = "1" ]; then
STATUS=$(curl -sS -o /tmp/eapim-ready-body.json -w '%{http_code}' --max-time 3 \
"http://localhost:$DEPLOY_HTTP_PORT/health/ready" 2>/dev/null || echo "000")
if [ "$STATUS" = "200" ]; then
echo "Readiness OK (/health/ready)"
cat /tmp/eapim-ready-body.json
echo
break
fi
fi
if [ -f "$LOG" ] && tail -c +$((BEFORE+1)) "$LOG" | grep -qE "Application listener .* Exception|SEVERE.*startup.Catalina"; then
echo "Startup error detected in log"
tail -c +$((BEFORE+1)) "$LOG" | tail -80
exit 1
fi
sleep 2
done
if [ "$STATUS" != "200" ]; then
echo "Readiness probe failed within 120s, last HTTP status: $STATUS"
[ -f /tmp/eapim-ready-body.json ] && cat /tmp/eapim-ready-body.json && echo
[ -f "$LOG" ] && tail -c +$((BEFORE+1)) "$LOG" | tail -100
exit 1
fi
echo "--- key boot log lines ---"
tail -c +$((BEFORE+1)) "$LOG" | grep -E "Server startup|Deployment of web" | head -10 || true
'''
}
}
}
}
+102
View File
@@ -0,0 +1,102 @@
pipeline {
agent { label 'djb-vm' }
triggers {
pollSCM('H/10 * * * *')
}
options {
timestamps()
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20'))
}
environment {
JAVA_HOME = '/apps/opts/jdk8'
JAVA_HOME_TOMCAT = '/apps/opts/jdk17'
GRADLE_HOME = '/apps/opts/gradle-8.7'
GRADLE_USER_HOME = '/apps/opts/gradle-home'
NODE_HOME = '/apps/opts/node-v24'
PATH = "/apps/opts/jdk8/bin:/apps/opts/gradle-8.7/bin:/apps/opts/node-v24/bin:/apps/opts/bin:${env.PATH}"
GIT_SSH_COMMAND = 'ssh -o StrictHostKeyChecking=accept-new'
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Checkout dependencies') {
steps {
sh '''
set -eu
cd "$WORKSPACE/.."
if [ ! -d elink-portal-common/.git ]; then
git clone --depth=1 --branch master \
ssh://git@172.30.1.50:2222/djb-eapim/elink-portal-common.git \
elink-portal-common
else
git -C elink-portal-common fetch --depth=1 origin master
git -C elink-portal-common reset --hard origin/master
git -C elink-portal-common clean -fdx
fi
mkdir -p eapim-online
if [ ! -d eapim-online/elink-online-core-jpa/.git ]; then
git clone --depth=1 --branch master \
ssh://git@172.30.1.50:2222/djb-eapim/elink-online-core-jpa.git \
eapim-online/elink-online-core-jpa
else
git -C eapim-online/elink-online-core-jpa fetch --depth=1 origin master
git -C eapim-online/elink-online-core-jpa reset --hard origin/master
git -C eapim-online/elink-online-core-jpa clean -fdx
fi
'''
}
}
stage('Verify toolchain') {
steps {
sh '''
set -eu
java -version
gradle --version
node --version || true
npm --version || true
'''
}
}
stage('Test') {
steps {
sh 'gradle clean test --no-daemon'
}
post {
always {
junit allowEmptyResults: true, testResults: 'build/test-results/test/*.xml'
archiveArtifacts allowEmptyArchive: true, artifacts: 'build/reports/tests/test/**,build/test-results/test/**'
}
}
}
stage('Build WAR') {
steps {
sh 'gradle build -x test --no-daemon'
}
post {
success {
sh '''
set -eu
cd build/libs
sha1sum eapim-portal.war eapim-portal-boot.war > SHA1SUMS
sha256sum eapim-portal.war eapim-portal-boot.war > SHA256SUMS
'''
archiveArtifacts artifacts: 'build/libs/eapim-portal.war,build/libs/eapim-portal-boot.war,build/libs/SHA1SUMS,build/libs/SHA256SUMS', fingerprint: true
}
}
}
}
}
+7 -1
View File
@@ -158,7 +158,13 @@ processResources {
} }
test { test {
useJUnitPlatform() useJUnitPlatform {
if (project.hasProperty('includeE2E') && project.includeE2E.toBoolean()) {
includeTags 'e2e'
} else {
excludeTags 'e2e'
}
}
enabled = true enabled = true
} }
@@ -1,13 +1,20 @@
package com.eactive.apim.portal.apps.user; 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.controller.AccountController;
import com.eactive.apim.portal.apps.user.dto.PasswordChangeRequestDTO; import com.eactive.apim.portal.apps.user.dto.PortalUserDTO;
import com.eactive.apim.portal.apps.user.dto.PortalOrgDTO; import com.eactive.apim.portal.apps.user.facade.AuthFacade;
import com.eactive.apim.portal.apps.user.service.PortalUserService; 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.user.PortalAuthenticatedUser;
import com.eactive.apim.portal.common.util.SecurityUtil; 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.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@@ -17,29 +24,38 @@ import org.mockito.MockedStatic;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; 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.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.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; 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") @SuppressWarnings("all")
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
class AccountControllerTest { class AccountControllerTest {
@Mock @Mock
private Validator validator; private UserFacade userFacade;
@Mock @Mock
private PortalUserService userService; private OrgRegisterFacade orgRegisterFacade;
@Mock @Mock
private FileService fileService; private AgreementsFacade agreementsFacade;
@Mock
private AuthFacade authFacade;
@Mock
private UserInvitationRepository userInvitationRepository;
@InjectMocks @InjectMocks
private AccountController accountController; private AccountController accountController;
@@ -52,110 +68,101 @@ class AccountControllerTest {
} }
@Test @Test
void testChangePassword() throws Exception { void testShowChangePasswordPage() throws Exception {
mockMvc.perform(get("/change_password.do")) mockMvc.perform(get("/change_password"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(view().name("apps/main/myUpdatePw")) .andExpect(view().name("apps/mypage/passwordChangeEntry"))
.andExpect(model().attributeExists("passwordChangeRequest")); .andExpect(model().attributeExists("passwordChangeRequest"));
} }
@Test @Test
void testUpdatePassword() throws Exception { void testUpdatePasswordRedirectsToLogin() throws Exception {
PasswordChangeRequestDTO dto = new PasswordChangeRequestDTO();
dto.setOldPassword("old");
dto.setNewPassword("new");
dto.setNewPassword2("new");
try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) { try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) {
securityUtil.when(SecurityUtil::getCurrentLoginId).thenReturn("testUser"); 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") @Test
.flashAttr("passwordChangeRequest", dto)) 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(status().isOk())
.andExpect(view().name("apps/main/myUpdatePw")) .andExpect(view().name("apps/mypage/passwordChange"))
.andExpect(model().attributeExists("error"))
.andExpect(model().attributeExists("passwordChangeRequest")); .andExpect(model().attributeExists("passwordChangeRequest"));
verify(validator).validate(any(), any());
} }
} }
@Test @Test
void testUpdatePasswordWithErrors() throws Exception { void testMypageForUser() throws Exception {
PasswordChangeRequestDTO dto = new PasswordChangeRequestDTO(); PortalAuthenticatedUser authenticatedUser = new PortalAuthenticatedUser();
dto.setOldPassword("old"); authenticatedUser.setId("user-1");
dto.setNewPassword("new"); authenticatedUser.setLoginId("testUser");
dto.setNewPassword2("different"); authenticatedUser.setRoleCode(RoleCode.ROLE_USER);
authenticatedUser.setUserStatus(UserStatus.ACTIVE);
authenticatedUser.setApprovalStatus(ApprovalStatus.COMPLETED);
doAnswer(invocation -> { PortalUserDTO dto = new PortalUserDTO();
BindingResult bindingResult = invocation.getArgument(1); dto.setId("user-1");
bindingResult.rejectValue("newPassword2", "error.password", "Passwords do not match"); dto.setLoginId("testUser");
return null; dto.setUserName("테스트유저");
}).when(validator).validate(any(), any(BindingResult.class)); 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)) { try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) {
PortalAuthenticatedUser user = new PortalAuthenticatedUser(); securityUtil.when(SecurityUtil::getPortalAuthenticatedUser).thenReturn(authenticatedUser);
securityUtil.when(SecurityUtil::getPortalAuthenticatedUser).thenReturn(user); when(userFacade.findById("user-1")).thenReturn(dto);
when(userInvitationRepository.findFirstByInvitationEmailAndStatus(
"test@example.com", InvitationStatus.PENDING))
.thenReturn(Optional.empty());
ModelAndView mav = accountController.mypage(); mockMvc.perform(get("/mypage"))
.andExpect(status().isOk())
assertEquals("apps/main/myPageEnt", mav.getViewName()); .andExpect(view().name("apps/mypage/updatePersonalUser"))
assertEquals(user, mav.getModel().get("user")); .andExpect(model().attributeExists("user"))
.andExpect(model().attribute("loginId", "testUser"))
.andExpect(model().attribute("hasPendingInvitation", false));
} }
} }
@Test @Test
void testMyCompanyInfo() throws Exception { void testMypageForCorporateManager() throws Exception {
try (MockedStatic<SecurityUtil> securityUtil = mockStatic(SecurityUtil.class)) { PortalAuthenticatedUser authenticatedUser = new PortalAuthenticatedUser();
securityUtil.when(SecurityUtil::getPortalAuthenticatedUser).thenReturn(new PortalAuthenticatedUser()); authenticatedUser.setId("manager-1");
authenticatedUser.setLoginId("manager");
authenticatedUser.setRoleCode(RoleCode.ROLE_CORP_MANAGER);
authenticatedUser.setUserStatus(UserStatus.ACTIVE);
authenticatedUser.setApprovalStatus(ApprovalStatus.COMPLETED);
mockMvc.perform(get("/my_company_info.do")) 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(status().isOk())
.andExpect(view().name("apps/main/myPageEntCompany")) .andExpect(view().name("apps/mypage/updateCorporateManager"))
.andExpect(model().attributeExists("user")); .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("--no-sandbox");
options.addArguments("--disable-dev-shm-usage"); options.addArguments("--disable-dev-shm-usage");
options.addArguments("--remote-allow-origins=*"); options.addArguments("--remote-allow-origins=*");
options.addArguments("--headless=new");
options.addArguments("--disable-gpu");
options.addArguments("--window-size=1280,800");
ChromeDriverService service = new ChromeDriverService.Builder() ChromeDriverService service = new ChromeDriverService.Builder()
.usingAnyFreePort() .usingAnyFreePort()
@@ -8,6 +8,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By; import org.openqa.selenium.By;
@@ -17,6 +18,7 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.ExpectedConditions;
@SuppressWarnings("all") @SuppressWarnings("all")
@Tag("e2e")
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class PortalOrgRegistrationRetainTest extends BaseWebTest { public class PortalOrgRegistrationRetainTest extends BaseWebTest {
@@ -8,6 +8,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By; import org.openqa.selenium.By;
@@ -17,6 +18,7 @@ import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.ExpectedConditions;
@SuppressWarnings("all") @SuppressWarnings("all")
@Tag("e2e")
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class PortalOrgRegistrationTest extends BaseWebTest { public class PortalOrgRegistrationTest extends BaseWebTest {
@@ -7,6 +7,7 @@ import io.github.bonigarcia.wdm.WebDriverManager;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.By; import org.openqa.selenium.By;
@@ -14,6 +15,7 @@ import org.openqa.selenium.WebElement;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("e2e")
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class PortalUserRegisterFieldTest extends BaseWebTest{ 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 com.eactive.apim.portal.PortalApplication;
import java.util.Objects; import java.util.Objects;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; 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; import org.springframework.test.web.servlet.MockMvc;
@SuppressWarnings("all") @SuppressWarnings("all")
@Tag("e2e")
@SpringBootTest(classes = PortalApplication.class) @SpringBootTest(classes = PortalApplication.class)
@ActiveProfiles({"dev", "unittest"}) @ActiveProfiles({"dev", "unittest"})
@AutoConfigureMockMvc @AutoConfigureMockMvc
@@ -7,12 +7,14 @@ import java.nio.file.Paths;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.TestFactory; import org.junit.jupiter.api.TestFactory;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.ExpectedConditions;
@SuppressWarnings("all") @SuppressWarnings("all")
@Tag("e2e")
class SignupPageTest extends BaseWebTest { class SignupPageTest extends BaseWebTest {
private final String USER_ID_FILE = "user_id_counter.txt"; private final String USER_ID_FILE = "user_id_counter.txt";