Skip to content

Commit d8246ab

Browse files
committed
Added an insert statement to basetest
1 parent cc3b510 commit d8246ab

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

src/test/java/org/apache/ibatis/submitted/basetest/BaseTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2012 The MyBatis Team
2+
* Copyright 2009-2013 The MyBatis Team
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,7 @@ public class BaseTest {
3333

3434
@BeforeClass
3535
public static void setUp() throws Exception {
36-
// create a SqlSessionFactory
36+
// create an SqlSessionFactory
3737
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/basetest/mybatis-config.xml");
3838
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
3939
reader.close();
@@ -61,4 +61,18 @@ public void shouldGetAUser() {
6161
}
6262
}
6363

64+
@Test
65+
public void shouldInsertAUser() {
66+
SqlSession sqlSession = sqlSessionFactory.openSession();
67+
try {
68+
Mapper mapper = sqlSession.getMapper(Mapper.class);
69+
User user = new User();
70+
user.setId(2);
71+
user.setName("User2");
72+
mapper.insertUser(user);
73+
} finally {
74+
sqlSession.close();
75+
}
76+
}
77+
6478
}

src/test/java/org/apache/ibatis/submitted/basetest/Mapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
public interface Mapper {
1919

2020
User getUser(Integer id);
21+
void insertUser(User user);
2122

2223
}

src/test/java/org/apache/ibatis/submitted/basetest/Mapper.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
Copyright 2009-2012 The MyBatis Team
3+
Copyright 2009-2013 The MyBatis Team
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -21,7 +21,11 @@
2121
<mapper namespace="org.apache.ibatis.submitted.basetest.Mapper">
2222

2323
<select id="getUser" resultType="org.apache.ibatis.submitted.basetest.User">
24-
select * from users
24+
select * from users where id = #{id}
2525
</select>
2626

27+
<insert id="insertUser">
28+
insert into users values(#{id}, #{name})
29+
</insert>
30+
2731
</mapper>

src/test/java/org/apache/ibatis/submitted/basetest/mybatis-config.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<!--
3-
Copyright 2009-2012 The MyBatis Team
3+
Copyright 2009-2013 The MyBatis Team
44
55
Licensed under the Apache License, Version 2.0 (the "License");
66
you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@
3434
</environments>
3535

3636
<mappers>
37-
<mapper resource="org/apache/ibatis/submitted/basetest/Mapper.xml" />
37+
<mapper class="org.apache.ibatis.submitted.basetest.Mapper" />
3838
</mappers>
3939

4040
</configuration>

0 commit comments

Comments
 (0)