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

Feature/product testcode #57

Merged
merged 19 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
47230d2
git commit -m "feature::docker-compose, github action CI"
HyunJunSon Jan 4, 2024
0e0b953
feat: flyway sql modify
linglong67 Jan 4, 2024
cad3149
Create cr.yml
linglong67 Jan 5, 2024
919c7c2
feat : JasyptEncryptor ์ถ”๊ฐ€
chan99k Jan 4, 2024
37f1e0e
chore : ์•”ํ˜ธ๋ฌธ ๋ณ€๊ฒฝ (์›๋ณธ ๋ฌธ์ž์—ด์— ์ฐจ์ด๋Š” ์—†์Šต๋‹ˆ๋‹ค)
chan99k Jan 4, 2024
818ff84
chore : jasypt ์˜์กด์„ฑ ์ถ”๊ฐ€
chan99k Jan 4, 2024
f91cd89
Update cr.yml
linglong67 Jan 5, 2024
64125ee
Update cr.yml
linglong67 Jan 5, 2024
03de4b9
Update cr.yml
linglong67 Jan 5, 2024
f5218ba
Update cr.yml
linglong67 Jan 5, 2024
2746aad
feature::docker + githubActions CI๊ธฐ๋Šฅ์ถ”๊ฐ€
HyunJunSon Jan 5, 2024
5f9c5de
Merge branch 'feature/docker' of https://github.com/HyunJunSon/F1-Wasโ€ฆ
HyunJunSon Jan 5, 2024
ffb1095
Merge branch 'develop' of https://github.com/HyunJunSon/F1-WashPedia โ€ฆ
HyunJunSon Jan 10, 2024
bd26605
Merge branch 'develop' of https://github.com/HyunJunSon/F1-WashPedia โ€ฆ
HyunJunSon Jan 11, 2024
aaba17c
Merge branch 'develop' of https://github.com/HyunJunSon/F1-WashPedia โ€ฆ
HyunJunSon Jan 11, 2024
b678a34
Merge branch 'develop' of https://github.com/HyunJunSon/F1-WashPedia โ€ฆ
HyunJunSon Jan 12, 2024
20beabb
feat::product testCode ์ž‘์„ฑ
HyunJunSon Jan 15, 2024
45d60da
feat::product testCode2 ์ž‘์„ฑ
HyunJunSon Jan 15, 2024
b32d9ec
feat::product controller testCode ์ถ”๊ฐ€
HyunJunSon Jan 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docker-compose.yml
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ดํ›„์—๋Š” PR์„ ๊ตฌ๋ถ„ํ•ด์„œ ์˜ฌ๋ ค์ฃผ์‹œ๋Š” ๊ฒŒ ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”!
PR ๋ช…๊ณผ ๋‚ด๋ถ€ ์ž‘์—… ์‚ฌํ•ญ์ด ๋‹ค๋ฅธ ๋ถ€๋ถ„๋“ค์ด ์žˆ์–ด์„œ ๋‚˜์ค‘์— ์ด๋ ฅ ๊ด€๋ฆฌ๊ฐ€ ์–ด๋ ค์šธ ์ˆ˜๋„ ์žˆ์ง€ ์•Š์„๊นŒ์š”!?

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ services:

# batch:
# build: ./module-batch
# image: ${IMAGE}
# ports:
# - "8082:8080"
# - "8082:8082"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐Ÿ‘๐Ÿป

# depends_on:
# - db-edit
#
Expand All @@ -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 }}
Copy link

Choose a reason for hiding this comment

The 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:

  1. The commented batch service image line (line 12) should be uncommented if you want to use a specific image. If you are using a custom image, make sure it is properly defined in the docker-compose.yml or specify it using the ${IMAGE} variable.

  2. Port mapping for the batch service (lines 14-15) seems to be incorrect. Port 8080 should be mapped to 8082 instead of mapping 8082 to 8080. Adjust it like this: - "8080:8082".

  3. Make sure the necessary dependencies (db-edit, db-read) are available when running the batch service. Verify that they are correctly specified in the depends_on section.

  4. For the db-read service (lines 35-37), check if the volume mapping is correct. It currently points to ./postgreEditDB, which may cause issues if the directory doesn't exist. Make sure the path is accurate, and the PostgreSQL data will be properly persisted.

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.

Expand Down
7 changes: 6 additions & 1 deletion module-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'

// validataion
implementation 'org.springframework.boot:spring-boot-starter-validation:2.7.4'
// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
// test - fixture Monkey
testImplementation 'net.jqwik:jqwik:1.7.3'
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:1.0.0")
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-jakarta-validation:1.0.0")
}

tasks.named('test') {
Expand Down
1 change: 1 addition & 0 deletions module-api/lombok.config
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Up @@ -7,7 +7,7 @@
/**
* DTO for {@link com.kernel360.commoncode.entity.CommonCode}
*/
public record CommonCodeDto(Integer codeNo,
public record CommonCodeDto(Long codeNo,
String codeName,
Integer upperNo,
String upperName,
Expand All @@ -25,7 +25,7 @@ public record CommonCodeDto(Integer codeNo,
* **/

public static CommonCodeDto of(
Integer codeNo,
Long codeNo,
String codeName,
Integer upperNo,
String upperName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +21,7 @@ public record MemberDto(Integer memberNo,
) {

public static MemberDto of(
Integer memberNo,
Long memberNo,
String id,
String email,
String password,
Expand Down Expand Up @@ -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()
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๊ฑฐ ์ด๋Œ€๋กœ๋ฉด memberDto.toEntity(memberDto) ๊ฐ™์€ ํ˜•ํƒœ๋กœ ํ˜ธ์ถœ๋˜๊ฒŒ ๋  ๊ฒƒ ๊ฐ™์€๋ฐ์š”
memberDto.toEntity() ํ˜•ํƒœ๊ฐ€ ๋” ๋‚˜์•„๋ณด์—ฌ์š”! (๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์˜๋ฏธ๊ฐ€ ์žˆ์„๊นŒ ์‹ถ์–ด์„œ์š”)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ™•์ธํ•ด๋ดค๋Š”๋ฐ this๋กœ ๋ณด๋‚ด๋‚˜ memberDto๋กœ ๋ณด๋‚ด๋‚˜ ๋‘˜๋‹ค toEntity(memberDto)๋กœ ํ•ด์ค˜์•ผ๋ฉ๋‹ˆ๋‹ค.
ํšŒ์› ๊ฐ€์ž…, ๋กœ๊ทธ์ธ ๊ตฌํ˜„ํ•˜๋Š” ๋™์•ˆ์€ member์ •๋ณด๋ฅผ ํ†ต์œผ๋กœ ๋ฐ”์ธ๋”ฉ ํ•  ์ผ์ด ์—†์–ด์„œ toEntity๋ฅผ ์“ฐ์ง€ ์•Š์•˜๋Š”๋ฐ
์ด๋Ÿฐ ๊ณ ๋ฏผ์ด ์žˆ๊ฒ ๊ตฌ๋‚˜ ํ•˜๋Š”๊ฑธ ์ด์ œ์•ผ ์•Œ์•˜๋„ค์š”

}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the code patch looks fine with a few suggestions for improvement:

  1. Data Type: The memberNo field in MemberDto has been changed from Integer to Long. Make sure this change is intentional and aligns with the data type in the Member entity.

  2. Redundant Parameters: In the of method of MemberDto, you can remove the parameters memberNo and memberDto, as they are not used within the method.

  3. Method Naming: Instead of having toEntity() accept a MemberDto parameter, it can directly access the fields of the current object. You can omit the parameter and modify the method to public Member toEntity(). This aligns with how other methods are written.

  4. Code Formatting: Ensure consistent indentation and formatting throughout the code. It helps with readability.

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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

Expand All @@ -26,6 +27,7 @@ public class MemberService {
/**
* ๊ฐ€์ž…
**/
@Transactional
public void joinMember(MemberDto requestDto) {

Member entity = getNewJoinMemberEntity(requestDto);
Expand All @@ -43,6 +45,7 @@ protected Member getNewJoinMemberEntity(MemberDto requestDto) {
/**
* ๋กœ๊ทธ์ธ
**/
@Transactional
public MemberDto login(MemberDto loginDto) {

Member loginEntity = getReqeustLoginEntity(loginDto);
Expand All @@ -67,7 +70,7 @@ protected Auth modifyAuthJwt(Auth modifyAuth, String encryptToken) {
return modifyAuth;
}

protected Auth createAuthJwt(Integer memberNo, String encryptToken) {
protected Auth createAuthJwt(Long memberNo, String encryptToken) {

return Auth.of(null, memberNo, encryptToken, null);
}
Expand All @@ -78,14 +81,14 @@ private Member getReqeustLoginEntity(MemberDto loginDto) {

return Member.loginMember(loginDto.id(), encodePassword);
}


@Transactional(readOnly = true)
public boolean duplicatedCheckId(String id) {
Member member = memberRepository.findOneById(id);

return member != null;
}

@Transactional(readOnly = true)
public boolean duplicatedCheckEmail(String email) {
Member member = memberRepository.findOneByEmail(email);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,33 @@
import com.kernel360.product.repository.ProductRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class ProductService {

private final ProductRepository productRepository;

@Transactional(readOnly = true)
public Optional<Product> getProductById(Long id) {

return productRepository.findById(id);
}

@Transactional(readOnly = true)
public List<Product> getProductList() {

return productRepository.findAll();
}

@Transactional(readOnly = true)
public List<ProductDto> getProductListByKeyword(String keyword) {
List<Product> products = productRepository.findByKeyword(keyword);

return products.stream().map(ProductDto::from).toList();
}

}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class Auth extends BaseEntity {
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "auth_id_gen")
@SequenceGenerator(name = "auth_id_gen", sequenceName = "auth_auth_no_seq")
@Column(name = "auth_no", nullable = false)
private Integer authNo;
private Long authNo;

@Column(name = "member_no")
private Integer memberNo;
private Long memberNo;

@Column(name = "jwt_token")
private String jwtToken;
Expand All @@ -32,31 +32,31 @@ public class Auth extends BaseEntity {
/**
* all create
**/
public static Auth of(Integer authNo, Integer memberNo, String jwtToken, String snsToken) {
public static Auth of(Long authNo, Long memberNo, String jwtToken, String snsToken) {

return new Auth(authNo, memberNo, jwtToken, snsToken);
}

/**
* all binding
**/
private Auth(Integer authNo, Integer memberNo, String jwtToken, String snsToken) {
private Auth(Long authNo, Long memberNo, String jwtToken, String snsToken) {
this.authNo = authNo;
this.memberNo = memberNo;
this.jwtToken = jwtToken;
this.snsToken = snsToken;
}


public static Auth jwt(Integer authNo, Integer memberNo, String jwtToken) {
public static Auth jwt(Long authNo, Long memberNo, String jwtToken) {

return new Auth(authNo, memberNo, jwtToken);
}

/**
* JWT
**/
private Auth(Integer authNo, Integer memberNo, String jwtToken) {
private Auth(Long authNo, Long memberNo, String jwtToken) {
this.authNo = authNo;
this.memberNo = memberNo;
this.jwtToken = jwtToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

public interface AuthRepository extends JpaRepository <Auth, Id> {

Auth findOneByMemberNo(Integer memberNo);
Auth findOneByMemberNo(Long memberNo);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity {
public abstract class BaseEntity {

private static final int MAX_STRING_LENGTH = 255;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class CommonCode extends BaseEntity {
@Id
@Column(name = "code_no", nullable = false)
private Integer codeNo;
private Long codeNo;

@Column(name = "code_name", nullable = false, length = Integer.MAX_VALUE)
private String codeName;
Expand Down
Loading
Loading