|
@@ -11,6 +11,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.select.EntityWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.test.h2.config.H2Db;
|
|
import com.baomidou.mybatisplus.test.h2.config.H2Db;
|
|
import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserMapper;
|
|
import com.baomidou.mybatisplus.test.h2.entity.mapper.H2UserMapper;
|
|
import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
|
|
import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
|
|
@@ -20,8 +22,8 @@ import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
|
|
* Mybatis Plus H2 Junit Test
|
|
* Mybatis Plus H2 Junit Test
|
|
* </p>
|
|
* </p>
|
|
*
|
|
*
|
|
- * @author Caratacus
|
|
|
|
- * @date 2017/4/1
|
|
|
|
|
|
+ * @author hubin
|
|
|
|
+ * @since 2018-06-05
|
|
*/
|
|
*/
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
|
|
@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
|
|
@@ -31,14 +33,14 @@ public class H2UserMapperTest extends BaseTest {
|
|
protected H2UserMapper userMapper;
|
|
protected H2UserMapper userMapper;
|
|
|
|
|
|
@BeforeClass
|
|
@BeforeClass
|
|
- public static void initDB() throws SQLException, IOException {
|
|
|
|
|
|
+ public static void aInitDB() throws SQLException, IOException {
|
|
H2Db.initH2User();
|
|
H2Db.initH2User();
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- public void insert() {
|
|
|
|
|
|
+ public void bInsert() {
|
|
H2User h2User = new H2User();
|
|
H2User h2User = new H2User();
|
|
- h2User.setName("聂秋秋");
|
|
|
|
|
|
+ h2User.setName(NQQ);
|
|
h2User.setAge(1);
|
|
h2User.setAge(1);
|
|
h2User.setDesc("这是一个不错的小伙子");
|
|
h2User.setDesc("这是一个不错的小伙子");
|
|
Assert.assertTrue(1 == userMapper.insert(h2User));
|
|
Assert.assertTrue(1 == userMapper.insert(h2User));
|
|
@@ -46,4 +48,24 @@ public class H2UserMapperTest extends BaseTest {
|
|
log(h2User.getId());
|
|
log(h2User.getId());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test
|
|
|
|
+ public void cUpdate() {
|
|
|
|
+ H2User h2User = new H2User();
|
|
|
|
+ h2User.setAge(2);
|
|
|
|
+ Assert.assertTrue(1 == userMapper.update(h2User,
|
|
|
|
+ new EntityWrapper<H2User>().eq("name", NQQ)));
|
|
|
|
+
|
|
|
|
+ h2User.setAge(3);
|
|
|
|
+ Assert.assertTrue(1 == userMapper.update(h2User,
|
|
|
|
+ new EntityWrapper<H2User>().stream().eq(H2User::getName, NQQ)));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void dSelectOne() {
|
|
|
|
+ H2User h2User = userMapper.selectOne(new H2User().setName(NQQ));
|
|
|
|
+ Assert.assertNotNull(h2User);
|
|
|
|
+
|
|
|
|
+ log(h2User.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|