From 135f2ff4926737354dca3e6794a64887e24f795b Mon Sep 17 00:00:00 2001 From: byung eun park Date: Sun, 18 Aug 2019 20:05:14 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=85=EC=B6=9C=EA=B8=88=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=20=EC=A0=95=EB=B3=B4=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../totopia/server/init/DbInitializer.java | 12 ++++ .../user/entity/BankAccountEntity.java | 30 ++++---- .../modules/user/entity/DepositEntity.java | 43 +++++++++++ .../modules/user/entity/UserEntity.java | 16 ++++- .../modules/user/entity/WithdrawalEntity.java | 40 +++++++++++ .../user/repository/DepositRepository.java | 7 ++ .../user/repository/WithdrawalRepository.java | 7 ++ .../modules/user/type/ProcessingStatus.java | 5 ++ .../repository/BankAccountRepositoryTest.java | 6 +- .../repository/DepositRepositoryTest.java | 72 +++++++++++++++++++ .../user/repository/UserRepositoryTest.java | 45 ++++++------ .../repository/WithdrawalRepositoryTest.java | 50 +++++++++++++ 12 files changed, 291 insertions(+), 42 deletions(-) create mode 100644 src/main/java/com/totopia/server/modules/user/entity/DepositEntity.java create mode 100644 src/main/java/com/totopia/server/modules/user/entity/WithdrawalEntity.java create mode 100644 src/main/java/com/totopia/server/modules/user/repository/DepositRepository.java create mode 100644 src/main/java/com/totopia/server/modules/user/repository/WithdrawalRepository.java create mode 100644 src/main/java/com/totopia/server/modules/user/type/ProcessingStatus.java create mode 100644 src/test/java/com/totopia/server/modules/user/repository/DepositRepositoryTest.java create mode 100644 src/test/java/com/totopia/server/modules/user/repository/WithdrawalRepositoryTest.java diff --git a/src/main/java/com/totopia/server/init/DbInitializer.java b/src/main/java/com/totopia/server/init/DbInitializer.java index c112a0e..7c209b1 100644 --- a/src/main/java/com/totopia/server/init/DbInitializer.java +++ b/src/main/java/com/totopia/server/init/DbInitializer.java @@ -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"); diff --git a/src/main/java/com/totopia/server/modules/user/entity/BankAccountEntity.java b/src/main/java/com/totopia/server/modules/user/entity/BankAccountEntity.java index 7b85550..0153cf7 100644 --- a/src/main/java/com/totopia/server/modules/user/entity/BankAccountEntity.java +++ b/src/main/java/com/totopia/server/modules/user/entity/BankAccountEntity.java @@ -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; } diff --git a/src/main/java/com/totopia/server/modules/user/entity/DepositEntity.java b/src/main/java/com/totopia/server/modules/user/entity/DepositEntity.java new file mode 100644 index 0000000..b5a5e36 --- /dev/null +++ b/src/main/java/com/totopia/server/modules/user/entity/DepositEntity.java @@ -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; + +} diff --git a/src/main/java/com/totopia/server/modules/user/entity/UserEntity.java b/src/main/java/com/totopia/server/modules/user/entity/UserEntity.java index da9ed72..5d99da1 100644 --- a/src/main/java/com/totopia/server/modules/user/entity/UserEntity.java +++ b/src/main/java/com/totopia/server/modules/user/entity/UserEntity.java @@ -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 { // 아이디 // 로그인 아이디 // 로그인 패스워드 -// 로그인 패스워드 문자 // 이메일 // 닉네임 // 은행명 diff --git a/src/main/java/com/totopia/server/modules/user/entity/WithdrawalEntity.java b/src/main/java/com/totopia/server/modules/user/entity/WithdrawalEntity.java new file mode 100644 index 0000000..892fe3a --- /dev/null +++ b/src/main/java/com/totopia/server/modules/user/entity/WithdrawalEntity.java @@ -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; +} diff --git a/src/main/java/com/totopia/server/modules/user/repository/DepositRepository.java b/src/main/java/com/totopia/server/modules/user/repository/DepositRepository.java new file mode 100644 index 0000000..ae74a45 --- /dev/null +++ b/src/main/java/com/totopia/server/modules/user/repository/DepositRepository.java @@ -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 { +} diff --git a/src/main/java/com/totopia/server/modules/user/repository/WithdrawalRepository.java b/src/main/java/com/totopia/server/modules/user/repository/WithdrawalRepository.java new file mode 100644 index 0000000..abd38cd --- /dev/null +++ b/src/main/java/com/totopia/server/modules/user/repository/WithdrawalRepository.java @@ -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 { +} diff --git a/src/main/java/com/totopia/server/modules/user/type/ProcessingStatus.java b/src/main/java/com/totopia/server/modules/user/type/ProcessingStatus.java new file mode 100644 index 0000000..b4ca1ab --- /dev/null +++ b/src/main/java/com/totopia/server/modules/user/type/ProcessingStatus.java @@ -0,0 +1,5 @@ +package com.totopia.server.modules.user.type; + +public enum ProcessingStatus { + PROCESSING_WAITING, PROCESSING_HOLD, PROCESSING_COMPLETE +} diff --git a/src/test/java/com/totopia/server/modules/user/repository/BankAccountRepositoryTest.java b/src/test/java/com/totopia/server/modules/user/repository/BankAccountRepositoryTest.java index c11e9b2..25efe54 100644 --- a/src/test/java/com/totopia/server/modules/user/repository/BankAccountRepositoryTest.java +++ b/src/test/java/com/totopia/server/modules/user/repository/BankAccountRepositoryTest.java @@ -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); } diff --git a/src/test/java/com/totopia/server/modules/user/repository/DepositRepositoryTest.java b/src/test/java/com/totopia/server/modules/user/repository/DepositRepositoryTest.java new file mode 100644 index 0000000..2211d92 --- /dev/null +++ b/src/test/java/com/totopia/server/modules/user/repository/DepositRepositoryTest.java @@ -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 users; + List 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); + } +} \ No newline at end of file diff --git a/src/test/java/com/totopia/server/modules/user/repository/UserRepositoryTest.java b/src/test/java/com/totopia/server/modules/user/repository/UserRepositoryTest.java index 3938882..c35d933 100644 --- a/src/test/java/com/totopia/server/modules/user/repository/UserRepositoryTest.java +++ b/src/test/java/com/totopia/server/modules/user/repository/UserRepositoryTest.java @@ -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 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 diff --git a/src/test/java/com/totopia/server/modules/user/repository/WithdrawalRepositoryTest.java b/src/test/java/com/totopia/server/modules/user/repository/WithdrawalRepositoryTest.java new file mode 100644 index 0000000..97d6e8f --- /dev/null +++ b/src/test/java/com/totopia/server/modules/user/repository/WithdrawalRepositoryTest.java @@ -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 users; + List 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); + } +} \ No newline at end of file