[#8] modify: Cafe 도메인 관련 테스트 수정
- p6spy 모듈 제거 - CafeRepositoryTest BaseTimeEntity auditing 이슈 해결 - CafeTestUtils로 공통 함수 관리 - application.yml 설정 변경(주로 logging 관련)
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -33,7 +33,4 @@ out/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### log ###
|
||||
*.log
|
||||
.vscode/
|
||||
@@ -63,7 +63,6 @@ dependencies {
|
||||
runtimeOnly 'com.h2database:h2' // H2
|
||||
|
||||
implementation "org.flywaydb:flyway-core:${flywayVersion}" // flyway
|
||||
implementation("com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.8.0") // query logging
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ spring:
|
||||
hibernate:
|
||||
dialect: org.hibernate.dialect.MySQL5InnoDBDialect
|
||||
format_sql: true
|
||||
# show-sql: true
|
||||
show-sql: false
|
||||
flyway:
|
||||
baseline-on-migrate: true
|
||||
locations: classpath:db/migration,classpath:db/seed
|
||||
@@ -20,9 +20,4 @@ spring:
|
||||
logging:
|
||||
level:
|
||||
org.hibernate.SQL: debug # logger 통해 로깅
|
||||
org.hibernate.type: trace
|
||||
|
||||
decorator:
|
||||
datasource:
|
||||
p6spy:
|
||||
enable-logging: false # "p6spy": only for testing
|
||||
# org.hibernate.type: trace
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
package io.beaniejoy.dongnecafe.domain.cafe.entity
|
||||
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.CafeInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.CafeMenuInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.MenuOptionInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.OptionDetailInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.utils.CafeTestUtils
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.math.BigDecimal
|
||||
|
||||
internal class CafeTest {
|
||||
@Test
|
||||
fun create_cafe_test() {
|
||||
val cafeRequestDto = createCreateCafeRequestDto()
|
||||
val cafeRequestDto = CafeTestUtils.createCafeRequestDto()
|
||||
|
||||
val cafe = Cafe.createCafe(
|
||||
name = cafeRequestDto.name!!,
|
||||
@@ -24,42 +18,4 @@ internal class CafeTest {
|
||||
|
||||
CafeTestUtils.assertCafeEquals(request = cafeRequestDto, entity = cafe)
|
||||
}
|
||||
|
||||
private fun createCreateCafeRequestDto(): CafeInfoRequestDto {
|
||||
val cafeName = "beanie_cafe"
|
||||
val cafeAddress = "beanie_cafe_address"
|
||||
val phoneNumber = "01012345678"
|
||||
val description = "beanie_cafe_description"
|
||||
|
||||
val sizeOptionDetailList = listOf(
|
||||
OptionDetailInfoRequestDto(name = "medium", extraPrice = BigDecimal.ZERO),
|
||||
OptionDetailInfoRequestDto(name = "large", extraPrice = BigDecimal.valueOf(200L)),
|
||||
OptionDetailInfoRequestDto(name = "venti", extraPrice = BigDecimal.valueOf(700L))
|
||||
)
|
||||
val sizeMenuOption = MenuOptionInfoRequestDto(
|
||||
title = "size",
|
||||
optionDetailList = sizeOptionDetailList
|
||||
)
|
||||
|
||||
val cafeMenuList = listOf(
|
||||
CafeMenuInfoRequestDto(
|
||||
name = "menu1",
|
||||
price = BigDecimal.valueOf(2_800L),
|
||||
menuOptionList = listOf(sizeMenuOption)
|
||||
),
|
||||
CafeMenuInfoRequestDto(
|
||||
name = "menu2",
|
||||
price = BigDecimal.valueOf(3_500L),
|
||||
menuOptionList = listOf(sizeMenuOption)
|
||||
),
|
||||
)
|
||||
|
||||
return CafeInfoRequestDto(
|
||||
name = cafeName,
|
||||
address = cafeAddress,
|
||||
phoneNumber = phoneNumber,
|
||||
description = description,
|
||||
cafeMenuList = cafeMenuList
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package io.beaniejoy.dongnecafe.domain.cafe.repository
|
||||
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.CafeInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.CafeMenuInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.MenuOptionInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.OptionDetailInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.common.config.AuditingConfig
|
||||
import io.beaniejoy.dongnecafe.common.entity.BaseEntityAuditorAware
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.entity.Cafe
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.utils.CafeTestUtils
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
@@ -11,9 +9,21 @@ import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||
import java.math.BigDecimal
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.FilterType
|
||||
|
||||
@DataJpaTest
|
||||
@DataJpaTest(
|
||||
includeFilters = [
|
||||
ComponentScan.Filter(
|
||||
type = FilterType.ASSIGNABLE_TYPE,
|
||||
classes = [AuditingConfig::class]
|
||||
),
|
||||
ComponentScan.Filter(
|
||||
type = FilterType.ASSIGNABLE_TYPE,
|
||||
classes = [BaseEntityAuditorAware::class]
|
||||
)
|
||||
]
|
||||
)
|
||||
internal class CafeRepositoryTest {
|
||||
@Autowired
|
||||
lateinit var cafeRepository: CafeRepository
|
||||
@@ -21,7 +31,7 @@ internal class CafeRepositoryTest {
|
||||
@Test
|
||||
@DisplayName("[JPA] 신규 Cafe 저장 테스트")
|
||||
fun saveTest() {
|
||||
val cafeRequestDto = createCreateCafeRequestDto()
|
||||
val cafeRequestDto = CafeTestUtils.createCafeRequestDto()
|
||||
val cafe = cafeRequestDto.let {
|
||||
Cafe.createCafe(
|
||||
name = it.name!!,
|
||||
@@ -37,42 +47,4 @@ internal class CafeRepositoryTest {
|
||||
assertEquals(1L, savedCafe.id)
|
||||
CafeTestUtils.assertCafeEquals(cafeRequestDto, savedCafe)
|
||||
}
|
||||
|
||||
private fun createCreateCafeRequestDto(): CafeInfoRequestDto {
|
||||
val cafeName = "beanie_cafe"
|
||||
val cafeAddress = "beanie_cafe_address"
|
||||
val phoneNumber = "01012345678"
|
||||
val description = "beanie_cafe_description"
|
||||
|
||||
val sizeOptionDetailList = listOf(
|
||||
OptionDetailInfoRequestDto(name = "medium", extraPrice = BigDecimal.ZERO),
|
||||
OptionDetailInfoRequestDto(name = "large", extraPrice = BigDecimal.valueOf(200L)),
|
||||
OptionDetailInfoRequestDto(name = "venti", extraPrice = BigDecimal.valueOf(700L))
|
||||
)
|
||||
val sizeMenuOption = MenuOptionInfoRequestDto(
|
||||
title = "size",
|
||||
optionDetailList = sizeOptionDetailList
|
||||
)
|
||||
|
||||
val cafeMenuList = listOf(
|
||||
CafeMenuInfoRequestDto(
|
||||
name = "menu1",
|
||||
price = BigDecimal.valueOf(2_800L),
|
||||
menuOptionList = listOf(sizeMenuOption)
|
||||
),
|
||||
CafeMenuInfoRequestDto(
|
||||
name = "menu2",
|
||||
price = BigDecimal.valueOf(3_500L),
|
||||
menuOptionList = listOf(sizeMenuOption)
|
||||
),
|
||||
)
|
||||
|
||||
return CafeInfoRequestDto(
|
||||
name = cafeName,
|
||||
address = cafeAddress,
|
||||
phoneNumber = phoneNumber,
|
||||
description = description,
|
||||
cafeMenuList = cafeMenuList
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,17 @@
|
||||
package io.beaniejoy.dongnecafe.domain.cafe.service
|
||||
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.CafeInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.CafeMenuInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.MenuOptionInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.dto.request.OptionDetailInfoRequestDto
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.entity.Cafe
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.error.CafeExistedException
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.error.CafeNotFoundException
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.repository.CafeRepository
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.utils.CafeTestUtils
|
||||
import org.junit.jupiter.api.*
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.MethodOrderer
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestMethodOrder
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.InjectMocks
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import java.math.BigDecimal
|
||||
import java.util.*
|
||||
import javax.persistence.GeneratedValue
|
||||
|
||||
@@ -36,7 +28,7 @@ internal class CafeServiceTest {
|
||||
@DisplayName("카페 신규 생성 테스트")
|
||||
fun create_cafe_test() {
|
||||
// given
|
||||
val cafeRequestDto = createCreateCafeRequestDto()
|
||||
val cafeRequestDto = CafeTestUtils.createCafeRequestDto()
|
||||
val savedMockCafeId = 100L
|
||||
|
||||
`when`(mockCafeRepository.findByName(cafeRequestDto.name!!)).thenReturn(null)
|
||||
@@ -64,7 +56,7 @@ internal class CafeServiceTest {
|
||||
@DisplayName("카페 신규 생성시 이미 존재하는 카페 예외 발생 테스트")
|
||||
fun fail_create_cafe_when_existed() {
|
||||
// given
|
||||
val cafeRequestDto = createCreateCafeRequestDto()
|
||||
val cafeRequestDto = CafeTestUtils.createCafeRequestDto()
|
||||
val cafe = Cafe.createCafe(
|
||||
name = cafeRequestDto.name!!,
|
||||
address = cafeRequestDto.address!!,
|
||||
@@ -86,13 +78,15 @@ internal class CafeServiceTest {
|
||||
cafeMenuRequestList = cafeRequestDto.cafeMenuList
|
||||
)
|
||||
}
|
||||
|
||||
verify(mockCafeRepository).findByName(cafeRequestDto.name!!)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("카페 정보 변경 테스트")
|
||||
fun update_cafe_test() {
|
||||
// given
|
||||
val cafeRequestDto = createCreateCafeRequestDto()
|
||||
val cafeRequestDto = CafeTestUtils.createCafeRequestDto()
|
||||
val cafe = Cafe.createCafe(
|
||||
name = cafeRequestDto.name!!,
|
||||
address = cafeRequestDto.address!!,
|
||||
@@ -138,44 +132,6 @@ internal class CafeServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createCreateCafeRequestDto(): CafeInfoRequestDto {
|
||||
val cafeName = "beanie_cafe"
|
||||
val cafeAddress = "beanie_cafe_address"
|
||||
val phoneNumber = "01012345678"
|
||||
val description = "beanie_cafe_description"
|
||||
|
||||
val sizeOptionDetailList = listOf(
|
||||
OptionDetailInfoRequestDto(name = "medium", extraPrice = BigDecimal.ZERO),
|
||||
OptionDetailInfoRequestDto(name = "large", extraPrice = BigDecimal.valueOf(200L)),
|
||||
OptionDetailInfoRequestDto(name = "venti", extraPrice = BigDecimal.valueOf(700L))
|
||||
)
|
||||
val sizeMenuOption = MenuOptionInfoRequestDto(
|
||||
title = "size",
|
||||
optionDetailList = sizeOptionDetailList
|
||||
)
|
||||
|
||||
val cafeMenuList = listOf(
|
||||
CafeMenuInfoRequestDto(
|
||||
name = "menu1",
|
||||
price = BigDecimal.valueOf(2_800L),
|
||||
menuOptionList = listOf(sizeMenuOption)
|
||||
),
|
||||
CafeMenuInfoRequestDto(
|
||||
name = "menu2",
|
||||
price = BigDecimal.valueOf(3_500L),
|
||||
menuOptionList = listOf(sizeMenuOption)
|
||||
),
|
||||
)
|
||||
|
||||
return CafeInfoRequestDto(
|
||||
name = cafeName,
|
||||
address = cafeAddress,
|
||||
phoneNumber = phoneNumber,
|
||||
description = description,
|
||||
cafeMenuList = cafeMenuList
|
||||
)
|
||||
}
|
||||
|
||||
private fun injectCafeId(
|
||||
cafe: Cafe,
|
||||
newCafeId: Long,
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.beaniejoy.dongnecafe.domain.cafe.entity.CafeMenu
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.entity.MenuOption
|
||||
import io.beaniejoy.dongnecafe.domain.cafe.entity.OptionDetail
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import java.math.BigDecimal
|
||||
|
||||
class CafeTestUtils {
|
||||
companion object {
|
||||
@@ -29,7 +30,10 @@ class CafeTestUtils {
|
||||
Assertions.assertEquals(cafeMenuRequestList[index].name, cafeMenuList[index].name)
|
||||
Assertions.assertEquals(cafeMenuRequestList[index].price, cafeMenuList[index].price)
|
||||
|
||||
assertMenuOptionListEquals(cafeMenuRequestList[index].menuOptionList, cafeMenuList[index].menuOptionList)
|
||||
assertMenuOptionListEquals(
|
||||
cafeMenuRequestList[index].menuOptionList,
|
||||
cafeMenuList[index].menuOptionList
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,5 +61,43 @@ class CafeTestUtils {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun createCafeRequestDto(): CafeInfoRequestDto {
|
||||
val cafeName = "beanie_cafe"
|
||||
val cafeAddress = "beanie_cafe_address"
|
||||
val phoneNumber = "01012345678"
|
||||
val description = "beanie_cafe_description"
|
||||
|
||||
val sizeOptionDetailList = listOf(
|
||||
OptionDetailInfoRequestDto(name = "medium", extraPrice = BigDecimal.ZERO),
|
||||
OptionDetailInfoRequestDto(name = "large", extraPrice = BigDecimal.valueOf(200L)),
|
||||
OptionDetailInfoRequestDto(name = "venti", extraPrice = BigDecimal.valueOf(700L))
|
||||
)
|
||||
val sizeMenuOption = MenuOptionInfoRequestDto(
|
||||
title = "size",
|
||||
optionDetailList = sizeOptionDetailList
|
||||
)
|
||||
|
||||
val cafeMenuList = listOf(
|
||||
CafeMenuInfoRequestDto(
|
||||
name = "menu1",
|
||||
price = BigDecimal.valueOf(2_800L),
|
||||
menuOptionList = listOf(sizeMenuOption)
|
||||
),
|
||||
CafeMenuInfoRequestDto(
|
||||
name = "menu2",
|
||||
price = BigDecimal.valueOf(3_500L),
|
||||
menuOptionList = listOf(sizeMenuOption)
|
||||
),
|
||||
)
|
||||
|
||||
return CafeInfoRequestDto(
|
||||
name = cafeName,
|
||||
address = cafeAddress,
|
||||
phoneNumber = phoneNumber,
|
||||
description = description,
|
||||
cafeMenuList = cafeMenuList
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
spring:
|
||||
flyway:
|
||||
enabled: false
|
||||
jpa:
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
show_sql: false
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.hibernate.SQL: debug # logger 통해 로깅
|
||||
org.hibernate.type: trace
|
||||
org.hibernate.SQL: debug
|
||||
org.hibernate.type: trace
|
||||
Reference in New Issue
Block a user