-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#24] test: 상품 목록 조회에 대한 test code 작성
- Loading branch information
chung
committed
Jun 28, 2023
1 parent
91d6ddf
commit 38800ef
Showing
3 changed files
with
71 additions
and
2 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
56 changes: 56 additions & 0 deletions
56
be/kiosk/src/test/java/team/five/kiosk/service/ProductServiceTest.java
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,56 @@ | ||
package team.five.kiosk.service; | ||
|
||
import org.assertj.core.api.Assertions; | ||
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.jdbc.core.namedparam.MapSqlParameterSource; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import team.five.kiosk.dto.ResponseProduct; | ||
import team.five.kiosk.repository.ProductRepository; | ||
|
||
import java.util.List; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
class ProductServiceTest { | ||
|
||
@Autowired ProductService productService; | ||
@Autowired ProductRepository productRepository; | ||
@Autowired NamedParameterJdbcTemplate jdbcTemplate; | ||
|
||
|
||
@Test | ||
@DisplayName("카테고리명이 주어졌을 때 해당하는 메뉴의 개수가 옳게 나오는지 테스트") | ||
public void checkProductSizeByCategory() throws Exception { | ||
//given | ||
createSalesLog(2, 12); | ||
|
||
//when | ||
List<ResponseProduct> products = productService.getProducts("coffee"); | ||
|
||
//then | ||
Assertions.assertThat(products.size()).isEqualTo(4); | ||
} | ||
|
||
@Test | ||
@DisplayName("주어진 카테고리와 db의 카테고리의 이름이 맞는지 확인하는 테스트") | ||
public void checkCategoryName() throws Exception { | ||
//given | ||
String wrongName = "coff"; | ||
|
||
//when | ||
Assertions.assertThatThrownBy(() -> productService.getProducts(wrongName)) | ||
.isInstanceOf(IllegalStateException.class); | ||
} | ||
|
||
private void createSalesLog(final int productId, final int count) { | ||
String sql = "insert into sales_log (product_id, count) values(:productId, :count)"; | ||
MapSqlParameterSource params = new MapSqlParameterSource(); | ||
params.addValue("productId", productId); | ||
params.addValue("count", count); | ||
jdbcTemplate.update(sql, params); | ||
} | ||
} |