|
@@ -2,8 +2,8 @@ package com.baomidou.mybatisplus.test.h2.tenant;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.test.h2.tenant.mapper.StudentMapper;
|
|
|
import com.baomidou.mybatisplus.test.h2.tenant.model.Student;
|
|
|
+import com.baomidou.mybatisplus.test.h2.tenant.service.IStudentService;
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
import org.junit.jupiter.api.MethodOrderer;
|
|
|
import org.junit.jupiter.api.Test;
|
|
@@ -13,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* @author nieqiuqiu 2019/12/8
|
|
|
*/
|
|
@@ -22,34 +24,42 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
|
|
class TenantTest {
|
|
|
|
|
|
@Autowired
|
|
|
- private StudentMapper studentMapper;
|
|
|
+ private IStudentService studentService;
|
|
|
|
|
|
-// @Test
|
|
|
- void testSimple(){
|
|
|
+ // @Test
|
|
|
+ void testSimple() {
|
|
|
TenantConfig.TENANT_ID = 2L;
|
|
|
- Student student1 = studentMapper.selectById(1L);
|
|
|
+ Student student1 = studentService.getById(1L);
|
|
|
Assertions.assertNull(student1);
|
|
|
- student1 = studentMapper.selectById(1L);
|
|
|
+ student1 = studentService.getById(1L);
|
|
|
Assertions.assertNull(student1);
|
|
|
TenantConfig.TENANT_ID = 1L;
|
|
|
- Student student2 = studentMapper.selectById(1L);
|
|
|
+ Student student2 = studentService.getById(1L);
|
|
|
Assertions.assertNotNull(student2);
|
|
|
- student2 = studentMapper.selectById(1L);
|
|
|
+ student2 = studentService.getById(1L);
|
|
|
Assertions.assertNotNull(student2);
|
|
|
}
|
|
|
|
|
|
-// @Test
|
|
|
- void testPage(){
|
|
|
+ // @Test
|
|
|
+ void testPage() {
|
|
|
TenantConfig.TENANT_ID = 2L;
|
|
|
- Page<Student> page1 = studentMapper.selectPage(new Page<>(0, 10), new QueryWrapper<>());
|
|
|
- Assertions.assertEquals(page1.getTotal(),1);
|
|
|
- page1 = studentMapper.selectPage(new Page<>(0, 10), new QueryWrapper<>());
|
|
|
- Assertions.assertEquals(page1.getTotal(),1);
|
|
|
+ Page<Student> page1 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
|
|
|
+ Assertions.assertEquals(page1.getTotal(), 1);
|
|
|
+ page1 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
|
|
|
+ Assertions.assertEquals(page1.getTotal(), 1);
|
|
|
TenantConfig.TENANT_ID = 3L;
|
|
|
- Page<Student> page2 = studentMapper.selectPage(new Page<>(0,10), new QueryWrapper<>());
|
|
|
- Assertions.assertEquals(page2.getTotal(),0);
|
|
|
- page2 = studentMapper.selectPage(new Page<>(0,10), new QueryWrapper<>());
|
|
|
- Assertions.assertEquals(page2.getTotal(),0);
|
|
|
+ Page<Student> page2 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
|
|
|
+ Assertions.assertEquals(page2.getTotal(), 0);
|
|
|
+ page2 = studentService.page(new Page<>(0, 10), new QueryWrapper<>());
|
|
|
+ Assertions.assertEquals(page2.getTotal(), 0);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void testBatch() {
|
|
|
+ TenantConfig.TENANT_ID = 1L;
|
|
|
+ List<Student> list = studentService.list();
|
|
|
+ list.forEach(student -> student.setName("小红"));
|
|
|
+ studentService.updateBatchById(list);
|
|
|
+ studentService.list().forEach(student -> Assertions.assertEquals("小红", student.getName()));
|
|
|
+ }
|
|
|
}
|