-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KAN-78] 음식점 조회 API에 MySQL 연결 - test code 세팅 및 기본 테스트코드
- Loading branch information
1 parent
9c9a5c3
commit 8327ffc
Showing
9 changed files
with
248 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/kotlin/com/restaurant/be/common/PageDeserializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.restaurant.be.common | ||
|
||
import com.fasterxml.jackson.core.JsonParser | ||
import com.fasterxml.jackson.databind.DeserializationContext | ||
import com.fasterxml.jackson.databind.JsonDeserializer | ||
import com.fasterxml.jackson.databind.JsonNode | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.PageImpl | ||
import org.springframework.data.domain.PageRequest | ||
|
||
class PageDeserializer<T>(private val clazz: Class<T>) : JsonDeserializer<Page<T>>() { | ||
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): Page<T> { | ||
val mapper = (p.codec as ObjectMapper) | ||
val node: JsonNode = mapper.readTree(p) | ||
val content: List<T> = mapper.convertValue( | ||
node.get("content"), | ||
mapper.typeFactory.constructCollectionType(List::class.java, clazz) | ||
) | ||
val pageable = PageRequest.of( | ||
node.get("pageable")?.get("pageNumber")?.asInt() ?: 0, | ||
node.get("pageable")?.get("pageSize")?.asInt() ?: 0 | ||
) | ||
return PageImpl(content, pageable, node.get("totalElements")?.asLong() ?: 0L) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/test/kotlin/com/restaurant/be/common/util/RestaurantDocument.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.restaurant.be.common.util | ||
|
||
import org.springframework.data.elasticsearch.annotations.Document | ||
import org.springframework.data.elasticsearch.annotations.Field | ||
import org.springframework.data.elasticsearch.annotations.FieldType | ||
import javax.persistence.Id | ||
|
||
@Document(indexName = "restaurant") | ||
data class RestaurantDocument( | ||
@Id | ||
@Field(type = FieldType.Long, name = "id") | ||
val id: Long, | ||
|
||
@Field(type = FieldType.Text, name = "name") | ||
val name: String, | ||
|
||
@Field(type = FieldType.Text, name = "original_category") | ||
val originalCategory: String, | ||
|
||
@Field(type = FieldType.Text, name = "address") | ||
val address: String, | ||
|
||
@Field(type = FieldType.Long, name = "naver_review_count") | ||
val naverReviewCount: Long, | ||
|
||
@Field(type = FieldType.Float, name = "naver_rating_avg") | ||
val naverRatingAvg: Float, | ||
|
||
@Field(type = FieldType.Long, name = "review_count") | ||
val reviewCount: Long, | ||
|
||
@Field(type = FieldType.Float, name = "rating_avg") | ||
val ratingAvg: Float, | ||
|
||
@Field(type = FieldType.Long, name = "like_count") | ||
val likeCount: Long, | ||
|
||
@Field(type = FieldType.Text, name = "number") | ||
val number: String, | ||
|
||
@Field(type = FieldType.Text, name = "image_url") | ||
val imageUrl: String, | ||
|
||
@Field(type = FieldType.Text, name = "category") | ||
val category: String, | ||
|
||
@Field(type = FieldType.Text, name = "discount_content") | ||
val discountContent: String, | ||
|
||
@Field(type = FieldType.Nested, name = "menus") | ||
val menus: List<MenuDocument> | ||
) | ||
|
||
data class MenuDocument( | ||
@Field(type = FieldType.Text, name = "menu_name") | ||
val menuName: String, | ||
|
||
@Field(type = FieldType.Integer, name = "price") | ||
val price: Int, | ||
|
||
@Field(type = FieldType.Text, name = "description") | ||
val description: String, | ||
|
||
@Field(type = FieldType.Text, name = "is_representative") | ||
val isRepresentative: String, | ||
|
||
@Field(type = FieldType.Text, name = "image_url") | ||
val imageUrl: String | ||
) |
71 changes: 71 additions & 0 deletions
71
src/test/kotlin/com/restaurant/be/common/util/RestaurantUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.restaurant.be.common.util | ||
|
||
import com.restaurant.be.restaurant.presentation.domain.entity.Menu | ||
import com.restaurant.be.restaurant.presentation.domain.entity.Restaurant | ||
|
||
object RestaurantUtil { | ||
|
||
fun generateRestaurantDocument( | ||
id: Long, | ||
name: String = "default_name", | ||
originalCategory: String = "default_category", | ||
address: String = "default_address", | ||
naverReviewCount: Long = 0, | ||
naverRatingAvg: Float = 0.0f, | ||
reviewCount: Long = 0, | ||
ratingAvg: Float = 0.0f, | ||
likeCount: Long = 0, | ||
number: String = "default_number", | ||
imageUrl: String = "default_image_url", | ||
category: String = "default_category", | ||
discountContent: String = "default_discount_content", | ||
menus: List<MenuDocument> = emptyList() | ||
): RestaurantDocument { | ||
return RestaurantDocument( | ||
id = id, | ||
name = name, | ||
originalCategory = originalCategory, | ||
address = address, | ||
naverReviewCount = naverReviewCount, | ||
naverRatingAvg = naverRatingAvg, | ||
reviewCount = reviewCount, | ||
ratingAvg = ratingAvg, | ||
likeCount = likeCount, | ||
number = number, | ||
imageUrl = imageUrl, | ||
category = category, | ||
discountContent = discountContent, | ||
menus = menus | ||
) | ||
} | ||
|
||
fun generateRestaurantEntity( | ||
id: Long = 0, | ||
name: String = "default_name", | ||
originalCategories: String = "default_category", | ||
reviewCount: Long = 0, | ||
likeCount: Long = 0, | ||
address: String = "default_address", | ||
contactNumber: String = "default_number", | ||
ratingAvg: Double = 0.0, | ||
representativeImageUrl: String = "default_image_url", | ||
viewCount: Long = 0, | ||
discountContent: String? = null, | ||
menus: MutableList<Menu> = mutableListOf() | ||
): Restaurant { | ||
return Restaurant( | ||
id = id, | ||
name = name, | ||
originalCategories = originalCategories, | ||
reviewCount = reviewCount, | ||
likeCount = likeCount, | ||
address = address, | ||
contactNumber = contactNumber, | ||
ratingAvg = ratingAvg, | ||
representativeImageUrl = representativeImageUrl, | ||
viewCount = viewCount, | ||
discountContent = discountContent, | ||
menus = menus | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.