From 2a1daebd09b46453bbac9741636349634266c8c0 Mon Sep 17 00:00:00 2001 From: hyunsu Date: Thu, 15 Aug 2024 23:15:50 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20querydsl,=20mockk,=20kotest=20=EB=B9=8C?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 62 ++++--------------- .../common/config/JpaQueryFactoryConfig.kt | 17 +++++ 2 files changed, 28 insertions(+), 51 deletions(-) create mode 100644 src/test/kotlin/org/store/clothstar/common/config/JpaQueryFactoryConfig.kt diff --git a/build.gradle.kts b/build.gradle.kts index 8424bb4..cb5553d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,8 +1,8 @@ plugins { id("org.springframework.boot") version "3.3.2" id("io.spring.dependency-management") version "1.1.6" + id("org.jetbrains.kotlin.kapt") version "1.9.24" kotlin("jvm") version "1.9.24" -// kotlin("kapt") version "1.9.24" kotlin("plugin.spring") version "1.9.24" kotlin("plugin.jpa") version "1.9.24" //Entity의 기본생성자를 자동으로 만들어줌 } @@ -53,19 +53,20 @@ dependencies { runtimeOnly("com.mysql:mysql-connector-j") runtimeOnly("com.h2database:h2") - //querydsl - //참고 URL : https://velog.io/@yangwon-park/Kotlin-Querydsl-%EC%84%B8%ED%8C%85 -// implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta") -// implementation("com.querydsl:querydsl-apt:5.0.0:jakarta") -// implementation("jakarta.persistence:jakarta.persistence-api") -// implementation("jakarta.annotation:jakarta.annotation-api") -// kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") -// kapt("org.springframework.boot:spring-boot-configuration-processor") + //Querydsl + implementation("com.querydsl:querydsl-jpa:5.0.0:jakarta") + kapt("com.querydsl:querydsl-apt:5.0.0:jakarta") + kapt("org.springframework.boot:spring-boot-configuration-processor") //test testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") - testImplementation("io.mockk:mockk:1.13.5") + + //mockk, kotest + val mockkVersion = "1.13.8" + val kotestVersion = "5.8" + testImplementation("io.mockk:mockk:${mockkVersion}") + testImplementation("io.kotest:kotest-runner-junit5:${kotestVersion}") //etc implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0") //swagger @@ -73,49 +74,8 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-mail") //mail 전송 implementation("org.springframework.boot:spring-boot-starter-data-redis") //redis testRuntimeOnly("org.junit.platform:junit-platform-launcher") - } -/** - * Query DSL 설정 참고 - * URL : https://velog.io/@hana0627/Kotlin-SpringBoot3-QueryDsl-%EC%84%A4%EC%A0%95%ED%95%98%EA%B8%B0 - */ - -// Querydsl 설정부 추가 - start -//val generated = file("src/main/generated") -// -//// querydsl QClass 파일 생성 위치를 지정 -//tasks.withType { -// options.generatedSourceOutputDirectory.set(generated) -//} -// -//// kotlin source set 에 querydsl QClass 위치 추가 -//sourceSets { -// main { -// kotlin.srcDirs += generated -// } -//} -// -//// gradle clean 시에 QClass 디렉토리 삭제 -//tasks.named("clean") { -// doLast { -// generated.deleteRecursively() -// } -//} -// -// -//kapt { -// generateStubs = true -//} -// -//// Querydsl 설정부 추가 - end -// -//kotlin { -// compilerOptions { -// freeCompilerArgs.addAll("-Xjsr305=strict") -// } -//} - tasks.withType { useJUnitPlatform() } diff --git a/src/test/kotlin/org/store/clothstar/common/config/JpaQueryFactoryConfig.kt b/src/test/kotlin/org/store/clothstar/common/config/JpaQueryFactoryConfig.kt new file mode 100644 index 0000000..6922faa --- /dev/null +++ b/src/test/kotlin/org/store/clothstar/common/config/JpaQueryFactoryConfig.kt @@ -0,0 +1,17 @@ +package org.store.clothstar.common.config + +import com.querydsl.jpa.impl.JPAQueryFactory +import jakarta.persistence.EntityManager +import jakarta.persistence.PersistenceContext +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class JpaQueryFactoryConfig { + + @PersistenceContext + private lateinit var entityManager: EntityManager + + @Bean + fun jpaQueryFactory() = JPAQueryFactory(entityManager) +} \ No newline at end of file