Skip to content

Commit 023df8a

Browse files
committed
Merge pull request #674 from kazuki43zoo/improve-tests-for-XMLConfigBuilder
Improve and add tests for XMLConfigBuilder
2 parents b05dfe2 + ea24030 commit 023df8a

16 files changed

+454
-12
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2009-2016 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+
* http://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.builder;
17+
18+
import org.apache.ibatis.domain.blog.Author;
19+
20+
public interface CachedAuthorMapper {
21+
Author selectAllAuthors();
22+
Author selectAuthorWithInlineParams(int id);
23+
void insertAuthor(Author author);
24+
boolean updateAuthor(Author author);
25+
boolean deleteAuthor(int id);
26+
}

src/test/java/org/apache/ibatis/builder/CachedAuthorMapper.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
2121
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
2222

23-
<mapper namespace="com.domain.CachedAuthorMapper">
23+
<mapper namespace="org.apache.ibatis.builder.CachedAuthorMapper">
2424

2525
<cache readOnly="true"/>
2626

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright 2009-2016 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+
* http://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.builder;
17+
18+
import org.apache.ibatis.type.JdbcType;
19+
import org.apache.ibatis.type.MappedTypes;
20+
import org.apache.ibatis.type.TypeHandler;
21+
22+
import java.sql.CallableStatement;
23+
import java.sql.PreparedStatement;
24+
import java.sql.ResultSet;
25+
import java.sql.SQLException;
26+
27+
@MappedTypes(Long.class)
28+
public class CustomLongTypeHandler implements TypeHandler<Long> {
29+
30+
@Override
31+
public void setParameter(PreparedStatement ps, int i, Long parameter, JdbcType jdbcType) throws SQLException {
32+
ps.setLong(i, parameter);
33+
}
34+
35+
@Override
36+
public Long getResult(ResultSet rs, String columnName) throws SQLException {
37+
return rs.getLong(columnName);
38+
}
39+
40+
@Override
41+
public Long getResult(ResultSet rs, int columnIndex) throws SQLException {
42+
return rs.getLong(columnIndex);
43+
}
44+
45+
@Override
46+
public Long getResult(CallableStatement cs, int columnIndex) throws SQLException {
47+
return cs.getLong(columnIndex);
48+
}
49+
50+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2009-2016 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+
* http://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.builder;
17+
18+
import org.apache.ibatis.reflection.MetaObject;
19+
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
20+
import org.apache.ibatis.reflection.wrapper.ObjectWrapper;
21+
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
22+
23+
import java.util.List;
24+
import java.util.Properties;
25+
26+
public class CustomObjectWrapperFactory implements ObjectWrapperFactory {
27+
28+
private String option;
29+
30+
@Override
31+
public boolean hasWrapperFor(Object object) {
32+
return false;
33+
}
34+
35+
@Override
36+
public ObjectWrapper getWrapperFor(MetaObject metaObject, Object object) {
37+
return null;
38+
}
39+
40+
}

src/test/java/org/apache/ibatis/builder/ExampleTypeHandler.java renamed to src/test/java/org/apache/ibatis/builder/CustomStringTypeHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2016 the original author or authors.
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.
@@ -23,7 +23,7 @@
2323
import java.sql.ResultSet;
2424
import java.sql.SQLException;
2525

26-
public class ExampleTypeHandler implements TypeHandler<String> {
26+
public class CustomStringTypeHandler implements TypeHandler<String> {
2727

2828
@Override
2929
public void setParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {

src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
<configuration>
2424

25+
<properties resource="org/apache/ibatis/builder/jdbc.properties">
26+
<property name="prop1" value="aaaa"/>
27+
</properties>
28+
2529
<settings>
2630
<setting name="autoMappingBehavior" value="NONE"/>
2731
<setting name="autoMappingUnknownColumnBehavior" value="WARNING"/>
@@ -49,4 +53,55 @@
4953
<setting name="configurationFactory" value="java.lang.String"/>
5054
</settings>
5155

56+
<typeAliases>
57+
<typeAlias alias="BlogAuthor" type="org.apache.ibatis.domain.blog.Author"/>
58+
<typeAlias type="org.apache.ibatis.domain.blog.Blog"/>
59+
<typeAlias type="org.apache.ibatis.domain.blog.Post"/>
60+
<package name="org.apache.ibatis.domain.jpetstore"/>
61+
</typeAliases>
62+
63+
<typeHandlers>
64+
<typeHandler javaType="String" handler="org.apache.ibatis.builder.CustomStringTypeHandler"/>
65+
<typeHandler javaType="String" jdbcType="VARCHAR" handler="org.apache.ibatis.builder.CustomStringTypeHandler"/>
66+
<typeHandler handler="org.apache.ibatis.builder.CustomLongTypeHandler"/>
67+
<package name="org.apache.ibatis.builder.typehandler"/>
68+
</typeHandlers>
69+
70+
<objectFactory type="org.apache.ibatis.builder.ExampleObjectFactory">
71+
<property name="objectFactoryProperty" value="100"/>
72+
</objectFactory>
73+
74+
<objectWrapperFactory type="org.apache.ibatis.builder.CustomObjectWrapperFactory" />
75+
76+
<plugins>
77+
<plugin interceptor="org.apache.ibatis.builder.ExamplePlugin">
78+
<property name="pluginProperty" value="100"/>
79+
</plugin>
80+
</plugins>
81+
82+
<environments default="development">
83+
<environment id="development">
84+
<transactionManager type="JDBC">
85+
<property name="" value=""/>
86+
</transactionManager>
87+
<dataSource type="UNPOOLED">
88+
<property name="driver" value="${driver}"/>
89+
<property name="url" value="${url}"/>
90+
<property name="username" value="${username}"/>
91+
<property name="password" value="${password}"/>
92+
</dataSource>
93+
</environment>
94+
</environments>
95+
96+
<databaseIdProvider type="VENDOR">
97+
<property name="Apache Derby" value="derby"/>
98+
</databaseIdProvider>
99+
100+
<mappers>
101+
<mapper resource="org/apache/ibatis/builder/BlogMapper.xml"/>
102+
<mapper url="file:./src/test/java/org/apache/ibatis/builder/NestedBlogMapper.xml"/>
103+
<mapper class="org.apache.ibatis.builder.CachedAuthorMapper"/>
104+
<package name="org.apache.ibatis.builder.mapper"/>
105+
</mappers>
106+
52107
</configuration>

src/test/java/org/apache/ibatis/builder/ExampleObjectFactory.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2016 the original author or authors.
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.
@@ -21,7 +21,7 @@
2121
import java.util.Properties;
2222

2323
public class ExampleObjectFactory extends DefaultObjectFactory {
24-
24+
private Properties properties;
2525
@Override
2626
public <T> T create(Class<T> type) {
2727
return super.<T>create(type);
@@ -35,6 +35,11 @@ public <T> T create(Class<T> type, List<Class<?>> constructorArgTypes, List<Obje
3535
@Override
3636
public void setProperties(Properties properties) {
3737
super.setProperties(properties);
38+
this.properties = properties;
39+
}
40+
41+
public Properties getProperties() {
42+
return properties;
3843
}
3944

4045
}

src/test/java/org/apache/ibatis/builder/ExamplePlugin.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2016 the original author or authors.
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.
@@ -24,7 +24,7 @@
2424

2525
@Intercepts({})
2626
public class ExamplePlugin implements Interceptor {
27-
27+
private Properties properties;
2828
@Override
2929
public Object intercept(Invocation invocation) throws Throwable {
3030
return invocation.proceed();
@@ -37,7 +37,11 @@ public Object plugin(Object target) {
3737

3838
@Override
3939
public void setProperties(Properties properties) {
40+
this.properties = properties;
41+
}
4042

43+
public Properties getProperties() {
44+
return properties;
4145
}
4246

4347
}

src/test/java/org/apache/ibatis/builder/MapperConfig.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
</typeAliases>
4545

4646
<typeHandlers>
47-
<typeHandler javaType="String" jdbcType="VARCHAR" handler="org.apache.ibatis.builder.ExampleTypeHandler"/>
47+
<typeHandler javaType="String" jdbcType="VARCHAR" handler="org.apache.ibatis.builder.CustomStringTypeHandler"/>
4848
</typeHandlers>
4949

5050
<objectFactory type="org.apache.ibatis.builder.ExampleObjectFactory">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
4+
Copyright 2009-2016 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<!DOCTYPE configuration
20+
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
21+
"http://mybatis.org/dtd/mybatis-3-config.dtd">
22+
23+
<configuration>
24+
25+
<properties url="file:./src/test/java/org/apache/ibatis/builder/jdbc.properties">
26+
<property name="prop1" value="bbbb"/>
27+
</properties>
28+
29+
</configuration>

0 commit comments

Comments
 (0)