|
@@ -1,20 +1,9 @@
|
|
|
package com.baomidou.mybatisplus.test.h2;
|
|
|
|
|
|
-import java.io.BufferedReader;
|
|
|
-import java.io.FileReader;
|
|
|
-import java.io.IOException;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.sql.Connection;
|
|
|
-import java.sql.SQLException;
|
|
|
-import java.sql.Statement;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Random;
|
|
|
-
|
|
|
-import javax.sql.DataSource;
|
|
|
-
|
|
|
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
+import com.baomidou.mybatisplus.plugins.Page;
|
|
|
+import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
|
|
|
+import com.baomidou.mybatisplus.test.h2.entity.service.IH2UserService;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.BeforeClass;
|
|
|
import org.junit.Test;
|
|
@@ -25,10 +14,13 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|
|
import org.springframework.test.context.ContextConfiguration;
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
-import com.baomidou.mybatisplus.plugins.Page;
|
|
|
-import com.baomidou.mybatisplus.test.h2.entity.persistent.H2User;
|
|
|
-import com.baomidou.mybatisplus.test.h2.entity.service.IH2UserService;
|
|
|
+import javax.sql.DataSource;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.sql.Connection;
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Statement;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -40,7 +32,7 @@ import com.baomidou.mybatisplus.test.h2.entity.service.IH2UserService;
|
|
|
*/
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
@ContextConfiguration(locations = {"classpath:h2/spring-test-h2.xml"})
|
|
|
-public class H2UserTest {
|
|
|
+public class H2UserTest extends H2Test {
|
|
|
|
|
|
@Autowired
|
|
|
private IH2UserService userService;
|
|
@@ -55,39 +47,11 @@ public class H2UserTest {
|
|
|
Statement stmt = conn.createStatement();
|
|
|
stmt.execute(createTableSql);
|
|
|
stmt.execute("truncate table h2user");
|
|
|
- insertUsers(stmt);
|
|
|
+ executeSql(stmt, "user.insert.sql");
|
|
|
conn.commit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void insertUsers(Statement stmt) throws SQLException, IOException {
|
|
|
- String filename = "user.insert.sql";
|
|
|
- String filePath = H2UserTest.class.getClassLoader().getResource("").getPath() + "/h2/" + filename;
|
|
|
- try (
|
|
|
- BufferedReader reader = new BufferedReader(new FileReader(filePath))
|
|
|
- ) {
|
|
|
- String line;
|
|
|
- while ((line = reader.readLine()) != null) {
|
|
|
- stmt.execute(line.replace(";", ""));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private static String readFile(String filename) {
|
|
|
- StringBuilder builder = new StringBuilder();
|
|
|
- String filePath = H2UserTest.class.getClassLoader().getResource("").getPath() + "/h2/" + filename;
|
|
|
- try (
|
|
|
- BufferedReader reader = new BufferedReader(new FileReader(filePath))
|
|
|
- ) {
|
|
|
- String line;
|
|
|
- while ((line = reader.readLine()) != null)
|
|
|
- builder.append(line).append(" ");
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return builder.toString();
|
|
|
- }
|
|
|
-
|
|
|
@Test
|
|
|
public void testInsert() {
|
|
|
H2User user = new H2User();
|
|
@@ -101,7 +65,6 @@ public class H2UserTest {
|
|
|
Assert.assertEquals("Caratacus", userFromDB.getDesc());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Test
|
|
|
public void testInsertBatch() {
|
|
|
userService.insert(new H2User("sanmao", 1));
|