1515 */
1616package org .apache .ibatis .builder ;
1717
18- import static org .junit .Assert .assertArrayEquals ;
19- import static org .junit .Assert .assertNotNull ;
20- import static org .junit .Assert .assertTrue ;
21-
2218import java .io .InputStream ;
2319import java .io .StringReader ;
2420import java .sql .CallableStatement ;
2521import java .sql .PreparedStatement ;
2622import java .sql .ResultSet ;
2723import java .sql .SQLException ;
24+ import java .util .Arrays ;
25+ import java .util .HashSet ;
26+ import java .util .Set ;
2827
2928import org .apache .ibatis .builder .xml .XMLConfigBuilder ;
29+ import org .apache .ibatis .executor .loader .cglib .CglibProxyFactory ;
30+ import org .apache .ibatis .executor .loader .javassist .JavassistProxyFactory ;
3031import org .apache .ibatis .io .Resources ;
32+ import org .apache .ibatis .logging .slf4j .Slf4jImpl ;
33+ import org .apache .ibatis .scripting .defaults .RawLanguageDriver ;
34+ import org .apache .ibatis .scripting .xmltags .XMLLanguageDriver ;
35+ import org .apache .ibatis .session .AutoMappingBehavior ;
3136import org .apache .ibatis .session .Configuration ;
37+ import org .apache .ibatis .session .ExecutorType ;
38+ import org .apache .ibatis .session .LocalCacheScope ;
3239import org .apache .ibatis .type .BaseTypeHandler ;
3340import org .apache .ibatis .type .JdbcType ;
3441import org .apache .ibatis .type .TypeHandler ;
3542import org .apache .ibatis .type .TypeHandlerRegistry ;
3643import org .junit .Test ;
3744
45+ import static org .hamcrest .core .Is .*;
46+ import static org .hamcrest .core .IsInstanceOf .*;
47+ import static org .junit .Assert .*;
48+
3849public class XmlConfigBuilderTest {
3950
4051 @ Test
@@ -44,6 +55,28 @@ public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
4455 XMLConfigBuilder builder = new XMLConfigBuilder (inputStream );
4556 Configuration config = builder .parse ();
4657 assertNotNull (config );
58+ assertThat (config .getAutoMappingBehavior (), is (AutoMappingBehavior .PARTIAL ));
59+ assertThat (config .isCacheEnabled (), is (true ));
60+ assertThat (config .getProxyFactory (), is (instanceOf (JavassistProxyFactory .class )));
61+ assertThat (config .isLazyLoadingEnabled (), is (false ));
62+ assertThat (config .isAggressiveLazyLoading (), is (true ));
63+ assertThat (config .isMultipleResultSetsEnabled (), is (true ));
64+ assertThat (config .isUseColumnLabel (), is (true ));
65+ assertThat (config .isUseGeneratedKeys (), is (false ));
66+ assertThat (config .getDefaultExecutorType (), is (ExecutorType .SIMPLE ));
67+ assertNull (config .getDefaultStatementTimeout ());
68+ assertNull (config .getDefaultFetchSize ());
69+ assertThat (config .isMapUnderscoreToCamelCase (), is (false ));
70+ assertThat (config .isSafeRowBoundsEnabled (), is (false ));
71+ assertThat (config .getLocalCacheScope (), is (LocalCacheScope .SESSION ));
72+ assertThat (config .getJdbcTypeForNull (), is (JdbcType .OTHER ));
73+ assertThat (config .getLazyLoadTriggerMethods (), is ((Set <String >) new HashSet <String >(Arrays .asList ("equals" , "clone" , "hashCode" , "toString" ))));
74+ assertThat (config .isSafeResultHandlerEnabled (), is (true ));
75+ assertThat (config .getDefaultScriptingLanuageInstance (), is (instanceOf (XMLLanguageDriver .class )));
76+ assertThat (config .isCallSettersOnNulls (), is (false ));
77+ assertNull (config .getLogPrefix ());
78+ assertNull (config .getLogImpl ());
79+ assertNull (config .getConfigurationFactory ());
4780 }
4881
4982 enum MyEnum {
@@ -102,4 +135,37 @@ public void registerJavaTypeInitializingTypeHandler() {
102135 assertTrue (typeHandler instanceof EnumOrderTypeHandler );
103136 assertArrayEquals (MyEnum .values (), ((EnumOrderTypeHandler ) typeHandler ).constants );
104137 }
138+
139+ @ Test
140+ public void shouldSuccessfullyLoadXMLConfigFile () throws Exception {
141+ String resource = "org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml" ;
142+ InputStream inputStream = Resources .getResourceAsStream (resource );
143+ XMLConfigBuilder builder = new XMLConfigBuilder (inputStream );
144+ Configuration config = builder .parse ();
145+
146+ assertThat (config .getAutoMappingBehavior (), is (AutoMappingBehavior .NONE ));
147+ assertThat (config .isCacheEnabled (), is (false ));
148+ assertThat (config .getProxyFactory (), is (instanceOf (CglibProxyFactory .class )));
149+ assertThat (config .isLazyLoadingEnabled (), is (true ));
150+ assertThat (config .isAggressiveLazyLoading (), is (false ));
151+ assertThat (config .isMultipleResultSetsEnabled (), is (false ));
152+ assertThat (config .isUseColumnLabel (), is (false ));
153+ assertThat (config .isUseGeneratedKeys (), is (true ));
154+ assertThat (config .getDefaultExecutorType (), is (ExecutorType .BATCH ));
155+ assertThat (config .getDefaultStatementTimeout (), is (10 ));
156+ assertThat (config .getDefaultFetchSize (), is (100 ));
157+ assertThat (config .isMapUnderscoreToCamelCase (), is (true ));
158+ assertThat (config .isSafeRowBoundsEnabled (), is (true ));
159+ assertThat (config .getLocalCacheScope (), is (LocalCacheScope .STATEMENT ));
160+ assertThat (config .getJdbcTypeForNull (), is (JdbcType .NULL ));
161+ assertThat (config .getLazyLoadTriggerMethods (), is ((Set <String >) new HashSet <String >(Arrays .asList ("equals" , "clone" , "hashCode" , "toString" , "xxx" ))));
162+ assertThat (config .isSafeResultHandlerEnabled (), is (false ));
163+ assertThat (config .getDefaultScriptingLanuageInstance (), is (instanceOf (RawLanguageDriver .class )));
164+ assertThat (config .isCallSettersOnNulls (), is (true ));
165+ assertThat (config .getLogPrefix (), is ("mybatis_" ));
166+ assertThat (config .getLogImpl ().getName (), is (Slf4jImpl .class .getName ()));
167+ assertThat (config .getConfigurationFactory ().getName (), is (String .class .getName ()));
168+
169+ }
170+
105171}
0 commit comments