1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.dbunit.database;
22
23 import org.dbunit.dataset.datatype.DataType;
24 import org.dbunit.dataset.datatype.DataTypeException;
25 import org.dbunit.dataset.datatype.IDataTypeFactory;
26
27 import junit.framework.TestCase;
28
29
30
31
32
33
34
35 public class DatabaseConfigTest extends TestCase
36 {
37 public void testSetProperty_InvalidType_Array() throws Exception
38 {
39 DatabaseConfig config = new DatabaseConfig();
40 String simpleString = "TABLE";
41 try {
42 config.setProperty(DatabaseConfig.PROPERTY_TABLE_TYPE, simpleString);
43 fail("The property 'table type' should be a string array");
44 }
45 catch(IllegalArgumentException expected){
46 String expectedMsg = "Cannot cast object of type 'class java.lang.String' to allowed type 'class [Ljava.lang.String;'.";
47 assertEquals(expectedMsg, expected.getMessage());
48 }
49 }
50
51 public void testSetProperty_CorrectType_Array() throws Exception
52 {
53 DatabaseConfig config = new DatabaseConfig();
54 String[] stringArray = new String[] {"TABLE"};
55 config.setProperty(DatabaseConfig.PROPERTY_TABLE_TYPE, stringArray);
56 assertEquals(stringArray, config.getProperty(DatabaseConfig.PROPERTY_TABLE_TYPE));
57 }
58
59 public void testSetProperty_Interface() throws Exception
60 {
61 DatabaseConfig config = new DatabaseConfig();
62 IDataTypeFactory myFactory = new IDataTypeFactory() {
63
64 public DataType createDataType(int sqlType, String sqlTypeName,
65 String tableName, String columnName) throws DataTypeException {
66 return null;
67 }
68
69 public DataType createDataType(int sqlType, String sqlTypeName)
70 throws DataTypeException {
71 return null;
72 }
73 };
74 config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, myFactory);
75 assertEquals(myFactory, config.getProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY));
76 }
77
78 public void testSetPropertyToNullWhereNotAllowed() throws Exception
79 {
80 DatabaseConfig config = new DatabaseConfig();
81 try {
82 config.setProperty(DatabaseConfig.PROPERTY_BATCH_SIZE, null);
83 assertEquals(null, config.getProperty(DatabaseConfig.PROPERTY_BATCH_SIZE));
84 fail("Should not be able to set a not-nullable property to null");
85 }
86 catch(IllegalArgumentException expected){
87 String expectedMsg = "The property 'http://www.dbunit.org/properties/batchSize' is not nullable.";
88 assertEquals(expectedMsg, expected.getMessage());
89 }
90 }
91
92 public void testSetPropertyToNullWhereAllowed() throws Exception
93 {
94 DatabaseConfig config = new DatabaseConfig();
95 config.setProperty(DatabaseConfig.PROPERTY_PRIMARY_KEY_FILTER, null);
96 assertEquals(null, config.getProperty(DatabaseConfig.PROPERTY_PRIMARY_KEY_FILTER));
97 }
98
99 public void testSetFeatureViaSetPropertyMethod() throws Exception
100 {
101 DatabaseConfig config = new DatabaseConfig();
102 config.setProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, "true");
103 assertEquals(Boolean.TRUE, config.getProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS));
104 assertEquals(true, config.getFeature(DatabaseConfig.FEATURE_BATCHED_STATEMENTS));
105 }
106
107 public void testSetFeatureViaSetFeatureMethod() throws Exception
108 {
109 DatabaseConfig config = new DatabaseConfig();
110 config.setFeature(DatabaseConfig.FEATURE_BATCHED_STATEMENTS, true);
111 assertEquals(Boolean.TRUE, config.getProperty(DatabaseConfig.FEATURE_BATCHED_STATEMENTS));
112 assertEquals(true, config.getFeature(DatabaseConfig.FEATURE_BATCHED_STATEMENTS));
113 }
114
115 }