Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

자동으로 계약서(contract)가 작성되도록 수정한다. #17

Merged
merged 10 commits into from
May 12, 2024
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ plugins {
id("io.spring.dependency-management") version "1.1.4"
id("com.google.osdetector") version "1.7.1"
kotlin("jvm") version "1.9.23"
kotlin("plugin.allopen") version "1.9.23"
kotlin("plugin.spring") version "1.9.23"
kotlin("plugin.jpa") version "1.9.23"
}

allprojects {
Expand All @@ -20,6 +22,8 @@ subprojects {
plugin("org.springframework.boot")
plugin("org.jetbrains.kotlin.jvm")
plugin("org.jetbrains.kotlin.plugin.spring")
plugin("org.jetbrains.kotlin.plugin.jpa")
plugin("org.jetbrains.kotlin.plugin.allopen")
plugin("com.google.osdetector")
}

Expand Down Expand Up @@ -66,4 +70,10 @@ subprojects {
tasks.test {
useJUnitPlatform()
}

allOpen {
annotation("jakarta.persistence.Entity")
annotation("jakarta.persistence.Embeddable")
annotation("jakarta.persistence.MappedSuperclass")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package event

import org.springframework.cloud.contract.spec.ContractDsl.Companion.contract

contract {
request {
method = GET
url = url("/events/1")
}
response {
status = OK
headers {
contentType = "application/json"
}
body = body(
"id" to 1,
"description" to "이벤트 설명",
"isProgress" to true,
"discountType" to "FIXED",
"intervalsProbability" to listOf(
mapOf(
"min" to 1000,
"max" to 1500,
"probability" to 0.5
),
mapOf(
"min" to 1600,
"max" to 2000,
"probability" to 0.3
),
mapOf(
"min" to 2100,
"max" to 2500,
"probability" to 0.2
)
),
"discountRangeMin" to 1000,
"discountRangeMax" to 2500,
"participatedMembers" to listOf(1, 2, 3)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import org.springframework.cloud.contract.spec.ContractDsl.Companion.contract

contract {
request {
method = PUT
url = url("/events/1/participants/1")
}
response {
status = OK
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package member

import org.springframework.cloud.contract.spec.ContractDsl.Companion.contract

contract {
request {
method = GET
url = url(v(consumer(regex("\\/members\\/[0-9]{1,10}")), producer("/members/1")))
}
response {
status = OK
headers {
contentType = "application/json"
}
body = body(
"id" to 1,
"name" to "이건창"
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package shop

import org.springframework.cloud.contract.spec.ContractDsl.Companion.contract

listOf(
contract {
name = "get owner shop id is 1"
request {
method = GET
url = url("/owners/shop/1")
}
response {
status = OK
headers {
contentType = "application/json"
}
body = body(
"shopOwnerId" to 1,
"shopId" to 1,
"shopName" to "첫 번째 가게"
)
}
},
contract {
name = "get owner shop id is 2"
request {
method = GET
url = url("/owners/shop/2")
}
response {
status = OK
headers {
contentType = "application/json"
}
body = body(
"shopOwnerId" to 2,
"shopId" to 2,
"shopName" to "두 번째 가게"
)
}
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package shop

import org.springframework.cloud.contract.spec.ContractDsl.Companion.contract

listOf(
contract {
name = "get owner id is 1"
request {
method = GET
url = url("/owners/1")
}
response {
status = OK
headers {
contentType = "application/json"
}
body = body(
"shopOwnerId" to 1,
"shopId" to 1,
"shopName" to "첫 번째 가게"
)
}
},
contract {
name = "get owner id is 2"
request {
method = GET
url = url("/owners/2")
}
response {
status = OK
headers {
contentType = "application/json"
}
body = body(
"shopOwnerId" to 2,
"shopId" to 2,
"shopName" to "두 번째 가게"
)
}
}
)
6 changes: 5 additions & 1 deletion coupon/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

tasks.withType<Jar> {
enabled = true
}

dependencies {
testImplementation("org.springframework.cloud:spring-cloud-starter-contract-stub-runner")
testImplementation("org.springframework.cloud:spring-cloud-contract-spec-kotlin")
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import jakarta.persistence.Table
@Table(name = "member")
class MemberEntity(
var name: String,
@ManyToMany
@ManyToMany(
targetEntity = CouponEntity::class
)
@JoinTable(
name = "member_coupon_book",
joinColumns = [JoinColumn(name = "member_id")],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,45 @@ import jakarta.persistence.Table
@Entity
@Table(name = "shop")
class ShopEntity(
@ManyToMany
@ManyToMany(
targetEntity = CouponEntity::class
)
@JoinTable(
name = "publish_coupon_book",
joinColumns = [JoinColumn(name = "shop_id")],
inverseJoinColumns = [JoinColumn(name = "coupon_id")],
)
val publishedCouponBook: List<CouponEntity>,
@ManyToMany
@ManyToMany(
targetEntity = CouponEntity::class
)
@JoinTable(
name = "publish_event_coupon_book",
joinColumns = [JoinColumn(name = "shop_id")],
inverseJoinColumns = [JoinColumn(name = "coupon_id")],
)
val publishedEventCouponBook: List<CouponEntity>,
@ManyToMany
@ManyToMany(
targetEntity = CouponEntity::class
)
@JoinTable(
name = "handout_coupon_book",
joinColumns = [JoinColumn(name = "shop_id")],
inverseJoinColumns = [JoinColumn(name = "coupon_id")],
)
var handOutCouponBook: List<CouponEntity>,
@ManyToMany
@ManyToMany(
targetEntity = CouponEntity::class
)
@JoinTable(
name = "use_coupon_book",
joinColumns = [JoinColumn(name = "shop_id")],
inverseJoinColumns = [JoinColumn(name = "coupon_id")],
)
var usedCouponBook: List<CouponEntity>,
@ManyToMany
@ManyToMany(
targetEntity = MemberEntity::class
)
@JoinTable(
name = "use_coupon_book",
joinColumns = [JoinColumn(name = "shop_id")],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.example.estdelivery.application.port.out.persistence.repository

import com.example.estdelivery.application.port.out.persistence.entity.ShopEntity
import com.example.estdelivery.application.port.out.persistence.entity.ShopOwnerEntity
import org.springframework.data.jpa.repository.JpaRepository
import java.util.Optional
import org.springframework.data.jpa.repository.JpaRepository

interface ShopOwnerRepository : JpaRepository<ShopOwnerEntity, Long> {
fun findByShopEntity(shopEntity: ShopEntity): Optional<ShopOwnerEntity>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Shop(
coupon,
CouponBook(
publishedCoupons.showPublishedCoupons() +
handOutCouponBook.showHandOutCoupon() +
publishedEventCoupons.showEventCoupons(),
handOutCouponBook.showHandOutCoupon() +
publishedEventCoupons.showEventCoupons(),
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest
class EstDeliveryCouponApplicationTests {
@Test
fun contextLoads() {}
fun contextLoads() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ class IssueRandomCouponServiceTest : FreeSpec({
isProgress = true,
disCountType = EventDiscountType.FIXED,
probabilityRanges =
DiscountAmountProbability(
listOf(
ProbabilityRange(1000, 1500, 0.5),
ProbabilityRange(1200, 2000, 0.3),
ProbabilityRange(2100, 3000, 0.2),
),
DiscountRange(1000, 3000),
DiscountAmountProbability(
listOf(
ProbabilityRange(1000, 1500, 0.5),
ProbabilityRange(1200, 2000, 0.3),
ProbabilityRange(2100, 3000, 0.2),
),
DiscountRange(1000, 3000),
),
participatedMembers = emptyList(),
)
val 이벤트_쿠폰 = 이벤트_쿠폰
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.kotest.core.spec.style.FreeSpec
import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.mockk
import java.util.*
import java.util.Optional

class CouponPersistenceAdapterTest : FreeSpec({
var couponRepository = mockk<CouponRepository>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import java.util.*
import java.util.Optional

class MemberPersistenceAdapterTest : FreeSpec({

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import java.util.*
import java.util.Optional

class ShopOwnerPersistenceAdapterTest : FreeSpec({

Expand Down
25 changes: 25 additions & 0 deletions event/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
import org.springframework.cloud.contract.verifier.config.TestFramework.JUNIT5

plugins {
id("org.springframework.cloud.contract") version "4.1.2"
}

group = "com.example.estdelivery.event"
version = "1.0-SNAPSHOT"

tasks.withType<Jar> {
enabled = true
}

dependencies {
testImplementation("org.springframework.cloud:spring-cloud-starter-contract-verifier")
testImplementation("org.springframework.cloud:spring-cloud-contract-spec-kotlin")
}

tasks.contractTest {
useJUnitPlatform()
}

contracts {
contractsDslDir.set(file("src/test/resources/contracts"))
testFramework.set(JUNIT5)
packageWithBaseClasses.set("com.example.estdelivery.event")
stubsOutputDir.set(file("../contract-stubs"))
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.estdelivery
package com.example.estdelivery.event

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
Expand Down
Loading
Loading