|
|
@@ -1,9 +1,13 @@
|
|
|
package com.izouma.immall.repo;
|
|
|
|
|
|
+import com.github.javafaker.Faker;
|
|
|
import com.izouma.immall.domain.User;
|
|
|
+import com.izouma.immall.domain.VipUser;
|
|
|
import com.izouma.immall.exception.BusinessException;
|
|
|
+import com.izouma.immall.security.Authority;
|
|
|
import com.izouma.immall.security.JwtTokenUtil;
|
|
|
import com.izouma.immall.security.JwtUserFactory;
|
|
|
+import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -11,7 +15,9 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
@SpringBootTest
|
|
|
@@ -20,6 +26,8 @@ public class UserRepoTest {
|
|
|
private UserRepo userRepo;
|
|
|
@Autowired
|
|
|
private JwtTokenUtil jwtTokenUtil;
|
|
|
+ @Autowired
|
|
|
+ private VipUserRepo vipUserRepo;
|
|
|
|
|
|
@Test
|
|
|
public void testUser() {
|
|
|
@@ -48,15 +56,64 @@ public class UserRepoTest {
|
|
|
// }
|
|
|
|
|
|
@Test
|
|
|
- public void findAllUser(){
|
|
|
+ public void findAllUser() {
|
|
|
List<User> list = userRepo.findAll();
|
|
|
System.out.println(list);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Test
|
|
|
- public void token(){
|
|
|
+ public void token() {
|
|
|
User user = userRepo.findById(999l).orElseThrow(new BusinessException("不存在"));
|
|
|
System.out.println(jwtTokenUtil.generateToken(JwtUserFactory.create(user)));
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void addFakeUser() {
|
|
|
+ Faker faker = new Faker(new Locale("zh-CN"));
|
|
|
+
|
|
|
+ char[] alls = "A. @#!$%*&。-'`^© A.".toCharArray();
|
|
|
+
|
|
|
+ Random random = new Random();
|
|
|
+
|
|
|
+ for (int i = 0; i < 1000; i++) {
|
|
|
+ //15864
|
|
|
+ int num = 16000 + (int) (Math.random() * (16200 - 15936));
|
|
|
+ if (num % 2 != 0) {
|
|
|
+ num += 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ LocalDateTime time = LocalDateTime.now().minusMinutes(Math.round(Math.random() * 6000));
|
|
|
+ String name = faker.name().name();
|
|
|
+ int nextInt = random.nextInt(alls.length);
|
|
|
+ User user = userRepo.save(User.builder()
|
|
|
+ .password(new BCryptPasswordEncoder().encode("123456"))
|
|
|
+ .nickname(alls[nextInt] + name + RandomStringUtils.randomAlphabetic(0))
|
|
|
+ .username(UUID.randomUUID().toString())
|
|
|
+ .avatar(faker.avatar().image())
|
|
|
+ .authorities(Collections
|
|
|
+ .singleton(Authority.builder().name(Authority.NAMES.ROLE_USER.name()).build()))
|
|
|
+ .registerTime(time)
|
|
|
+ .parentId((long) num)
|
|
|
+ .enabled(true)
|
|
|
+ .sex((int) (10 * Math.random()) % 2 > 0 ? "男" : "女")
|
|
|
+ .build());
|
|
|
+
|
|
|
+
|
|
|
+ LocalDateTime vipTime = time.plusMinutes(Math.round(Math.random() * 500));
|
|
|
+ vipUserRepo.save(VipUser.builder()
|
|
|
+ .openId(user.getOpenId())
|
|
|
+ .startTime(vipTime)
|
|
|
+ .endTime(vipTime.plusYears(1))
|
|
|
+ .identityId(34L)
|
|
|
+ .fansNum(0L)
|
|
|
+ .money(BigDecimal.ZERO)
|
|
|
+ .userId(user.getId())
|
|
|
+ .expired(false)
|
|
|
+ .parentId(user.getParentId())
|
|
|
+ .isShare(true)
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|