19
19
import java .sql .Connection ;
20
20
import java .util .List ;
21
21
22
- import org .apache .ibatis .exceptions .PersistenceException ;
23
22
import org .apache .ibatis .io .Resources ;
24
23
import org .apache .ibatis .jdbc .ScriptRunner ;
25
24
import org .apache .ibatis .session .SqlSession ;
26
25
import org .apache .ibatis .session .SqlSessionFactory ;
27
26
import org .apache .ibatis .session .SqlSessionFactoryBuilder ;
28
27
import org .junit .Assert ;
28
+ import org .junit .BeforeClass ;
29
29
import org .junit .Test ;
30
30
31
31
public class ResultMapWithAssociationsTest {
32
32
33
- private static SqlSessionFactory sqlSessionFactory ;
33
+ private static SqlSessionFactory sqlSessionFactory ;
34
34
35
- @ Test ( expected = PersistenceException . class )
36
- public void testMissingColumn () throws Exception {
37
- // create a SqlSessionFactory
38
- Reader reader = Resources .getResourceAsReader ("org/apache/ibatis/submitted/resultmapwithassociationstest/mybatis-config.xml" );
39
- sqlSessionFactory = new SqlSessionFactoryBuilder ().build (reader );
40
- reader .close ();
35
+ @ BeforeClass
36
+ public static void setUp () throws Exception {
37
+ // create a SqlSessionFactory
38
+ Reader reader = Resources .getResourceAsReader ("org/apache/ibatis/submitted/resultmapwithassociationstest/mybatis-config.xml" );
39
+ sqlSessionFactory = new SqlSessionFactoryBuilder ().build (reader );
40
+ reader .close ();
41
41
42
- // populate in-memory database
43
- SqlSession session = sqlSessionFactory .openSession ();
44
- Connection conn = session .getConnection ();
45
- reader = Resources .getResourceAsReader ("org/apache/ibatis/submitted/resultmapwithassociationstest/CreateDB.sql" );
46
- ScriptRunner runner = new ScriptRunner (conn );
47
- runner .setLogWriter (null );
48
- runner .runScript (reader );
49
- reader .close ();
50
- session .close ();
51
- }
42
+ // populate in-memory database
43
+ SqlSession session = sqlSessionFactory .openSession ();
44
+ Connection conn = session .getConnection ();
45
+ reader = Resources .getResourceAsReader ("org/apache/ibatis/submitted/resultmapwithassociationstest/CreateDB.sql" );
46
+ ScriptRunner runner = new ScriptRunner (conn );
47
+ runner .setLogWriter (null );
48
+ runner .runScript (reader );
49
+ reader .close ();
50
+ session .close ();
51
+ }
52
52
53
- public void shouldFindAllPersonRecordsWithAssociatedAddressRecord () {
54
- SqlSession sqlSession = sqlSessionFactory .openSession ();
55
- try {
56
- Mapper mapper = sqlSession .getMapper (Mapper .class );
57
- List <Person > resultList = mapper .findAll ();
58
- Assert .assertEquals (3 , resultList .size ());
59
- }
60
- finally {
61
- sqlSession .close ();
62
- }
53
+ @ Test
54
+ public void shouldFindAllPersonRecordsWithAssociatedAddressRecord () {
55
+ SqlSession sqlSession = sqlSessionFactory .openSession ();
56
+ try {
57
+ Mapper mapper = sqlSession .getMapper (Mapper .class );
58
+ List <Person > resultList = mapper .findAll ();
59
+ Assert .assertEquals (3 , resultList .size ());
60
+ } finally {
61
+ sqlSession .close ();
63
62
}
63
+ }
64
64
65
65
}
0 commit comments