1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.javassist;
17
18 import static org.junit.jupiter.api.Assertions.assertTrue;
19
20 import java.io.Reader;
21
22 import javassist.util.proxy.Proxy;
23
24 import org.apache.ibatis.BaseDataTest;
25 import org.apache.ibatis.io.Resources;
26 import org.apache.ibatis.session.SqlSession;
27 import org.apache.ibatis.session.SqlSessionFactory;
28 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
29 import org.junit.jupiter.api.Assertions;
30 import org.junit.jupiter.api.BeforeAll;
31 import org.junit.jupiter.api.Test;
32
33 class JavassistTest {
34
35 private static SqlSessionFactory sqlSessionFactory;
36
37 @BeforeAll
38 static void setUp() throws Exception {
39
40 try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/javassist/mybatis-config.xml")) {
41 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
42 }
43
44
45 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
46 "org/apache/ibatis/submitted/javassist/CreateDB.sql");
47 }
48
49 @Test
50 void shouldGetAUserAndGroups() {
51 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
52 Mapper mapper = sqlSession.getMapper(Mapper.class);
53 User user = mapper.getUser(1);
54 Assertions.assertEquals("User1", user.getName());
55 assertTrue(user instanceof Proxy);
56 Assertions.assertEquals(1, user.getGroups().size());
57 }
58 }
59
60 }