Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@

package tk.mybatis.mapper.test.country;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import tk.mybatis.mapper.mapper.CountryMapper;
import tk.mybatis.mapper.mapper.MybatisHelper;
import tk.mybatis.mapper.model.Country;
import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;

/**
* 通过主键查询
Expand All @@ -38,6 +44,22 @@
*/
public class TestExistsWithPrimaryKey {

@Before
public void setupDB() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
Connection conn = sqlSession.getConnection();
Reader reader = Resources.getResourceAsReader("CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
} catch (IOException e) {}
finally {
sqlSession.close();
}
}

/**
* 根据PK进行查询
*/
Expand Down
22 changes: 22 additions & 0 deletions base/src/test/java/tk/mybatis/mapper/test/country/TestInsert.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@
package tk.mybatis.mapper.test.country;

import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import tk.mybatis.mapper.mapper.CountryMapper;
import tk.mybatis.mapper.mapper.MybatisHelper;
import tk.mybatis.mapper.model.Country;

import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;
import java.util.List;

/**
Expand All @@ -41,6 +47,22 @@
*/
public class TestInsert {

@Before
public void setupDB() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
Connection conn = sqlSession.getConnection();
Reader reader = Resources.getResourceAsReader("CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
} catch (IOException e) {}
finally {
sqlSession.close();
}
}

/**
* 插入空数据,id不能为null,会报错
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@

package tk.mybatis.mapper.test.example;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSession;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -37,6 +40,9 @@
import tk.mybatis.mapper.model.Country;
import tk.mybatis.mapper.model.Country2;

import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand All @@ -49,6 +55,22 @@ public class TestSelectByExample {
@Rule
public ExpectedException exception = ExpectedException.none();

@Before
public void setupDB() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
try {
Connection conn = sqlSession.getConnection();
Reader reader = Resources.getResourceAsReader("CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
} catch (IOException e) {}
finally {
sqlSession.close();
}
}

@Test
public void testSelectByExample() {
SqlSession sqlSession = MybatisHelper.getSqlSession();
Expand Down