generated from pricelees/issue-pr-template
[#1] 코틀린 의존성 추가 및 View 기능 마이그레이션 #2
34
build.gradle
34
build.gradle
@ -1,34 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'org.springframework.boot' version '3.2.4'
|
|
||||||
id 'io.spring.dependency-management' version '1.1.4'
|
|
||||||
id 'java'
|
|
||||||
}
|
|
||||||
|
|
||||||
group = 'nextstep'
|
|
||||||
version = '0.0.1-SNAPSHOT'
|
|
||||||
sourceCompatibility = '17'
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
|
||||||
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
|
|
||||||
|
|
||||||
implementation 'io.jsonwebtoken:jjwt:0.9.1'
|
|
||||||
implementation 'javax.xml.bind:jaxb-api:2.3.1'
|
|
||||||
|
|
||||||
runtimeOnly 'com.h2database:h2'
|
|
||||||
|
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
|
||||||
testImplementation 'io.rest-assured:rest-assured:5.3.1'
|
|
||||||
}
|
|
||||||
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
||||||
82
build.gradle.kts
Normal file
82
build.gradle.kts
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
plugins {
|
||||||
|
val springBootVersion = "3.5.3"
|
||||||
|
val kotlinVersion = "2.2.0"
|
||||||
|
|
||||||
|
java
|
||||||
|
id("org.springframework.boot") version springBootVersion
|
||||||
|
id("io.spring.dependency-management") version "1.1.7"
|
||||||
|
|
||||||
|
//kotlin plugins
|
||||||
|
kotlin("jvm") version kotlinVersion
|
||||||
|
kotlin("plugin.spring") version kotlinVersion
|
||||||
|
kotlin("plugin.jpa") version kotlinVersion
|
||||||
|
kotlin("kapt") version kotlinVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "com.sangdol"
|
||||||
|
version = "0.0.1-SNAPSHOT"
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(17)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// spring
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-validation")
|
||||||
|
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0")
|
||||||
|
runtimeOnly("com.h2database:h2")
|
||||||
|
|
||||||
|
// jwt
|
||||||
|
implementation("io.jsonwebtoken:jjwt:0.9.1")
|
||||||
|
implementation("javax.xml.bind:jaxb-api:2.3.1")
|
||||||
|
|
||||||
|
// kotlin
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-reflect")
|
||||||
|
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
|
||||||
|
implementation("io.github.oshai:kotlin-logging-jvm:7.0.3")
|
||||||
|
|
||||||
|
// test
|
||||||
|
testImplementation("io.mockk:mockk:1.14.4")
|
||||||
|
testImplementation("io.kotest:kotest-runner-junit5:5.9.1")
|
||||||
|
testImplementation("io.kotest.extensions:kotest-extensions-spring:1.3.0")
|
||||||
|
testImplementation("com.ninja-squad:springmockk:4.0.2")
|
||||||
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
|
testImplementation("io.rest-assured:rest-assured:5.3.1")
|
||||||
|
testImplementation("io.rest-assured:kotlin-extensions:5.5.5")
|
||||||
|
}
|
||||||
|
|
||||||
|
kapt {
|
||||||
|
keepJavacAnnotationProcessors = true
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<Test>().configureEach {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
compileKotlin {
|
||||||
|
compilerOptions {
|
||||||
|
freeCompilerArgs.add("-Xjsr305=strict")
|
||||||
|
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
|
||||||
|
freeCompilerArgs.set(listOf("-Xannotation-default-target=param-property"))
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
compileTestKotlin {
|
||||||
|
compilerOptions {
|
||||||
|
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
|
||||||
|
freeCompilerArgs.set(listOf("-Xannotation-default-target=param-property"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
47
gradlew
vendored
47
gradlew
vendored
@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@ -55,7 +57,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (3) This script is generated from the Groovy template
|
||||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
# within the Gradle project.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
@ -80,13 +82,11 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
APP_NAME="Gradle"
|
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@ -114,7 +114,7 @@ case "$( uname )" in #(
|
|||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH="\\\"\\\""
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@ -133,22 +133,29 @@ location of your Java installation."
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD=java
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
max*)
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
warn "Could not query maximum file descriptor limit"
|
warn "Could not query maximum file descriptor limit"
|
||||||
esac
|
esac
|
||||||
case $MAX_FD in #(
|
case $MAX_FD in #(
|
||||||
'' | soft) :;; #(
|
'' | soft) :;; #(
|
||||||
*)
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
ulimit -n "$MAX_FD" ||
|
ulimit -n "$MAX_FD" ||
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
esac
|
esac
|
||||||
@ -193,18 +200,28 @@ if "$cygwin" || "$msys" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Collect all arguments for the java command;
|
|
||||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
# shell script including quotes and variable substitutions, so put them in
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
# double quotes to make sure that they get re-expanded; and
|
|
||||||
# * put everything else in single quotes, so that it's not re-expanded.
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-classpath "$CLASSPATH" \
|
-classpath "$CLASSPATH" \
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
# Use "xargs" to parse quoted args.
|
||||||
#
|
#
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
|||||||
37
gradlew.bat
vendored
37
gradlew.bat
vendored
@ -13,6 +13,8 @@
|
|||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@ -26,6 +28,7 @@ if "%OS%"=="Windows_NT" setlocal
|
|||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
|||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
@ -56,32 +59,34 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
echo.
|
echo. 1>&2
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
echo location of your Java installation.
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
goto fail
|
goto fail
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
package roomescape;
|
|
||||||
|
|
||||||
import org.springframework.boot.Banner.Mode;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class RoomescapeApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication springApplication = new SpringApplication(RoomescapeApplication.class);
|
|
||||||
springApplication.setBannerMode(Mode.OFF);
|
|
||||||
springApplication.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
src/main/java/roomescape/RoomescapeApplication.kt
Normal file
14
src/main/java/roomescape/RoomescapeApplication.kt
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package roomescape
|
||||||
|
|
||||||
|
import org.springframework.boot.Banner
|
||||||
|
import org.springframework.boot.SpringApplication
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
class RoomescapeApplication
|
||||||
|
|
||||||
|
fun main(args: Array<String>) {
|
||||||
|
val springApplication = SpringApplication(RoomescapeApplication::class.java)
|
||||||
|
springApplication.setBannerMode(Banner.Mode.OFF)
|
||||||
|
springApplication.run()
|
||||||
|
}
|
||||||
@ -1,40 +0,0 @@
|
|||||||
package roomescape.view.controller;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
|
|
||||||
import roomescape.system.auth.annotation.Admin;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
public class AdminPageController {
|
|
||||||
|
|
||||||
@Admin
|
|
||||||
@GetMapping("/admin")
|
|
||||||
public String showAdminPage() {
|
|
||||||
return "admin/index";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Admin
|
|
||||||
@GetMapping("/admin/reservation")
|
|
||||||
public String showAdminReservationPage() {
|
|
||||||
return "admin/reservation-new";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Admin
|
|
||||||
@GetMapping("/admin/time")
|
|
||||||
public String showAdminTimePage() {
|
|
||||||
return "admin/time";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Admin
|
|
||||||
@GetMapping("/admin/theme")
|
|
||||||
public String showAdminThemePage() {
|
|
||||||
return "admin/theme";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Admin
|
|
||||||
@GetMapping("/admin/waiting")
|
|
||||||
public String showAdminWaitingPage() {
|
|
||||||
return "admin/waiting";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
package roomescape.view.controller;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
public class AuthPageController {
|
|
||||||
|
|
||||||
@GetMapping("/login")
|
|
||||||
public String showLoginPage() {
|
|
||||||
return "login";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
package roomescape.view.controller;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
|
|
||||||
import roomescape.system.auth.annotation.LoginRequired;
|
|
||||||
|
|
||||||
@Controller
|
|
||||||
public class ClientPageController {
|
|
||||||
|
|
||||||
@GetMapping("/")
|
|
||||||
public String showPopularThemePage() {
|
|
||||||
return "index";
|
|
||||||
}
|
|
||||||
|
|
||||||
@LoginRequired
|
|
||||||
@GetMapping("/reservation")
|
|
||||||
public String showReservationPage() {
|
|
||||||
return "reservation";
|
|
||||||
}
|
|
||||||
|
|
||||||
@LoginRequired
|
|
||||||
@GetMapping("/reservation-mine")
|
|
||||||
public String showReservationMinePage() {
|
|
||||||
return "reservation-mine";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
48
src/main/java/roomescape/view/controller/PageController.kt
Normal file
48
src/main/java/roomescape/view/controller/PageController.kt
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package roomescape.view.controller
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
|
import roomescape.system.auth.annotation.Admin
|
||||||
|
import roomescape.system.auth.annotation.LoginRequired
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
class AuthPageController {
|
||||||
|
|
||||||
|
@GetMapping("/login")
|
||||||
|
fun showLoginPage(): String = "login"
|
||||||
|
}
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/admin")
|
||||||
|
class AdminPageController {
|
||||||
|
|
||||||
|
@Admin
|
||||||
|
@GetMapping
|
||||||
|
fun showIndexPage() = "admin/index"
|
||||||
|
|
||||||
|
@Admin
|
||||||
|
@GetMapping("/{page}")
|
||||||
|
fun showAdminSubPage(@PathVariable page: String) = when (page) {
|
||||||
|
"reservation" -> "admin/reservation-new"
|
||||||
|
"time" -> "admin/time"
|
||||||
|
"theme" -> "admin/theme"
|
||||||
|
"waiting" -> "admin/waiting"
|
||||||
|
else -> "admin/index"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
class ClientPageController {
|
||||||
|
@GetMapping("/")
|
||||||
|
fun showPopularThemePage(): String = "index"
|
||||||
|
|
||||||
|
@LoginRequired
|
||||||
|
@GetMapping("/reservation")
|
||||||
|
fun showReservationPage(): String = "reservation"
|
||||||
|
|
||||||
|
@LoginRequired
|
||||||
|
@GetMapping("/reservation-mine")
|
||||||
|
fun showReservationMinePage(): String = "reservation-mine"
|
||||||
|
}
|
||||||
20
src/test/java/roomescape/common/Fixtures.kt
Normal file
20
src/test/java/roomescape/common/Fixtures.kt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package roomescape.common
|
||||||
|
|
||||||
|
import roomescape.member.domain.Member
|
||||||
|
import roomescape.member.domain.Role
|
||||||
|
import java.util.concurrent.atomic.AtomicLong
|
||||||
|
|
||||||
|
object MemberFixture {
|
||||||
|
val idCounter: AtomicLong = AtomicLong(1L)
|
||||||
|
|
||||||
|
fun create(
|
||||||
|
id: Long? = idCounter.incrementAndGet(),
|
||||||
|
name: String = "sangdol",
|
||||||
|
account: String = "default",
|
||||||
|
password: String = "password",
|
||||||
|
role: Role = Role.ADMIN
|
||||||
|
): Member = Member(id, name, "$account@email.com", password, role)
|
||||||
|
|
||||||
|
fun admin(): Member = create(account = "admin", role = Role.ADMIN)
|
||||||
|
fun user(): Member = create(account = "user", role = Role.MEMBER)
|
||||||
|
}
|
||||||
9
src/test/java/roomescape/common/KotestConfig.kt
Normal file
9
src/test/java/roomescape/common/KotestConfig.kt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package roomescape.common
|
||||||
|
|
||||||
|
import io.kotest.core.config.AbstractProjectConfig
|
||||||
|
import io.kotest.extensions.spring.SpringExtension
|
||||||
|
import io.kotest.extensions.spring.SpringTestExtension
|
||||||
|
|
||||||
|
object KotestConfig : AbstractProjectConfig() {
|
||||||
|
override fun extensions(): List<SpringTestExtension> = listOf(SpringExtension)
|
||||||
|
}
|
||||||
11
src/test/java/roomescape/common/TestAnnotations.kt
Normal file
11
src/test/java/roomescape/common/TestAnnotations.kt
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package roomescape.common
|
||||||
|
|
||||||
|
import org.springframework.test.context.TestPropertySource
|
||||||
|
|
||||||
|
@Target(AnnotationTarget.CLASS)
|
||||||
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
|
@TestPropertySource(properties = [
|
||||||
|
"spring.jpa.hibernate.ddl-auto=none",
|
||||||
|
"spring.sql.init.mode=never"
|
||||||
|
])
|
||||||
|
annotation class NoSqlInitialize
|
||||||
@ -1,219 +0,0 @@
|
|||||||
package roomescape.view.controller;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hamcrest.Matchers;
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
|
||||||
import org.springframework.test.context.jdbc.Sql;
|
|
||||||
|
|
||||||
import io.restassured.RestAssured;
|
|
||||||
import io.restassured.http.ContentType;
|
|
||||||
import io.restassured.http.Header;
|
|
||||||
import roomescape.member.domain.Member;
|
|
||||||
import roomescape.member.domain.Role;
|
|
||||||
import roomescape.member.domain.repository.MemberRepository;
|
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
||||||
@Sql(scripts = "/truncate.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
|
|
||||||
class AdminPageControllerTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MemberRepository memberRepository;
|
|
||||||
|
|
||||||
@LocalServerPort
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 권한이 있는 유저가 /admin 으로 GET 요청을 보내면 어드민 페이지와 200 OK 를 받는다.")
|
|
||||||
void getAdminPageHasRole() {
|
|
||||||
// given
|
|
||||||
String adminAccessTokenCookie = getAdminAccessTokenCookieByLogin("admin@admin.com", "12341234");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", adminAccessTokenCookie))
|
|
||||||
.when().get("/admin")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 권한이 없는 유저가 /admin 으로 GET 요청을 보내면 로그인 페이지로 리다이렉트 된다.")
|
|
||||||
void getAdminPageHasNotRole() {
|
|
||||||
// given
|
|
||||||
String accessTokenCookie = getAccessTokenCookieByLogin("member@member.com", "12341234");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", accessTokenCookie))
|
|
||||||
.when().get("/admin")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(Matchers.containsString("<title>Login</title>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("/admin/reservation 으로 GET 요청을 보내면 어드민 예약 관리 페이지와 200 OK 를 받는다.")
|
|
||||||
void getAdminReservationPageHasRole() {
|
|
||||||
// given
|
|
||||||
String adminAccessTokenCookie = getAdminAccessTokenCookieByLogin("admin@admin.com", "12341234");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", adminAccessTokenCookie))
|
|
||||||
.when().get("/admin/reservation")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 권한이 없는 유저가 /admin/reservation 으로 GET 요청을 보내면 로그인 페이지로 리다이렉트 된다.")
|
|
||||||
void getAdminReservationPageHasNotRole() {
|
|
||||||
// given
|
|
||||||
String accessTokenCookie = getAccessTokenCookieByLogin("member@member.com", "12341234");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", accessTokenCookie))
|
|
||||||
.when().get("/admin/reservation")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(Matchers.containsString("<title>Login</title>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("/admin/time 으로 GET 요청을 보내면 어드민 예약 시간 관리 페이지와 200 OK 를 받는다.")
|
|
||||||
void getAdminTimePageHasRole() {
|
|
||||||
// given
|
|
||||||
String adminAccessTokenCookie = getAdminAccessTokenCookieByLogin("admin@admin.com", "12341234");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", adminAccessTokenCookie))
|
|
||||||
.when().get("/admin/time")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 권한이 없는 유저가 /admin/time 으로 GET 요청을 보내면 로그인 페이지로 리다이렉트 된다.")
|
|
||||||
void getAdminTimePageHasNotRole() {
|
|
||||||
// given
|
|
||||||
String accessTokenCookie = getAccessTokenCookieByLogin("member@member.com", "12341234");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", accessTokenCookie))
|
|
||||||
.when().get("/admin/time")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(Matchers.containsString("<title>Login</title>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 권한이 있는 유저가 /admin/theme 으로 GET 요청을 보내면 어드민 테마 관리 페이지와 200 OK 를 받는다.")
|
|
||||||
void getAdminThemePageHasRole() {
|
|
||||||
// given
|
|
||||||
String adminAccessTokenCookie = getAdminAccessTokenCookieByLogin("admin@admin.com", "12341234");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", adminAccessTokenCookie))
|
|
||||||
.when().get("/admin/theme")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 권한이 없는 유저가 /admin/theme 으로 GET 요청을 보내면 로그인 페이지로 리다이렉트 된다.")
|
|
||||||
void getAdminThemePageHasNotRole() {
|
|
||||||
// given
|
|
||||||
String accessTokenCookie = getAccessTokenCookieByLogin("member@member.com", "12341234");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", accessTokenCookie))
|
|
||||||
.when().get("/admin/theme")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(Matchers.containsString("<title>Login</title>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 권한이 있는 유저가 /admin/waiting 으로 GET 요청을 보내면 어드민 대기 관리 페이지와 200 OK 를 받는다.")
|
|
||||||
void getAdminWatingPage() {
|
|
||||||
// given
|
|
||||||
String adminAccessTokenCookie = getAdminAccessTokenCookieByLogin("admin@email.com", "12341234");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", adminAccessTokenCookie))
|
|
||||||
.when().get("/admin/waiting")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("관리자 권한이 없는 유저가 /admin/waiting 으로 GET 요청을 보내면 로그인 페이지로 리다이렉트 된다.")
|
|
||||||
void getAdminWaitingPageHasNotRole() {
|
|
||||||
// given
|
|
||||||
String accessTokenCookie = getAccessTokenCookieByLogin("member@email.com", "member");
|
|
||||||
|
|
||||||
// when & then
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", accessTokenCookie))
|
|
||||||
.when().get("/admin/waiting")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(Matchers.containsString("<title>Login</title>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getAdminAccessTokenCookieByLogin(String email, String password) {
|
|
||||||
memberRepository.save(new Member("이름", email, password, Role.ADMIN));
|
|
||||||
|
|
||||||
Map<String, String> loginParams = Map.of(
|
|
||||||
"email", email,
|
|
||||||
"password", password
|
|
||||||
);
|
|
||||||
|
|
||||||
String accessToken = RestAssured.given().log().all()
|
|
||||||
.contentType(ContentType.JSON)
|
|
||||||
.port(port)
|
|
||||||
.body(loginParams)
|
|
||||||
.when().post("/login")
|
|
||||||
.then().log().all().extract().cookie("accessToken");
|
|
||||||
|
|
||||||
return "accessToken=" + accessToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getAccessTokenCookieByLogin(String email, String password) {
|
|
||||||
memberRepository.save(new Member("name", email, password, Role.MEMBER));
|
|
||||||
Map<String, String> loginParams = Map.of(
|
|
||||||
"email", email,
|
|
||||||
"password", password
|
|
||||||
);
|
|
||||||
|
|
||||||
String accessToken = RestAssured.given().log().all()
|
|
||||||
.contentType(ContentType.JSON)
|
|
||||||
.port(port)
|
|
||||||
.body(loginParams)
|
|
||||||
.when().post("/login")
|
|
||||||
.then().log().all().extract().cookie("accessToken");
|
|
||||||
|
|
||||||
return "accessToken=" + accessToken;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
package roomescape.view.controller;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
|
||||||
|
|
||||||
import io.restassured.RestAssured;
|
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
||||||
class AuthPageControllerTest {
|
|
||||||
|
|
||||||
@LocalServerPort
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("/login 으로 GET 요청을 보내면 login 페이지와 200 OK 를 받는다.")
|
|
||||||
void getMainPage() {
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.when().get("/login")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,102 +0,0 @@
|
|||||||
package roomescape.view.controller;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.DisplayName;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
|
||||||
import org.springframework.test.context.jdbc.Sql;
|
|
||||||
|
|
||||||
import io.restassured.RestAssured;
|
|
||||||
import io.restassured.http.ContentType;
|
|
||||||
import io.restassured.http.Header;
|
|
||||||
import roomescape.member.domain.Member;
|
|
||||||
import roomescape.member.domain.Role;
|
|
||||||
import roomescape.member.domain.repository.MemberRepository;
|
|
||||||
|
|
||||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
||||||
@Sql(scripts = "/truncate.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
|
|
||||||
class ClientPageControllerTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MemberRepository memberRepository;
|
|
||||||
|
|
||||||
@LocalServerPort
|
|
||||||
private int port;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("/ 으로 GET 요청을 보내면 index 페이지와 200 OK 를 받는다.")
|
|
||||||
void getMainPage() {
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", getAccessTokenCookieByLogin("email@email.com", "password")))
|
|
||||||
.when().get("/")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("/reservation 으로 GET 요청을 보내면 방탈출 예약 페이지와 200 OK 를 받는다.")
|
|
||||||
void getReservationPage() {
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", getAccessTokenCookieByLogin("email@email.com", "password")))
|
|
||||||
.when().get("/reservation")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("로그인 없이 /reservation 으로 GET 요청을 보내면 로그인 페이지로 리다이렉트 된다.")
|
|
||||||
void getReservationPageWithoutLogin() {
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.when().get("/reservation")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(containsString("<title>Login</title>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("/reservation-mine 으로 GET 요청을 보내면 방탈출 예약 페이지와 200 OK 를 받는다.")
|
|
||||||
void getMyReservationPage() {
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.header(new Header("Cookie", getAccessTokenCookieByLogin("email@email.com", "password")))
|
|
||||||
.when().get("/reservation-mine")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@DisplayName("로그인 없이 /reservation-mine 으로 GET 요청을 보내면 로그인 페이지로 리다이렉트 된다.")
|
|
||||||
void getMyReservationPageWithoutLogin() {
|
|
||||||
RestAssured.given().log().all()
|
|
||||||
.port(port)
|
|
||||||
.when().get("/reservation-mine")
|
|
||||||
.then().log().all()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(containsString("<title>Login</title>"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getAccessTokenCookieByLogin(String email, String password) {
|
|
||||||
memberRepository.save(new Member("name", email, password, Role.MEMBER));
|
|
||||||
Map<String, String> loginParams = Map.of(
|
|
||||||
"email", email,
|
|
||||||
"password", password
|
|
||||||
);
|
|
||||||
|
|
||||||
String accessToken = RestAssured.given().log().all()
|
|
||||||
.contentType(ContentType.JSON)
|
|
||||||
.port(port)
|
|
||||||
.body(loginParams)
|
|
||||||
.when().post("/login")
|
|
||||||
.then().log().all().extract().cookie("accessToken");
|
|
||||||
|
|
||||||
return "accessToken=" + accessToken;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
161
src/test/java/roomescape/view/controller/PageControllerTest.kt
Normal file
161
src/test/java/roomescape/view/controller/PageControllerTest.kt
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
package roomescape.view.controller
|
||||||
|
|
||||||
|
import com.ninjasquad.springmockk.MockkBean
|
||||||
|
import io.kotest.core.spec.style.BehaviorSpec
|
||||||
|
import io.mockk.every
|
||||||
|
import io.restassured.module.kotlin.extensions.Given
|
||||||
|
import io.restassured.module.kotlin.extensions.Then
|
||||||
|
import io.restassured.module.kotlin.extensions.When
|
||||||
|
import io.restassured.response.ValidatableResponse
|
||||||
|
import org.hamcrest.Matchers.containsString
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest
|
||||||
|
import org.springframework.boot.test.web.server.LocalServerPort
|
||||||
|
import org.springframework.http.HttpStatus
|
||||||
|
import roomescape.common.MemberFixture
|
||||||
|
import roomescape.common.NoSqlInitialize
|
||||||
|
import roomescape.member.domain.Member
|
||||||
|
import roomescape.member.service.MemberService
|
||||||
|
import roomescape.system.auth.jwt.JwtHandler
|
||||||
|
import roomescape.system.exception.ErrorType
|
||||||
|
import roomescape.system.exception.RoomEscapeException
|
||||||
|
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
|
@NoSqlInitialize
|
||||||
|
class PageControllerTest(
|
||||||
|
@LocalServerPort val port: Int,
|
||||||
|
) : BehaviorSpec() {
|
||||||
|
|
||||||
|
@MockkBean
|
||||||
|
private lateinit var jwtHandler: JwtHandler
|
||||||
|
|
||||||
|
@MockkBean
|
||||||
|
private lateinit var memberService: MemberService
|
||||||
|
|
||||||
|
private val admin: Member = MemberFixture.admin()
|
||||||
|
private val user: Member = MemberFixture.user()
|
||||||
|
|
||||||
|
|
||||||
|
init {
|
||||||
|
listOf("/", "/login").forEach {
|
||||||
|
given("GET $it 요청은") {
|
||||||
|
`when`("로그인 및 권한 여부와 관계없이 성공한다.") {
|
||||||
|
then("비회원") {
|
||||||
|
runTest(it) {
|
||||||
|
statusCode(200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
then("회원") {
|
||||||
|
every {
|
||||||
|
jwtHandler.getMemberIdFromToken(any())
|
||||||
|
} returns user.id
|
||||||
|
|
||||||
|
runTest(it) {
|
||||||
|
statusCode(200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
then("관리자") {
|
||||||
|
every {
|
||||||
|
jwtHandler.getMemberIdFromToken(any())
|
||||||
|
} returns admin.id
|
||||||
|
|
||||||
|
runTest(it) {
|
||||||
|
statusCode(200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listOf("/admin", "/admin/reservation", "/admin/time", "/admin/theme", "/admin/waiting").forEach {
|
||||||
|
given("GET $it 요청을") {
|
||||||
|
`when`("관리자가 보내면") {
|
||||||
|
every {
|
||||||
|
jwtHandler.getMemberIdFromToken(any())
|
||||||
|
} returns admin.id
|
||||||
|
|
||||||
|
then("성공한다.") {
|
||||||
|
runTest(it) {
|
||||||
|
statusCode(200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
`when`("회원이 보내면") {
|
||||||
|
every {
|
||||||
|
jwtHandler.getMemberIdFromToken(any())
|
||||||
|
} returns user.id
|
||||||
|
|
||||||
|
then("로그인 페이지로 이동한다.") {
|
||||||
|
runTest(it) {
|
||||||
|
statusCode(200)
|
||||||
|
body(containsString("<title>Login</title>"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
listOf("/reservation", "/reservation-mine").forEach {
|
||||||
|
given("GET $it 요청을") {
|
||||||
|
`when`("로그인 된 회원이 보내면 성공한다.") {
|
||||||
|
then("회원") {
|
||||||
|
every {
|
||||||
|
jwtHandler.getMemberIdFromToken(any())
|
||||||
|
} returns user.id
|
||||||
|
|
||||||
|
runTest(it) {
|
||||||
|
statusCode(200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
then("관리자") {
|
||||||
|
every {
|
||||||
|
jwtHandler.getMemberIdFromToken(any())
|
||||||
|
} returns admin.id
|
||||||
|
|
||||||
|
runTest(it) {
|
||||||
|
statusCode(200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
`when`("로그인 없이 보내면") {
|
||||||
|
then("로그인 페이지로 이동한다.") {
|
||||||
|
every {
|
||||||
|
jwtHandler.getMemberIdFromToken(any())
|
||||||
|
} returns null
|
||||||
|
|
||||||
|
runTest(it) {
|
||||||
|
statusCode(200)
|
||||||
|
body(containsString("<title>Login</title>"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun runTest(endpoint: String, assert: ValidatableResponse.() -> Unit) {
|
||||||
|
setUpMocks()
|
||||||
|
|
||||||
|
Given {
|
||||||
|
port(port)
|
||||||
|
header("Cookie", "accessToken=token")
|
||||||
|
} When {
|
||||||
|
get(endpoint)
|
||||||
|
} Then assert
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setUpMocks() {
|
||||||
|
every { memberService.findMemberById(admin.id) } returns admin
|
||||||
|
|
||||||
|
every { memberService.findMemberById(user.id) } returns user
|
||||||
|
|
||||||
|
every { memberService.findMemberById(null) } throws RoomEscapeException(
|
||||||
|
ErrorType.MEMBER_NOT_FOUND,
|
||||||
|
String.format("[memberId: %d]", null),
|
||||||
|
HttpStatus.BAD_REQUEST
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user