Skip to content

Commit

Permalink
Merge pull request #25 from Caramel1004/test/#21
Browse files Browse the repository at this point in the history
[#21][TEST]Repository Test
  • Loading branch information
Caramel1004 authored May 9, 2024
2 parents 7cbf204 + 0fe6cdb commit 2c89b12
Show file tree
Hide file tree
Showing 10 changed files with 544 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ public RemittanceQuoteEntityV2 toEntity (RemittanceQuoteV2DTO dto) {
.build();
}

public static RemittanceQuoteV2DTO of (RemittanceQuoteEntityV2 dto) {
if(dto == null) {
public static RemittanceQuoteV2DTO of (RemittanceQuoteEntityV2 entity) {
if(entity == null) {
throw new NullPointerQuotationException(BAD_NOT_MATCH_QUOTATION);
}
return RemittanceQuoteV2DTO.builder()
.sourceAmount(dto.getSourceAmount())// 원화
.fee(new BigDecimal(String.valueOf(dto.getFee())))// 수수료
.usdExchangeRate(dto.getUsdExchangeRate())
.usdAmount(dto.getUsdAmount())// USD 송금액
.targetCurrency(dto.getTargetCurrency())
.targetAmount(dto.getTargetAmount())// 받는 금액
.exchangeRate(dto.getExchangeRate())
.expireTime(dto.getExpireTime())// 송금 견적서 만료 기간
.sourceAmount(entity.getSourceAmount())// 원화
.fee(new BigDecimal(String.valueOf(entity.getFee())))// 수수료
.usdExchangeRate(entity.getUsdExchangeRate())
.usdAmount(entity.getUsdAmount())// USD 송금액
.targetCurrency(entity.getTargetCurrency())
.targetAmount(entity.getTargetAmount())// 받는 금액
.exchangeRate(entity.getExchangeRate())
.expireTime(entity.getExpireTime())// 송금 견적서 만료 기간
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ public class MemberEntityV2 {

@Column(name = "ID_VALUE", nullable = false)
private String idValue;

@Override
public String toString() {
return "MemberEntityV2 {" + "\n" +
"\tindex: " + index + ",\n" +
"\tuserId: '" + userId + '\''+ ",\n" +
"\tpassword: '" + password+ '\'' + ",\n" +
"\tname: '" + name+ '\'' + ",\n" +
"\tidType: '" + idType+ '\'' + ",\n" +
"\tidValue: '" + idValue + '\'' + ",\n" +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,20 @@ public class RemittanceLogEntityV2 {

@Column(name = "user_id", nullable = false)
private String userId;

@Override
public String toString() {
return "RemittanceLogEntityV2 {" + "\n" +
"\tlogId: " + logId + ",\n" +
"\tsourceAmount: " + sourceAmount + ",\n" +
"\tfee: " + fee + ",\n" +
"\tusdExchangeRate: " + usdExchangeRate + ",\n" +
"\tusdAmount: " + usdAmount + ",\n" +
"\ttargetCurrency: '" + targetCurrency + '\'' + ",\n" +
"\ttargetAmount: " + targetAmount + ",\n" +
"\texchangeRate: " + exchangeRate + ",\n" +
"\texpireTime: " + requestedDate + ",\n" +
"\tuserId: '" + userId + '\'' + ",\n" +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.moin.remittance.domain.entity.remittance.v2;

import jakarta.persistence.*;
import jakarta.validation.constraints.Positive;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -24,6 +25,7 @@ public class RemittanceQuoteEntityV2 {

// 송금 할 금액(원화)
@Column(name = "source_amount", nullable = false)
@Positive
private long sourceAmount;

// 수수료 = 보내는금액(amount: 원화) * 수수료율 + 고정 수수료
Expand All @@ -36,6 +38,7 @@ public class RemittanceQuoteEntityV2 {

// USD 송금액
@Column(name = "usd_amount", nullable = false)
@Positive
private BigDecimal usdAmount;

// 받는 환율 정보
Expand All @@ -48,6 +51,7 @@ public class RemittanceQuoteEntityV2 {

// 받는 금액
@Column(name = "target_amount", nullable = false)
@Positive
private BigDecimal targetAmount;

// 만료 기간
Expand All @@ -56,4 +60,20 @@ public class RemittanceQuoteEntityV2 {

@Column(name = "user_id", nullable = false)
private String userId;

@Override
public String toString() {
return "RemittanceQuoteEntityV2 {" + "\n" +
"\tquoteId: " + quoteId + ",\n" +
"\tsourceAmount: " + sourceAmount + ",\n" +
"\tfee: " + fee + ",\n" +
"\tusdExchangeRate: " + usdExchangeRate + ",\n" +
"\tusdAmount: " + usdAmount + ",\n" +
"\ttargetCurrency: '" + targetCurrency + '\'' + ",\n" +
"\ttargetAmount: " + targetAmount + ",\n" +
"\texchangeRate: " + exchangeRate + ",\n" +
"\texpireTime: " + expireTime + ",\n" +
"\tuserId: '" + userId + '\'' + ",\n" +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.lang.reflect.Member;
import java.util.UUID;

@Repository
Expand All @@ -17,4 +18,7 @@ public interface MemberRepositoryV2 extends JpaRepository<MemberEntityV2, UUID>

@Query(value = "select name from member_v2 where user_id = :userId", nativeQuery = true)
String getNameOfMemberByUserId(String userId);

/* TEST Query Method*/
MemberEntityV2 findByUserIdAndPassword(String userId, String password);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
@Repository
public interface RemittanceLogRepositoryV2 extends JpaRepository<RemittanceLogEntityV2, UUID> {
List<RemittanceLogEntityV2> findByUserId(String userId);

/* 테스트 용 쿼리 메소드 */
boolean existsByUserId(String userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
public interface RemittanceRepositoryV2 extends JpaRepository<RemittanceQuoteEntityV2, UUID> {
// 송금 견적서 조회
RemittanceQuoteEntityV2 findByQuoteIdAndUserId(UUID quoteId, String userId);

boolean existsByQuoteIdAndUserId(UUID quoteId, String userId);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.moin.remittance.repository.v2;

import com.moin.remittance.domain.entity.member.v2.MemberEntityV2;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;


@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY) // 가짜 DB로 테스트
@ExtendWith(SpringExtension.class)
public class MemberRepositoryV2Test {

@Autowired
private MemberRepositoryV2 memberRepositoryV2;

private MemberEntityV2 createMemberTestCase(
String userId, String password, String name, String idType, String idValue
) {
return MemberEntityV2.builder()
.userId(userId)
.password(password)
.name(name)
.idType(idType)
.idValue(idValue)
.build();
}

/**
* 회원가입
* 유저데이터 저장 -> 유저 조회 where(유저아이디, 비밀번호)
*/
@BeforeEach
@Test
@DisplayName("회원 저장")
void saveUserTest() {
String REG_NO = "REG_NO";
String BUSINESS_NO = "BUSINESS_NO";
// given: 회원 엔티티
MemberEntityV2 member1 = createMemberTestCase(
"[email protected]", "1234", "카라멜프라프치노", REG_NO, "111111-1111111"
);
MemberEntityV2 member2 = createMemberTestCase(
"[email protected]", "3333", "자바칩프라푸치노", REG_NO, "222222-2222222"
);
MemberEntityV2 member3 = createMemberTestCase(
"[email protected]", "3333", "(주) 컴포즈", BUSINESS_NO, "222222-2222222"
);

// when: 회원 저장
MemberEntityV2 savedMember1 = memberRepositoryV2.save(member1);
MemberEntityV2 savedMember2 = memberRepositoryV2.save(member2);
MemberEntityV2 savedMember3 = memberRepositoryV2.save(member3);

// then: junit 메소드로 값 비교
assertEquals(member1, savedMember1);
assertEquals(member2, savedMember2);
assertEquals(member3, savedMember3);

// then: PK가 잘 생성되었는지 확인
assertNotNull(savedMember1.getIndex());
assertNotNull(savedMember2.getIndex());
assertNotNull(savedMember3.getIndex());
assertNotEquals(member1, savedMember2);
assertNotEquals(member2, savedMember1);
assertNotEquals(savedMember1, savedMember2);
assertNotEquals(savedMember1, savedMember3);
}

/**
* 회원가입 -> 로그인
*/
@Test
@DisplayName("Parameter: 유저아이디, 비밀번호 => 회원 조회")
void findByUserIdAndPasswordTest() {
// then: 회원 조회
assertTrue(memberRepositoryV2.existsByUserIdAndPassword("[email protected]", "1234")); // true && true == true
assertFalse(memberRepositoryV2.existsByUserIdAndPassword("[email protected]", "123")); // true && false == false
assertFalse(memberRepositoryV2.existsByUserIdAndPassword("[email protected]", "1234")); // false && true == false
assertFalse(memberRepositoryV2.existsByUserIdAndPassword("[email protected]", "123")); // false && false == false

// Test Data 확인
System.out.println("====** 회원 조회 **====");
System.out.println("====↑↑ Test Data ↑↑====");
System.out.println(memberRepositoryV2.findByUserIdAndPassword("[email protected]", "1234"));
}

@Test
@DisplayName("모든 회원 조회")
void findAllMember() {
List<MemberEntityV2> dataAll = memberRepositoryV2.findAll();

// then: Not Null 체크
dataAll.forEach(data -> {
assertNotNull(data);
assertNotNull(data.getIndex());
assertNotNull(data.getUserId());
assertNotNull(data.getPassword());
assertNotNull(data.getName());
assertNotNull(data.getIdType());
assertNotNull(data.getIdValue());
});

// Test Data 확인
System.out.println("====** 모든 회원 조회 **====");
System.out.println("====↑↑ Test Data ↑↑====");
dataAll.forEach(System.out::println);
}

}
Loading

0 comments on commit 2c89b12

Please sign in to comment.