|
| 1 | +package io.ymq.example.mongodb; |
| 2 | + |
| 3 | +import com.alibaba.fastjson.JSONObject; |
| 4 | +import org.junit.Test; |
| 5 | +import org.junit.runner.RunWith; |
| 6 | +import org.springframework.beans.factory.annotation.Autowired; |
| 7 | +import org.springframework.boot.test.context.SpringBootTest; |
| 8 | +import org.springframework.test.context.junit4.SpringRunner; |
| 9 | + |
| 10 | +/** |
| 11 | + * 描述: 单元测试 |
| 12 | + * |
| 13 | + * @author: yanpenglei |
| 14 | + * @create: 2018/2/5 13:52 |
| 15 | + */ |
| 16 | +@RunWith(SpringRunner.class) |
| 17 | +@SpringBootTest(classes = SpringBootMongodbApplication.class) |
| 18 | +public class SpringBootMongodbApplicationTests { |
| 19 | + |
| 20 | + @Autowired |
| 21 | + private DemoDao demoDao; |
| 22 | + |
| 23 | + @Test |
| 24 | + public void saveDemoTest() { |
| 25 | + |
| 26 | + DemoEntity demoEntity = new DemoEntity(); |
| 27 | + demoEntity.setId(1L); |
| 28 | + demoEntity.setTitle("Spring Boot 中使用 MongoDB"); |
| 29 | + demoEntity.setDescription("关注公众号,搜云库,专注于开发技术的研究与知识分享"); |
| 30 | + demoEntity.setBy("souyunku"); |
| 31 | + demoEntity.setUrl("http://www.souyunku.com"); |
| 32 | + |
| 33 | + demoDao.saveDemo(demoEntity); |
| 34 | + |
| 35 | + demoEntity = new DemoEntity(); |
| 36 | + demoEntity.setId(2L); |
| 37 | + demoEntity.setTitle("Spring Boot 中使用 MongoDB"); |
| 38 | + demoEntity.setDescription("关注公众号,搜云库,专注于开发技术的研究与知识分享"); |
| 39 | + demoEntity.setBy("souyunku"); |
| 40 | + demoEntity.setUrl("http://www.souyunku.com"); |
| 41 | + |
| 42 | + demoDao.saveDemo(demoEntity); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void removeDemoTest() { |
| 47 | + demoDao.removeDemo(2L); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void updateDemoTest() { |
| 52 | + |
| 53 | + DemoEntity demoEntity = new DemoEntity(); |
| 54 | + demoEntity.setId(1L); |
| 55 | + demoEntity.setTitle("Spring Boot 中使用 MongoDB 更新数据"); |
| 56 | + demoEntity.setDescription("关注公众号,搜云库,专注于开发技术的研究与知识分享"); |
| 57 | + demoEntity.setBy("souyunku"); |
| 58 | + demoEntity.setUrl("http://www.souyunku.com"); |
| 59 | + |
| 60 | + demoDao.updateDemo(demoEntity); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + public void findDemoByIdTest() { |
| 65 | + |
| 66 | + DemoEntity demoEntity = demoDao.findDemoById(1L); |
| 67 | + |
| 68 | + System.out.println(JSONObject.toJSONString(demoEntity)); |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments