-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feature/product testcode #57
Changes from 17 commits
47230d2
0e0b953
cad3149
919c7c2
37f1e0e
818ff84
f91cd89
64125ee
03de4b9
f5218ba
2746aad
5f9c5de
ffb1095
bd26605
aaba17c
b678a34
20beabb
45d60da
b32d9ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,9 @@ services: | |
|
||
# batch: | ||
# build: ./module-batch | ||
# image: ${IMAGE} | ||
# ports: | ||
# - "8082:8080" | ||
# - "8082:8082" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐๐ป |
||
# depends_on: | ||
# - db-edit | ||
# | ||
|
@@ -36,7 +37,7 @@ services: | |
# db-read: | ||
# image: younglong/pg-washpedia:latest | ||
# volumes: | ||
# - postgreEditDB:/var/lib/postgresql/data | ||
# - ./postgreEditDB:/var/lib/postgresql/data | ||
# environment: | ||
# POSTGRES_DB: read_db | ||
# POSTGRES_USER: ${{ secrets.PROJECT_USER }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the code patch you provided, here are some of the improvements and bug risks I can identify:
Additionally, it would be helpful to review other parts of the codebase, including Dockerfile, environment variables, and any additional services or functionality not included in the given patch. |
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๋ด์ฉ์ ๋ํด ๊ฐ๋ตํ๊ฒ ์ค๋ช
ํด์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์์~ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lombok.anyConstructor.addConstructorProperties=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
/** | ||
* DTO for {@link com.kernel360.member.entity.Member} | ||
*/ | ||
public record MemberDto(Integer memberNo, | ||
public record MemberDto(Long memberNo, | ||
String id, | ||
String email, | ||
String password, | ||
|
@@ -21,7 +21,7 @@ public record MemberDto(Integer memberNo, | |
) { | ||
|
||
public static MemberDto of( | ||
Integer memberNo, | ||
Long memberNo, | ||
String id, | ||
String email, | ||
String password, | ||
|
@@ -66,12 +66,12 @@ public static MemberDto from(Member entity) { | |
|
||
public Member toEntity(MemberDto memberDto) { | ||
return Member.of( | ||
this.memberNo, | ||
this.id, | ||
this.email, | ||
this.password, | ||
this.gender, | ||
this.birthdate | ||
memberDto.memberNo(), | ||
memberDto.id(), | ||
memberDto.email(), | ||
memberDto.password(), | ||
memberDto.gender(), | ||
memberDto.birthdate() | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด๊ฑฐ ์ด๋๋ก๋ฉด memberDto.toEntity(memberDto) ๊ฐ์ ํํ๋ก ํธ์ถ๋๊ฒ ๋ ๊ฒ ๊ฐ์๋ฐ์ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ํ์ธํด๋ดค๋๋ฐ this๋ก ๋ณด๋ด๋ memberDto๋ก ๋ณด๋ด๋ ๋๋ค toEntity(memberDto)๋ก ํด์ค์ผ๋ฉ๋๋ค. |
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overall, the code patch looks fine with a few suggestions for improvement:
Besides these suggestions, ensure that the changes made match the requirements of your application, as I can only provide general code review suggestions based on the given information. |
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixture monkey ์ฌ์ฉ ์์๊ฐ ์๊ฒจ์ ์ข๋ค์ ๐ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.kernel360.product.dto; | ||
|
||
import com.kernel360.product.entity.Product; | ||
import com.navercorp.fixturemonkey.FixtureMonkey; | ||
import com.navercorp.fixturemonkey.api.introspector.*; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
|
||
class ProductDtoTest { | ||
private FixtureMonkey fixtureMonkey; | ||
|
||
@BeforeEach | ||
void ์ค๋น() { | ||
fixtureMonkey = FixtureMonkey.builder() | ||
.objectIntrospector(new FailoverIntrospector( | ||
Arrays.asList( | ||
FieldReflectionArbitraryIntrospector.INSTANCE, | ||
ConstructorPropertiesArbitraryIntrospector.INSTANCE, | ||
BeanArbitraryIntrospector.INSTANCE, | ||
BuilderArbitraryIntrospector.INSTANCE | ||
) | ||
)) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void ์ํฐํฐ๊ฐ์ฒด๋ฅผ_ProductDto๊ฐ์ฒด๋ก_์_๋ณํํ๋์ง() { | ||
//given | ||
Product product = fixtureMonkey.giveMeBuilder(Product.class).sample(); | ||
ProductDto productDto = ProductDto.from(product); | ||
|
||
//then | ||
assertEquals(product.getProductName(), productDto.productName()); | ||
assertEquals(product.getProductNo(), productDto.productNo()); | ||
assertEquals(product.getViewCount(), productDto.viewCount()); | ||
assertEquals(product.getIsViolation(), productDto.isViolation()); | ||
assertEquals(product.getBarcode(), productDto.barcode()); | ||
assertEquals(product.getDeclareNo(), productDto.declareNo()); | ||
assertEquals(product.getDescription(), productDto.description()); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.kernel360.product.service; | ||
|
||
import com.kernel360.product.dto.ProductDto; | ||
import com.kernel360.product.entity.Product; | ||
import com.kernel360.product.repository.ProductRepository; | ||
import com.navercorp.fixturemonkey.FixtureMonkey; | ||
import com.navercorp.fixturemonkey.api.introspector.FieldReflectionArbitraryIntrospector; | ||
import com.navercorp.fixturemonkey.jakarta.validation.plugin.JakartaValidationPlugin; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
class ProductServiceTest { | ||
private FixtureMonkey fixtureMonkey; | ||
private ProductRepository productRepository; | ||
private ProductService productService; | ||
@BeforeEach | ||
void ํ ์คํธ์ค๋น() { | ||
fixtureMonkey = FixtureMonkey.builder() | ||
.objectIntrospector(FieldReflectionArbitraryIntrospector.INSTANCE) | ||
.plugin(new JakartaValidationPlugin()) | ||
.build(); | ||
|
||
productRepository = mock(ProductRepository.class); | ||
productService = new ProductService(productRepository); | ||
} | ||
|
||
@Test | ||
void ์์ด๋๋ก_์ ํ์ฐพ๊ธฐ() { | ||
|
||
Product product = fixtureMonkey.giveMeBuilder(Product.class) | ||
.set("productNo", 1L) | ||
.sample(); | ||
|
||
when(productRepository.findById(1L)).thenReturn(Optional.of(product)); | ||
Optional<Product> foundProduct = productService.getProductById(1L); | ||
|
||
then(foundProduct).isPresent(); | ||
then(foundProduct.get()).isEqualTo(product); | ||
} | ||
|
||
@Test | ||
void ์ ์ฒด_์ ํ_๋ชฉ๋ก_์กฐํ(){ | ||
//given | ||
List<Product> products = fixtureMonkey.giveMe(Product.class, 3); | ||
//when | ||
when(productRepository.findAll()).thenReturn(products); | ||
List<Product> productList = productService.getProductList(); | ||
//then | ||
then(productList).isEqualTo(products); | ||
} | ||
|
||
@Test | ||
void ํค์๋๋ก_์ ํ_๋ชฉ๋ก_์กฐํ(){ | ||
//given | ||
List<Product> products = new ArrayList<>(); | ||
String keyword = "sample"; | ||
|
||
for (int i = 0; i < 5; i++) { | ||
Product product = fixtureMonkey.giveMeBuilder(Product.class) | ||
.set("productName", keyword + i) // Append a unique number to each productName | ||
.sample(); | ||
products.add(product); | ||
} | ||
//when | ||
when(productRepository.findByKeyword(keyword)).thenReturn(products); | ||
List<ProductDto> productListByKeyword = productService.getProductListByKeyword(keyword); | ||
//then | ||
then(productListByKeyword).hasSize(5); | ||
then(productListByKeyword).allSatisfy(productDto -> then(productDto.productName()).contains(keyword)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ดํ์๋ PR์ ๊ตฌ๋ถํด์ ์ฌ๋ ค์ฃผ์๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ์์!
PR ๋ช ๊ณผ ๋ด๋ถ ์์ ์ฌํญ์ด ๋ค๋ฅธ ๋ถ๋ถ๋ค์ด ์์ด์ ๋์ค์ ์ด๋ ฅ ๊ด๋ฆฌ๊ฐ ์ด๋ ค์ธ ์๋ ์์ง ์์๊น์!?