-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Applied formatter. - Renamed tests to clarify intention. - Removed redundant comments. - Added license headers.
- Loading branch information
Showing
11 changed files
with
286 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_resultmapid/CreateDB.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 0 additions & 77 deletions
77
src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_resultmapid/MyBatisTest.java
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
...a/org/apache/ibatis/submitted/annotion_many_one_add_resultmapid/OneManyResultMapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.submitted.annotion_many_one_add_resultmapid; | ||
|
||
import org.apache.ibatis.BaseDataTest; | ||
import org.apache.ibatis.io.Resources; | ||
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.session.SqlSessionFactoryBuilder; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.io.Reader; | ||
import java.util.List; | ||
|
||
class OneManyResultMapTest { | ||
|
||
private static SqlSessionFactory sqlSessionFactory; | ||
|
||
@BeforeAll | ||
static void setUp() throws Exception { | ||
// create an SqlSessionFactory | ||
try (Reader reader = Resources | ||
.getResourceAsReader("org/apache/ibatis/submitted/annotion_many_one_add_resultmapid/SqlMapConfig.xml")) { | ||
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); | ||
} | ||
|
||
// populate in-memory database | ||
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), | ||
"org/apache/ibatis/submitted/annotion_many_one_add_resultmapid/CreateDB.sql"); | ||
} | ||
|
||
@Test | ||
void shouldUseResultMapWithMany() { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
UserDao mapper = sqlSession.getMapper(UserDao.class); | ||
List<User> users = mapper.findAll(); | ||
assertNotNull(users); | ||
assertEquals(4, users.size()); | ||
assertEquals(2, users.get(0).getRoles().size()); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldUseResultMapInXmlWithMany() { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
UserDao mapper = sqlSession.getMapper(UserDao.class); | ||
List<User> users = mapper.findAll2(); | ||
assertNotNull(users); | ||
assertEquals(4, users.size()); | ||
assertEquals(2, users.get(0).getRoles().size()); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldUseResultMapWithOne() { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
UserDao mapper = sqlSession.getMapper(UserDao.class); | ||
List<User> users = mapper.findAll3(); | ||
assertNotNull(users); | ||
assertEquals(2, users.size()); | ||
assertNotNull(users.get(0).getRole()); | ||
assertEquals("teacher", users.get(0).getRole().getRoleName()); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldResolveResultMapInTheSameNamespace() { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
UserDao mapper = sqlSession.getMapper(UserDao.class); | ||
User headmaster = mapper.findHeadmaster(); | ||
assertNotNull(headmaster); | ||
assertEquals(3, headmaster.getTeachers().size()); | ||
assertEquals("Doug Lea", headmaster.getTeachers().get(0).getUsername()); | ||
} | ||
} | ||
|
||
} |
25 changes: 20 additions & 5 deletions
25
src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_resultmapid/Role.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 23 additions & 4 deletions
27
src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_resultmapid/RoleDao.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2009-2019 the original author or authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<!DOCTYPE mapper | ||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
<mapper namespace="org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao"> | ||
<resultMap id="roleMap2" type="org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.Role"> | ||
<id column="role_id" property="id"/> | ||
<result column="role_name" property="roleName" /> | ||
<mapper | ||
namespace="org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao"> | ||
<resultMap id="roleMap2" | ||
type="org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.Role"> | ||
<id column="role_id" property="id" /> | ||
<result column="role_name" property="roleName" /> | ||
</resultMap> | ||
</mapper> |
32 changes: 26 additions & 6 deletions
32
src/test/java/org/apache/ibatis/submitted/annotion_many_one_add_resultmapid/SqlMapConfig.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- | ||
Copyright 2009-2019 the original author or authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<!DOCTYPE configuration | ||
PUBLIC "-//mybatis.org//DTD Config 3.0//EN" | ||
"http://mybatis.org/dtd/mybatis-3-config.dtd"> | ||
<configuration> | ||
<environments default="development"> | ||
<environment id="development"> | ||
<transactionManager type="JDBC"/> | ||
<transactionManager type="JDBC" /> | ||
<dataSource type="UNPOOLED"> | ||
<property name="driver" value="org.hsqldb.jdbcDriver" /> | ||
<property name="url" value="jdbc:hsqldb:mem:annotion_many_one_add_resultmapid" /> | ||
<property name="url" | ||
value="jdbc:hsqldb:mem:annotion_many_one_add_resultmapid" /> | ||
<property name="username" value="sa" /> | ||
</dataSource> | ||
</environment> | ||
</environments> | ||
|
||
<mappers> | ||
<mapper class="org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao"/> | ||
<mapper class="org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.UserDao"/> | ||
</mappers> | ||
<mappers> | ||
<mapper | ||
class="org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.RoleDao" /> | ||
<mapper | ||
class="org.apache.ibatis.submitted.annotion_many_one_add_resultmapid.UserDao" /> | ||
</mappers> | ||
</configuration> |
Oops, something went wrong.