입출금 내역 정보 클래스 생성 및 테스트 코드
This commit is contained in:
		
							parent
							
								
									51d1d52654
								
							
						
					
					
						commit
						135f2ff492
					
				| @ -50,6 +50,18 @@ public class DbInitializer implements CommandLineRunner { | ||||
|           .build(); | ||||
| 
 | ||||
|       userRepository.save(user); | ||||
|       user = UserEntity.builder().username("test1").password(passwordEncoder.encode("qwer5795")).nickname("test1") | ||||
|               .email("test1@example.com").block(false).resetCount(0L).sendEmail(true).roles(Stream.of(RoleEntity.builder().id(Short.valueOf((short) 2)).build()) | ||||
|                       .collect(Collectors.toCollection(HashSet::new))) | ||||
|               .build(); | ||||
|       userRepository.save(user); | ||||
| 
 | ||||
|       user = UserEntity.builder().username("test2").password(passwordEncoder.encode("qwer5795")).nickname("test2") | ||||
|               .email("test1@example.com").block(false).resetCount(0L).sendEmail(true).roles(Stream.of(RoleEntity.builder().id(Short.valueOf((short) 2)).build()) | ||||
|                       .collect(Collectors.toCollection(HashSet::new))) | ||||
|               .build(); | ||||
| 
 | ||||
|       userRepository.save(user); | ||||
|     } | ||||
| 
 | ||||
|     System.out.println(" -- Database has been initialized"); | ||||
|  | ||||
| @ -29,15 +29,15 @@ public class BankAccountEntity extends UserDateAuditEntity { | ||||
|   private String holder; | ||||
| 
 | ||||
|   @Basic | ||||
|   @Column(name = "username", nullable = false) | ||||
|   private String username; | ||||
|   @Column(name = "userId", nullable = false) | ||||
|   private Long userId; | ||||
| 
 | ||||
|   public BankAccountEntity(Long id, String name, String number, String holder, String username) { | ||||
|   public BankAccountEntity(Long id, String name, String number, String holder, Long userId) { | ||||
|     this.id = id; | ||||
|     this.name = name; | ||||
|     this.number = number; | ||||
|     this.holder = holder; | ||||
|     this.username = username; | ||||
|     this.userId = userId; | ||||
|   } | ||||
| 
 | ||||
|   public BankAccountEntity() { | ||||
| @ -59,10 +59,6 @@ public class BankAccountEntity extends UserDateAuditEntity { | ||||
|     return this.holder; | ||||
|   } | ||||
| 
 | ||||
|   public String getUsername() { | ||||
|     return this.username; | ||||
|   } | ||||
| 
 | ||||
|   public void setId(Long id) { | ||||
|     this.id = id; | ||||
|   } | ||||
| @ -79,12 +75,16 @@ public class BankAccountEntity extends UserDateAuditEntity { | ||||
|     this.holder = holder; | ||||
|   } | ||||
| 
 | ||||
|   public void setUsername(String username) { | ||||
|     this.username = username; | ||||
|   public Long getUserId() { | ||||
|     return userId; | ||||
|   } | ||||
| 
 | ||||
|   public void setUserId(Long userId) { | ||||
|     this.userId = userId; | ||||
|   } | ||||
| 
 | ||||
|   public String toString() { | ||||
|     return "BankAccountEntity(id=" + this.getId() + ", name=" + this.getName() + ", number=" + this.getNumber() + ", holder=" + this.getHolder() + ", username=" + this.getUsername() + ")"; | ||||
|     return "BankAccountEntity(id=" + this.getId() + ", name=" + this.getName() + ", number=" + this.getNumber() + ", holder=" + this.getHolder() + ", username=" + this.getUserId() + ")"; | ||||
|   } | ||||
| 
 | ||||
|   public boolean equals(final Object o) { | ||||
| @ -104,9 +104,9 @@ public class BankAccountEntity extends UserDateAuditEntity { | ||||
|     final Object this$holder = this.getHolder(); | ||||
|     final Object other$holder = other.getHolder(); | ||||
|     if (this$holder == null ? other$holder != null : !this$holder.equals(other$holder)) return false; | ||||
|     final Object this$username = this.getUsername(); | ||||
|     final Object other$username = other.getUsername(); | ||||
|     if (this$username == null ? other$username != null : !this$username.equals(other$username)) return false; | ||||
|     final Object this$userId = this.getUserId(); | ||||
|     final Object other$userId = other.getUserId(); | ||||
|     if (this$userId == null ? other$userId != null : !this$userId.equals(other$userId)) return false; | ||||
|     return true; | ||||
|   } | ||||
| 
 | ||||
| @ -125,7 +125,7 @@ public class BankAccountEntity extends UserDateAuditEntity { | ||||
|     result = result * PRIME + ($number == null ? 43 : $number.hashCode()); | ||||
|     final Object $holder = this.getHolder(); | ||||
|     result = result * PRIME + ($holder == null ? 43 : $holder.hashCode()); | ||||
|     final Object $username = this.getUsername(); | ||||
|     final Object $username = this.getUserId(); | ||||
|     result = result * PRIME + ($username == null ? 43 : $username.hashCode()); | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
| @ -0,0 +1,43 @@ | ||||
| package com.totopia.server.modules.user.entity; | ||||
| 
 | ||||
| import com.totopia.server.commons.data.entity.UserDateAuditEntity; | ||||
| import com.totopia.server.modules.user.type.ProcessingStatus; | ||||
| import lombok.*; | ||||
| import lombok.experimental.SuperBuilder; | ||||
| 
 | ||||
| import javax.persistence.*; | ||||
| import java.io.Serializable; | ||||
| import java.util.Objects; | ||||
| 
 | ||||
| @Entity(name = "deposit") | ||||
| @SuperBuilder | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| @Getter | ||||
| @Setter | ||||
| @ToString | ||||
| @Data | ||||
| public class DepositEntity extends UserDateAuditEntity implements Serializable { | ||||
| 
 | ||||
|     @Id | ||||
|     @GeneratedValue(generator = "deposit_generator") | ||||
|     @SequenceGenerator(name = "deposit_generator", sequenceName = "deposit_sequence", initialValue = 1) | ||||
|     private Long id; | ||||
| 
 | ||||
|     @Column(name = "amount_of_money", nullable = false) | ||||
|     private Integer amountOfMoney; | ||||
| 
 | ||||
|     @Column(name = "deposit_user", nullable = false) | ||||
|     private Long depositUser; | ||||
| 
 | ||||
|     @Column(name = "confirm_user", nullable = false) | ||||
|     private Long confirmUser; | ||||
| 
 | ||||
|     @Column(name = "bank_account", nullable = false) | ||||
|     private Long bankAccount; | ||||
| 
 | ||||
|     @Enumerated(EnumType.STRING) | ||||
|     @Column(name = "status", length = 60) | ||||
|     private ProcessingStatus status; | ||||
| 
 | ||||
| } | ||||
| @ -9,13 +9,16 @@ import java.util.Date; | ||||
| import java.util.Set; | ||||
| 
 | ||||
| @Entity | ||||
| @Table(name = "users", uniqueConstraints = { @UniqueConstraint(columnNames = { "username" }), | ||||
|     @UniqueConstraint(columnNames = { "email" }) }) | ||||
| @Table(name = "users") | ||||
| @SuperBuilder | ||||
| public class UserEntity extends DateAuditEntity { | ||||
|   private static final long serialVersionUID = 8891163223262220481L; | ||||
| 
 | ||||
|   @Id | ||||
|   @GeneratedValue(generator = "users_generator") | ||||
|   @SequenceGenerator(name = "users_generator", sequenceName = "users_sequence", initialValue = 1) | ||||
|   private Long id; | ||||
| 
 | ||||
|   @Column(name = "username", unique = true, nullable = false, length = 150) | ||||
|   private String username; | ||||
| 
 | ||||
| @ -88,6 +91,14 @@ public class UserEntity extends DateAuditEntity { | ||||
|   public UserEntity() { | ||||
|   } | ||||
| 
 | ||||
|   public Long getId() { | ||||
|     return id; | ||||
|   } | ||||
| 
 | ||||
|   public void setId(Long id) { | ||||
|     this.id = id; | ||||
|   } | ||||
| 
 | ||||
|   public String getUsername() { | ||||
|     return this.username; | ||||
|   } | ||||
| @ -296,7 +307,6 @@ public class UserEntity extends DateAuditEntity { | ||||
| // 아이디 | ||||
| // 로그인 아이디 | ||||
| // 로그인 패스워드 | ||||
| // 로그인 패스워드 문자 | ||||
| // 이메일 | ||||
| // 닉네임 | ||||
| // 은행명 | ||||
|  | ||||
| @ -0,0 +1,40 @@ | ||||
| package com.totopia.server.modules.user.entity; | ||||
| 
 | ||||
| import com.totopia.server.commons.data.entity.UserDateAuditEntity; | ||||
| import com.totopia.server.modules.user.type.ProcessingStatus; | ||||
| import lombok.*; | ||||
| import lombok.experimental.SuperBuilder; | ||||
| 
 | ||||
| import javax.persistence.*; | ||||
| import java.io.Serializable; | ||||
| 
 | ||||
| @Entity(name = "withdrawal") | ||||
| @SuperBuilder | ||||
| @NoArgsConstructor | ||||
| @AllArgsConstructor | ||||
| @Getter | ||||
| @Setter | ||||
| @ToString | ||||
| @Data | ||||
| public class WithdrawalEntity extends UserDateAuditEntity implements Serializable { | ||||
|     @Id | ||||
|     @GeneratedValue(generator = "withdrawal_generator") | ||||
|     @SequenceGenerator(name = "withdrawal_generator", sequenceName = "withdrawal_sequence", initialValue = 1) | ||||
|     private Long id; | ||||
| 
 | ||||
|     @Column(name = "amount_of_money", nullable = false) | ||||
|     private Integer amountOfMoney; | ||||
| 
 | ||||
|     @Column(name = "deposit_user", nullable = false) | ||||
|     private Long withdrawalUser; | ||||
| 
 | ||||
|     @Column(name = "confirm_user", nullable = false) | ||||
|     private Long confirmUser; | ||||
| 
 | ||||
|     @Column(name = "bank_account", nullable = false) | ||||
|     private Long bankAccount; | ||||
| 
 | ||||
|     @Enumerated(EnumType.STRING) | ||||
|     @Column(name = "status", length = 60) | ||||
|     private ProcessingStatus status; | ||||
| } | ||||
| @ -0,0 +1,7 @@ | ||||
| package com.totopia.server.modules.user.repository; | ||||
| 
 | ||||
| import com.totopia.server.modules.user.entity.DepositEntity; | ||||
| import org.springframework.data.jpa.repository.JpaRepository; | ||||
| 
 | ||||
| public interface DepositRepository extends JpaRepository<DepositEntity, Long> { | ||||
| } | ||||
| @ -0,0 +1,7 @@ | ||||
| package com.totopia.server.modules.user.repository; | ||||
| 
 | ||||
| import com.totopia.server.modules.user.entity.WithdrawalEntity; | ||||
| import org.springframework.data.jpa.repository.JpaRepository; | ||||
| 
 | ||||
| public interface WithdrawalRepository extends JpaRepository<WithdrawalEntity, Long> { | ||||
| } | ||||
| @ -0,0 +1,5 @@ | ||||
| package com.totopia.server.modules.user.type; | ||||
| 
 | ||||
| public enum ProcessingStatus { | ||||
|     PROCESSING_WAITING, PROCESSING_HOLD, PROCESSING_COMPLETE | ||||
| } | ||||
| @ -14,7 +14,7 @@ import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| 
 | ||||
| @Ignore | ||||
| //@Ignore | ||||
| @RunWith(SpringRunner.class) | ||||
| @SpringBootTest | ||||
| public class BankAccountRepositoryTest { | ||||
| @ -64,7 +64,7 @@ public class BankAccountRepositoryTest { | ||||
|                 break; | ||||
|             } | ||||
|             idx++; | ||||
|             bankAccount.setUsername(user.getUsername()); | ||||
|             bankAccount.setUserId(user.getId()); | ||||
|             bankAccount.setUpdatedAt(new Date()); | ||||
|             this.bankAccountRepository.save(bankAccount); | ||||
|         } | ||||
| @ -95,7 +95,7 @@ public class BankAccountRepositoryTest { | ||||
|                 break; | ||||
|             } | ||||
|             idx++; | ||||
|             account.setUsername(account.getUsername()); | ||||
|             account.setUserId(account.getId()); | ||||
| 
 | ||||
|             this.bankAccountRepository.save(account); | ||||
|         } | ||||
|  | ||||
| @ -0,0 +1,72 @@ | ||||
| package com.totopia.server.modules.user.repository; | ||||
| 
 | ||||
| import com.totopia.server.modules.user.entity.BankAccountEntity; | ||||
| import com.totopia.server.modules.user.entity.DepositEntity; | ||||
| import com.totopia.server.modules.user.entity.UserEntity; | ||||
| import com.totopia.server.modules.user.type.ProcessingStatus; | ||||
| import org.junit.Before; | ||||
| import org.junit.Ignore; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.test.context.SpringBootTest; | ||||
| import org.springframework.test.context.junit4.SpringRunner; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import static org.junit.Assert.*; | ||||
| 
 | ||||
| @Ignore | ||||
| @RunWith(SpringRunner.class) | ||||
| @SpringBootTest | ||||
| public class DepositRepositoryTest { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private UserRepository userRepository; | ||||
|     @Autowired | ||||
|     private BankAccountRepository bankAccountRepository; | ||||
|     @Autowired | ||||
|     private DepositRepository depositRepository; | ||||
| 
 | ||||
|     List<UserEntity> users; | ||||
|     List<BankAccountEntity> accounts; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setUp() throws Exception { | ||||
|         users = this.userRepository.findAll(); | ||||
|         accounts = this.bankAccountRepository.findAll(); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void insertTest() throws Exception { | ||||
|         DepositEntity en = DepositEntity.builder() | ||||
|                 .amountOfMoney(10000) | ||||
|                 .bankAccount(accounts.get(2).getId()) | ||||
|                 .confirmUser(accounts.get(0).getId()) | ||||
|                 .depositUser(accounts.get(2).getId()) | ||||
|                 .status(ProcessingStatus.PROCESSING_HOLD) | ||||
|                 .build(); | ||||
| 
 | ||||
| //        DepositEntity entity = new DepositEntity(); | ||||
| // | ||||
| //        entity.setAmountOfMoney(2000000); | ||||
| //        entity.setBankAccount(accounts.get(1).getId()); | ||||
| //        entity.setConfirmUser(accounts.get(0).getId()); | ||||
| //        entity.setDepositUser(accounts.get(1).getId()); | ||||
| //        entity.setStatus(ProcessingStatus.PROCESSING_WAITING); | ||||
| //        entity.setCreatedBy(accounts.get(1).getId()); | ||||
| //        entity.setUpdatedBy(accounts.get(1).getId()); | ||||
| 
 | ||||
|         this.depositRepository.save(en); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void updateTest() throws Exception { | ||||
|         DepositEntity entity = this.depositRepository.findById(1L).orElse(null); | ||||
|         entity.setStatus(ProcessingStatus.PROCESSING_COMPLETE); | ||||
|         this.depositRepository.save(entity); | ||||
|         assertEquals(entity.getDepositUser().longValue(), 2L); | ||||
|     } | ||||
| } | ||||
| @ -7,6 +7,7 @@ import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.test.context.SpringBootTest; | ||||
| import org.springframework.security.crypto.password.PasswordEncoder; | ||||
| import org.springframework.test.context.junit4.SpringRunner; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| @ -16,7 +17,7 @@ import java.util.Optional; | ||||
| 
 | ||||
| import static org.junit.Assert.assertEquals; | ||||
| 
 | ||||
| @Ignore | ||||
| //@Ignore | ||||
| @RunWith(SpringRunner.class) | ||||
| @SpringBootTest | ||||
| public class UserRepositoryTest { | ||||
| @ -24,38 +25,40 @@ public class UserRepositoryTest { | ||||
|     @Autowired | ||||
|     private UserRepository userRepository; | ||||
| 
 | ||||
|     @Autowired | ||||
|     PasswordEncoder passwordEncoder; | ||||
|     // private User.UserBuilder user; | ||||
| 
 | ||||
|     private List<UserEntity> userList = new ArrayList<>(); | ||||
| 
 | ||||
|     @Before | ||||
|     public void setUp() throws Exception { | ||||
|         UserEntity user = UserEntity.builder().activation("Y").block(false).email("geekdev@naver.com").nickname("admin") | ||||
|                 .otep("").otpKey("").password("qwer5795").username("admin").requireReset(false) | ||||
|                 .resetCount(Long.valueOf(0)).lastResetTime(new Date()).build(); | ||||
| //        UserEntity user = UserEntity.builder().activation("Y").block(false).email("geekdev@naver.com").nickname("admin") | ||||
| //                .otep("").otpKey("").password("qwer5795").username("admin").requireReset(false) | ||||
| //                .resetCount(Long.valueOf(0)).lastResetTime(new Date()).build(); | ||||
| // | ||||
| //        userList.add(user); | ||||
| 
 | ||||
|         userList.add(user); | ||||
| 
 | ||||
|         user = UserEntity.builder().activation("Y").block(false).email("geektest1@naver.com").nickname("test1").otep("") | ||||
|                 .otpKey("").password("qwer5795").username("test1").requireReset(false).resetCount(Long.valueOf(0)) | ||||
|                 .lastResetTime(new Date()).build(); | ||||
| 
 | ||||
|         userList.add(user); | ||||
| 
 | ||||
|         user = UserEntity.builder().activation("Y").block(false).email("geektest2@naver.com").nickname("test2").otep("") | ||||
|                 .otpKey("").password("qwer5795").username("test2").requireReset(false).resetCount(Long.valueOf(0)) | ||||
|                 .lastResetTime(new Date()).build(); | ||||
| 
 | ||||
|         userList.add(user); | ||||
| //        UserEntity user = UserEntity.builder().activation("Y").block(false).email("geektest1@naver.com").nickname("test1").otep("") | ||||
| //                .otpKey("").password(passwordEncoder.encode("qwer5795")).username("test1").requireReset(false).resetCount(Long.valueOf(0)) | ||||
| //                .lastResetTime(new Date()).sendEmail(true) | ||||
| //                .build(); | ||||
| // | ||||
| //        userList.add(user); | ||||
| // | ||||
| //        user = UserEntity.builder().activation("Y").block(false).email("geektest2@naver.com").nickname("test2").otep("") | ||||
| //                .otpKey("").password(passwordEncoder.encode("qwer5795")).username("test2").requireReset(false).resetCount(Long.valueOf(0)) | ||||
| //                .lastResetTime(new Date()).sendEmail(true) | ||||
| //                .build(); | ||||
| // | ||||
| //        userList.add(user); | ||||
| //        this.userRepository.saveAll(userList); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void findByUsername() { | ||||
|         UserEntity admin = this.getAdmin().orElse(null); | ||||
|         if (admin == null) { | ||||
|             this.userRepository.saveAll(userList); | ||||
|             assertEquals("Equlas", userList.get(0).getNickname(), "admin"); | ||||
|         } | ||||
|         assertEquals("Equlas",admin.getNickname(), "admin"); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|  | ||||
| @ -0,0 +1,50 @@ | ||||
| package com.totopia.server.modules.user.repository; | ||||
| 
 | ||||
| import com.totopia.server.modules.user.entity.BankAccountEntity; | ||||
| import com.totopia.server.modules.user.entity.UserEntity; | ||||
| import com.totopia.server.modules.user.entity.WithdrawalEntity; | ||||
| import com.totopia.server.modules.user.type.ProcessingStatus; | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.boot.test.context.SpringBootTest; | ||||
| import org.springframework.test.context.junit4.SpringRunner; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import static org.junit.Assert.*; | ||||
| 
 | ||||
| @RunWith(SpringRunner.class) | ||||
| @SpringBootTest | ||||
| public class WithdrawalRepositoryTest { | ||||
| 
 | ||||
|     @Autowired | ||||
|     private UserRepository userRepository; | ||||
|     @Autowired | ||||
|     private BankAccountRepository bankAccountRepository; | ||||
|     @Autowired | ||||
|     private WithdrawalRepository withdrawalRepository; | ||||
| 
 | ||||
|     List<UserEntity> users; | ||||
|     List<BankAccountEntity> accounts; | ||||
| 
 | ||||
|     @Before | ||||
|     public void setUp() throws Exception { | ||||
|         users = this.userRepository.findAll(); | ||||
|         accounts = this.bankAccountRepository.findAll(); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     public void insertTest() throws Exception { | ||||
|         WithdrawalEntity en = WithdrawalEntity.builder() | ||||
|                 .amountOfMoney(10000) | ||||
|                 .bankAccount(accounts.get(2).getId()) | ||||
|                 .confirmUser(accounts.get(0).getId()) | ||||
|                 .withdrawalUser(accounts.get(2).getId()) | ||||
|                 .status(ProcessingStatus.PROCESSING_WAITING) | ||||
|                 .build(); | ||||
| 
 | ||||
|         this.withdrawalRepository.save(en); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user