15
15
*/
16
16
package org .apache .ibatis .builder ;
17
17
18
- import static org .junit .Assert .assertArrayEquals ;
19
- import static org .junit .Assert .assertNotNull ;
20
- import static org .junit .Assert .assertTrue ;
21
-
22
18
import java .io .InputStream ;
23
19
import java .io .StringReader ;
24
20
import java .sql .CallableStatement ;
25
21
import java .sql .PreparedStatement ;
26
22
import java .sql .ResultSet ;
27
23
import java .sql .SQLException ;
24
+ import java .util .Arrays ;
25
+ import java .util .HashSet ;
26
+ import java .util .Set ;
28
27
29
28
import org .apache .ibatis .builder .xml .XMLConfigBuilder ;
29
+ import org .apache .ibatis .executor .loader .cglib .CglibProxyFactory ;
30
+ import org .apache .ibatis .executor .loader .javassist .JavassistProxyFactory ;
30
31
import 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 ;
31
36
import org .apache .ibatis .session .Configuration ;
37
+ import org .apache .ibatis .session .ExecutorType ;
38
+ import org .apache .ibatis .session .LocalCacheScope ;
32
39
import org .apache .ibatis .type .BaseTypeHandler ;
33
40
import org .apache .ibatis .type .JdbcType ;
34
41
import org .apache .ibatis .type .TypeHandler ;
35
42
import org .apache .ibatis .type .TypeHandlerRegistry ;
36
43
import org .junit .Test ;
37
44
45
+ import static org .hamcrest .core .Is .*;
46
+ import static org .hamcrest .core .IsInstanceOf .*;
47
+ import static org .junit .Assert .*;
48
+
38
49
public class XmlConfigBuilderTest {
39
50
40
51
@ Test
@@ -44,6 +55,28 @@ public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
44
55
XMLConfigBuilder builder = new XMLConfigBuilder (inputStream );
45
56
Configuration config = builder .parse ();
46
57
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 ());
47
80
}
48
81
49
82
enum MyEnum {
@@ -102,4 +135,37 @@ public void registerJavaTypeInitializingTypeHandler() {
102
135
assertTrue (typeHandler instanceof EnumOrderTypeHandler );
103
136
assertArrayEquals (MyEnum .values (), ((EnumOrderTypeHandler ) typeHandler ).constants );
104
137
}
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
+
105
171
}
0 commit comments