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.inline_association_with_dot;
17  
18  import static org.junit.jupiter.api.Assertions.assertEquals;
19  
20  import java.io.Reader;
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.AfterEach;
28  import org.junit.jupiter.api.Test;
29  
30  class InlineCollectionWithDotTest {
31  
32    private SqlSession sqlSession;
33  
34    public void openSession(String aConfig) throws Exception {
35  
36      final String resource = "org/apache/ibatis/submitted/inline_association_with_dot/ibatis-" + aConfig + ".xml";
37      try (Reader batisConfigReader = Resources.getResourceAsReader(resource)) {
38  
39        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(batisConfigReader);
40  
41        BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
42            "org/apache/ibatis/submitted/inline_association_with_dot/create.sql");
43  
44        sqlSession = sqlSessionFactory.openSession();
45      }
46    }
47  
48    @AfterEach
49    void closeSession() {
50      if (sqlSession != null) {
51        sqlSession.close();
52      }
53    }
54  
55    /*
56     * Load an element with an element with and element with a value. Expect that this is possible bij using an inline
57     * 'association' map.
58     */
59    @Test
60    void selectElementValueInContainerUsingInline() throws Exception {
61      openSession("inline");
62  
63      Element myElement = sqlSession.getMapper(ElementMapperUsingInline.class).selectElement();
64  
65      assertEquals("value", myElement.getElement().getElement().getValue());
66    }
67  
68    /*
69     * Load an element with an element with and element with a value. Expect that this is possible bij using an
70     * sub-'association' map.
71     */
72    @Test
73    void selectElementValueInContainerUsingSubMap() throws Exception {
74      openSession("submap");
75  
76      Element myElement = sqlSession.getMapper(ElementMapperUsingSubMap.class).selectElement();
77  
78      assertEquals("value", myElement.getElement().getElement().getValue());
79    }
80  }