|
@@ -1,5 +1,21 @@
|
|
|
package com.baomidou.mybatisplus.test.mysql;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import org.junit.Assert;
|
|
|
+import org.junit.BeforeClass;
|
|
|
+import org.junit.FixMethodOrder;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.junit.runners.MethodSorters;
|
|
|
+import org.springframework.test.context.ContextConfiguration;
|
|
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
@@ -15,20 +31,6 @@ import com.baomidou.mybatisplus.test.base.mapper.commons.CommonDataMapper;
|
|
|
import com.baomidou.mybatisplus.test.base.mapper.commons.CommonLogicDataMapper;
|
|
|
import com.baomidou.mybatisplus.test.base.mapper.mysql.MysqlDataMapper;
|
|
|
import com.baomidou.mybatisplus.test.mysql.config.MysqlDb;
|
|
|
-import org.junit.Assert;
|
|
|
-import org.junit.BeforeClass;
|
|
|
-import org.junit.FixMethodOrder;
|
|
|
-import org.junit.Test;
|
|
|
-import org.junit.runner.RunWith;
|
|
|
-import org.junit.runners.MethodSorters;
|
|
|
-import org.springframework.test.context.ContextConfiguration;
|
|
|
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -70,34 +72,37 @@ public class MysqlTestDataMapperTest {
|
|
|
|
|
|
@Test
|
|
|
public void b1_deleteById() {
|
|
|
- Assert.assertEquals(1, commonMapper.deleteById(1L));
|
|
|
- Assert.assertEquals(1, commonLogicMapper.deleteById(1L));
|
|
|
- Assert.assertEquals(1, mysqlMapper.deleteById(1L));
|
|
|
+ long id = 1L;
|
|
|
+ Assert.assertEquals(1, commonMapper.deleteById(id));
|
|
|
+ Assert.assertEquals(1, commonLogicMapper.deleteById(id));
|
|
|
+ Assert.assertEquals(1, mysqlMapper.deleteById(id));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void b2_deleteByMap() {
|
|
|
+ long id = 2L;
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("id", 2L);
|
|
|
+ map.put("id", id);
|
|
|
map.put("test_int", 5);
|
|
|
Assert.assertEquals(0, commonMapper.deleteByMap(map));
|
|
|
Assert.assertEquals(0, commonLogicMapper.deleteByMap(map));
|
|
|
Map<String, Object> map2 = new HashMap<>();
|
|
|
- map2.put("id", 2L);
|
|
|
+ map2.put("id", id);
|
|
|
map2.put("`order`", 5);
|
|
|
Assert.assertEquals(0, mysqlMapper.deleteByMap(map2));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void b3_delete() {
|
|
|
+ long id = 2L;
|
|
|
Assert.assertEquals(1, commonMapper.delete(new QueryWrapper<CommonData>().lambda()
|
|
|
- .eq(CommonData::getId, 2L)
|
|
|
+ .eq(CommonData::getId, id)
|
|
|
.eq(CommonData::getTestInt, 2)));
|
|
|
Assert.assertEquals(1, commonLogicMapper.delete(new QueryWrapper<CommonLogicData>().lambda()
|
|
|
- .eq(CommonLogicData::getId, 2L)
|
|
|
+ .eq(CommonLogicData::getId, id)
|
|
|
.eq(CommonLogicData::getTestInt, 2)));
|
|
|
Assert.assertEquals(1, mysqlMapper.delete(new QueryWrapper<MysqlData>().lambda()
|
|
|
- .eq(MysqlData::getId, 2L)
|
|
|
+ .eq(MysqlData::getId, id)
|
|
|
.eq(MysqlData::getOrder, 2)));
|
|
|
}
|
|
|
|
|
@@ -109,33 +114,47 @@ public class MysqlTestDataMapperTest {
|
|
|
Assert.assertEquals(2, mysqlMapper.deleteBatchIds(ids));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void b5_deleteByIdWithFill() {
|
|
|
+ long id = 5L;
|
|
|
+ // 真删
|
|
|
+ Assert.assertEquals(1, commonMapper.deleteByIdWithFill(new CommonData().setId(id)));
|
|
|
+ // 逻辑删除带填充
|
|
|
+ Assert.assertEquals(1, commonLogicMapper.deleteByIdWithFill(new CommonLogicData().setId(id)));
|
|
|
+ // 真删
|
|
|
+ Assert.assertEquals(1, mysqlMapper.deleteByIdWithFill(new MysqlData().setId(id)));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void c1_updateById() {
|
|
|
- Assert.assertEquals(1, commonMapper.updateById(new CommonData().setId(5L).setTestInt(555).setVersion(0)));
|
|
|
- Assert.assertEquals(1, commonLogicMapper.updateById(new CommonLogicData().setId(5L).setTestInt(555)));
|
|
|
- Assert.assertEquals(1, mysqlMapper.updateById(new MysqlData().setId(5L).setOrder(555)));
|
|
|
+ long id = 6L;
|
|
|
+ Assert.assertEquals(1, commonMapper.updateById(new CommonData().setId(id).setTestInt(555).setVersion(0)));
|
|
|
+ Assert.assertEquals(1, commonLogicMapper.updateById(new CommonLogicData().setId(id).setTestInt(555)));
|
|
|
+ Assert.assertEquals(1, mysqlMapper.updateById(new MysqlData().setId(id).setOrder(555)));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void c2_optimisticUpdateById() {
|
|
|
- Assert.assertEquals(1, commonMapper.updateById(new CommonData().setId(7L).setTestInt(778)
|
|
|
+ long id = 7L;
|
|
|
+ Assert.assertEquals(1, commonMapper.updateById(new CommonData().setId(id).setTestInt(778)
|
|
|
.setVersion(0)));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void c3_update() {
|
|
|
+ long id = 8L;
|
|
|
Assert.assertEquals(1, commonMapper.update(
|
|
|
- new CommonData().setTestInt(666).setVersion(0),
|
|
|
- new UpdateWrapper<CommonData>().lambda().eq(CommonData::getId, 6L)
|
|
|
- .eq(CommonData::getTestInt, 6)));
|
|
|
+ new CommonData().setTestInt(888).setVersion(0),
|
|
|
+ new UpdateWrapper<CommonData>().lambda().eq(CommonData::getId, id)
|
|
|
+ .eq(CommonData::getTestInt, 8)));
|
|
|
Assert.assertEquals(1, commonLogicMapper.update(
|
|
|
- new CommonLogicData().setTestInt(666),
|
|
|
- new UpdateWrapper<CommonLogicData>().lambda().eq(CommonLogicData::getId, 6L)
|
|
|
- .eq(CommonLogicData::getTestInt, 6)));
|
|
|
+ new CommonLogicData().setTestInt(888),
|
|
|
+ new UpdateWrapper<CommonLogicData>().lambda().eq(CommonLogicData::getId, id)
|
|
|
+ .eq(CommonLogicData::getTestInt, 8)));
|
|
|
Assert.assertEquals(1, mysqlMapper.update(
|
|
|
- new MysqlData().setOrder(666),
|
|
|
- new UpdateWrapper<MysqlData>().lambda().eq(MysqlData::getId, 6L)
|
|
|
- .eq(MysqlData::getOrder, 6)));
|
|
|
+ new MysqlData().setOrder(888),
|
|
|
+ new UpdateWrapper<MysqlData>().lambda().eq(MysqlData::getId, id)
|
|
|
+ .eq(MysqlData::getOrder, 8)));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -161,35 +180,38 @@ public class MysqlTestDataMapperTest {
|
|
|
|
|
|
@Test
|
|
|
public void d4_selectByMap() {
|
|
|
+ long id = 9L;
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
- map.put("id", 9L);
|
|
|
+ map.put("id", id);
|
|
|
map.put("test_int", 9);
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(commonMapper.selectByMap(map)));
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(commonLogicMapper.selectByMap(map)));
|
|
|
Map<String, Object> map2 = new HashMap<>();
|
|
|
- map2.put("id", 9L);
|
|
|
+ map2.put("id", id);
|
|
|
map2.put("`order`", 9);
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectByMap(map2)));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void d5_selectOne() {
|
|
|
+ long id = 10L;
|
|
|
Assert.assertNotNull(commonMapper.selectOne(new QueryWrapper<CommonData>().lambda()
|
|
|
- .eq(CommonData::getId, 10L).eq(CommonData::getTestInt, 10)));
|
|
|
+ .eq(CommonData::getId, id).eq(CommonData::getTestInt, 10)));
|
|
|
Assert.assertNotNull(commonLogicMapper.selectOne(new QueryWrapper<CommonLogicData>().lambda()
|
|
|
- .eq(CommonLogicData::getId, 10L).eq(CommonLogicData::getTestInt, 10)));
|
|
|
+ .eq(CommonLogicData::getId, id).eq(CommonLogicData::getTestInt, 10)));
|
|
|
Assert.assertNotNull(mysqlMapper.selectOne(new QueryWrapper<MysqlData>().lambda()
|
|
|
- .eq(MysqlData::getId, 10L).eq(MysqlData::getOrder, 10)));
|
|
|
+ .eq(MysqlData::getId, id).eq(MysqlData::getOrder, 10)));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void d6_selectList() {
|
|
|
+ long id = 10L;
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(commonMapper.selectList(new QueryWrapper<CommonData>()
|
|
|
.lambda().eq(CommonData::getTestInt, 10))));
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(commonLogicMapper.selectList(new QueryWrapper<CommonLogicData>()
|
|
|
- .lambda().eq(CommonLogicData::getId, 10L).eq(CommonLogicData::getTestInt, 10))));
|
|
|
+ .lambda().eq(CommonLogicData::getId, id).eq(CommonLogicData::getTestInt, 10))));
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(mysqlMapper.selectList(new QueryWrapper<MysqlData>()
|
|
|
- .lambda().eq(MysqlData::getId, 10L).eq(MysqlData::getOrder, 10))));
|
|
|
+ .lambda().eq(MysqlData::getId, id).eq(MysqlData::getOrder, 10))));
|
|
|
}
|
|
|
|
|
|
@Test
|