-
Notifications
You must be signed in to change notification settings - Fork 14
/
config_mapper_test.go
47 lines (45 loc) · 1.59 KB
/
config_mapper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package gobatis
import (
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
func TestBuildConfig(t *testing.T) {
xmlStr := `
<?xml version="1.0" encoding="utf-8"?>
<mapper namespace="Mapper">
<select id="findMapById" resultType="Map">
SELECT id, name FROM user where id=#{id} order by id
</select>
<insert id="insertStructsBatch">
insert into user (name, email, create_time)
values
<foreach item="item" collection="list" open="(" close=")" separator=",">
#{Name}, #{Email}, #{CrtTm}
</foreach>
</insert>
<update id="updateByStruct">
update user set name = #{Name}, email = #{Email}
where id = #{Id}
</update>
<update id="updateByCond">
update user
<set>
<if test="Name != nil and Name != ''">name = #{Name},</if>
<if test="Email != nil and Email != ''">email = #{Email},</if>
</set>
where id = #{Id}
</update>
<delete id="deleteById">
delete from user where id=#{id}
</delete>
</mapper>
`
r := strings.NewReader(xmlStr)
conf := buildMapperConfig(r)
assert.NotNil(t, conf.getMappedStmt("Mapper.findMapById"), "Mapper.findMapById mapped stmt is nil")
assert.NotNil(t, conf.getMappedStmt("Mapper.insertStructsBatch"), "Mapper.insertStructsBatch mapped stmt is nil")
assert.NotNil(t, conf.getMappedStmt("Mapper.updateByStruct"), "Mapper.updateByStruct mapped stmt is nil")
assert.NotNil(t, conf.getMappedStmt("Mapper.deleteById"), "Mapper.deleteById mapped stmt is nil")
assert.NotNil(t, conf.getMappedStmt("Mapper.updateByCond"), "Mapper.deleteById mapped stmt is nil")
}