1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.submitted.complex_type;
17
18 import java.io.Reader;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.ibatis.BaseDataTest;
23 import org.apache.ibatis.io.Resources;
24 import org.apache.ibatis.session.SqlSession;
25 import org.apache.ibatis.session.SqlSessionFactory;
26 import org.apache.ibatis.session.SqlSessionFactoryBuilder;
27 import org.junit.jupiter.api.BeforeAll;
28 import org.junit.jupiter.api.Test;
29
30 class ComplexTypeTest {
31
32 private static SqlSessionFactory sqlSessionFactory;
33
34 @BeforeAll
35 static void setUp() throws Exception {
36
37 try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_type/mybatis-config.xml")) {
38 sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
39 }
40
41
42 BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
43 "org/apache/ibatis/submitted/complex_type/CreateDB.sql");
44 }
45
46
47 @Test
48 void shouldUpdateProps() {
49 try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
50 Item item = new Item();
51 item.id = 10;
52 Property p1 = new Property();
53 p1.id = 11;
54 p1.value = "value11";
55 Property p2 = new Property();
56 p2.id = 12;
57 p2.value = "value12";
58 List<Property> list = new ArrayList<>();
59 list.add(p1);
60 list.add(p2);
61 item.properties = list;
62 sqlSession.update("updateProps", item);
63 }
64 }
65
66 }