View Javadoc
1   /*
2    *    Copyright 2009-2023 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
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      // create a SqlSessionFactory
37      try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_type/mybatis-config.xml")) {
38        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
39      }
40  
41      // populate in-memory database
42      BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
43          "org/apache/ibatis/submitted/complex_type/CreateDB.sql");
44    }
45  
46    // see https://issues.apache.org/jira/browse/IBATIS-653
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  }