1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| package top.lrshuai.mongodb;
import java.util.ArrayList; import java.util.List;
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 top.lrshuai.mongodb.dao.UserDao; import top.lrshuai.mongodb.entity.User; import top.lrshuai.mongodb.repository.UserRepository;
@RunWith(SpringRunner.class) @SpringBootTest public class ApplicationTests { @Autowired private UserDao userDao; @Autowired private UserRepository userRepository;
@Test public void customBathSave() { List<User> users = new ArrayList<>(); User u1 = new User(1l, "lrshuai", 23); User u2 = new User(2l, "rstyro", 24); User u3 = new User(3l, "tyro", 25); User u4 = new User(4l, "mongo", 26); users.add(u1); users.add(u2); users.add(u3); users.add(u4); userDao.saveBathUser(users); }
@Test public void customSave() { userDao.saveUser(new User(1l, "rstyro", 23)); }
@Test public void customDel() { userDao.delUserById(1l); }
@Test public void customUpdate() { User user = new User(2l,"修改用户名",25); System.out.println(userDao.upadteUserById(user)); }
@Test public void customQuery() { User user = userDao.findUserByName("haha"); System.out.println("user="+user); } @Test public void customQueryAll() { List<User> users = userDao.findAll(); System.out.println("users="+users); }
@Test public void customQueryLikeName() { String name="o"; List<User> users = userDao.findUserByLikeName(name); System.out.println("users="+users); }
@Test public void saveTest(){ User user = userRepository.save(new User(2l, "haha", 23)); System.out.println("保存后返回的 user"+user); } @Test public void delTest(){ userRepository.delete(3l); } @Test public void updateTest(){ User user = userRepository.save(new User(4l, "测试", 24)); System.out.println("修改后返回的 user"+user); } @Test public void findOneByNameTest(){ User u = userRepository.findUserByName("rstyro"); System.out.println("user="+u); } @Test public void findAllTest(){ List<User> users = userRepository.findAll(); System.out.println("users="+users); } }
|