Revision 44844 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.dbf/src/test/java/org/gvsig/fmap/dal/store/dbf/TestCreate.java
TestCreate.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.store.dbf; |
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 |
import java.util.Date; |
|
5 | 4 |
import java.util.List; |
6 | 5 |
import junit.framework.TestCase; |
7 | 6 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
9 | 8 |
import org.gvsig.fmap.dal.DataManager; |
10 | 9 |
import org.gvsig.fmap.dal.DataServerExplorer; |
11 | 10 |
import org.gvsig.fmap.dal.DataStore; |
11 |
import org.gvsig.fmap.dal.DataTypeUtils; |
|
12 | 12 |
import org.gvsig.fmap.dal.DataTypes; |
13 | 13 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
14 | 14 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
... | ... | |
75 | 75 |
explorer.add(getProviderName(), params, true); |
76 | 76 |
} |
77 | 77 |
|
78 |
protected void checkTypes(FeatureType sourceFeatureType) throws Exception { |
|
79 |
// DataType STRING_TYPE = ToolsLocator.getDataTypesManager().get(DataTypes.STRING); |
|
80 |
// DataType INT_TYPE = ToolsLocator.getDataTypesManager().get(DataTypes.INT); |
|
81 |
|
|
78 |
protected void checkTypes(FeatureType sourceFeatureType, boolean useDalFile) throws Exception { |
|
82 | 79 |
FeatureStore targetStore = openTargetStore1(); |
83 | 80 |
FeatureType targetFeatureType = targetStore.getDefaultFeatureType(); |
84 | 81 |
|
... | ... | |
89 | 86 |
assertEquals(sourceAttr.getName(), sourceAttr.getName(), targetAttr.getName()); |
90 | 87 |
switch(sourceAttr.getType()) { |
91 | 88 |
case DataTypes.TIME: |
92 |
if( targetAttr.getType()==DataTypes.STRING ) { |
|
93 |
// Cuando no hay fichero DAL puede leer un TIME como |
|
94 |
// un STRING de tama?o TIME_SIZE. |
|
95 |
assertEquals( |
|
96 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
97 |
FieldFormatter.TIME_SIZE, |
|
98 |
targetAttr.getSize() |
|
99 |
); |
|
100 |
} else if( targetAttr.getType()==DataTypes.TIME ) { |
|
101 |
// Si hay fichero DAL el tipo pude ser correcto (TIME). |
|
102 |
assertEquals( |
|
103 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
104 |
sourceAttr.getSize(), |
|
105 |
targetAttr.getSize() |
|
106 |
); |
|
107 |
} |
|
108 | 89 |
assertEquals( |
90 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
91 |
useDalFile?sourceAttr.getDataTypeName():DataTypes.STRING_NAME, |
|
92 |
targetAttr.getDataTypeName() |
|
93 |
); |
|
94 |
assertEquals( |
|
95 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
96 |
targetAttr.getSize(), |
|
97 |
useDalFile? targetAttr.getSize():FieldFormatter.TIME_SIZE |
|
98 |
); |
|
99 |
assertEquals( |
|
109 | 100 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
110 | 101 |
sourceAttr.getPrecision(), |
111 | 102 |
targetAttr.getPrecision() |
... | ... | |
117 | 108 |
); |
118 | 109 |
break; |
119 | 110 |
case DataTypes.TIMESTAMP: |
120 |
if( targetAttr.getType()==DataTypes.STRING ) { |
|
121 |
// Cuando no hay fichero DAL puede leer un TIMESTAMP como |
|
122 |
// un STRING de tama?o TIMESTAMP_SIZE. |
|
123 |
assertEquals( |
|
124 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
125 |
FieldFormatter.TIMESTAMP_SIZE, |
|
126 |
targetAttr.getSize() |
|
127 |
); |
|
128 |
} else if( targetAttr.getType()==DataTypes.TIMESTAMP ) { |
|
129 |
// Si hay fichero DAL el tipo pude ser correcto (TIMESTAMP). |
|
130 |
assertEquals( |
|
131 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
132 |
sourceAttr.getSize(), |
|
133 |
targetAttr.getSize() |
|
134 |
); |
|
135 |
} |
|
136 | 111 |
assertEquals( |
112 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
113 |
useDalFile?sourceAttr.getDataTypeName():DataTypes.STRING_NAME, |
|
114 |
targetAttr.getDataTypeName() |
|
115 |
); |
|
116 |
assertEquals( |
|
117 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
118 |
targetAttr.getSize(), |
|
119 |
useDalFile? targetAttr.getSize():FieldFormatter.TIMESTAMP_SIZE |
|
120 |
); |
|
121 |
assertEquals( |
|
137 | 122 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
138 | 123 |
sourceAttr.getPrecision(), |
139 | 124 |
targetAttr.getPrecision() |
... | ... | |
144 | 129 |
targetAttr.getScale() |
145 | 130 |
); |
146 | 131 |
break; |
132 |
case DataTypes.DECIMAL: |
|
133 |
assertEquals( |
|
134 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
135 |
sourceAttr.getDataTypeName(), |
|
136 |
targetAttr.getDataTypeName() |
|
137 |
); |
|
138 |
assertEquals( |
|
139 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
140 |
sourceAttr.getSize(), |
|
141 |
targetAttr.getSize() |
|
142 |
); |
|
143 |
assertEquals( |
|
144 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
145 |
useDalFile?sourceAttr.getPrecision():sourceAttr.getPrecision()+1, |
|
146 |
targetAttr.getPrecision() |
|
147 |
); |
|
148 |
assertEquals( |
|
149 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
150 |
sourceAttr.getScale(), |
|
151 |
targetAttr.getScale() |
|
152 |
); |
|
153 |
break; |
|
154 |
|
|
147 | 155 |
case DataTypes.BYTE: |
156 |
assertEquals( |
|
157 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
158 |
useDalFile?sourceAttr.getDataTypeName():DataTypes.DECIMAL_NAME, |
|
159 |
targetAttr.getDataTypeName() |
|
160 |
); |
|
161 |
assertEquals( |
|
162 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
163 |
sourceAttr.getSize(), |
|
164 |
targetAttr.getSize() |
|
165 |
); |
|
166 |
assertEquals( |
|
167 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
168 |
sourceAttr.getPrecision(), |
|
169 |
targetAttr.getPrecision() |
|
170 |
); |
|
171 |
assertEquals( |
|
172 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
173 |
sourceAttr.getScale(), |
|
174 |
targetAttr.getScale() |
|
175 |
); |
|
176 |
break; |
|
177 |
|
|
148 | 178 |
case DataTypes.INT: |
149 | 179 |
case DataTypes.LONG: |
150 | 180 |
case DataTypes.BOOLEAN: |
151 | 181 |
case DataTypes.DATE: |
152 | 182 |
case DataTypes.STRING: |
153 |
case DataTypes.DECIMAL: |
|
154 | 183 |
case DataTypes.DOUBLE: |
155 | 184 |
case DataTypes.FLOAT: |
156 | 185 |
assertEquals( |
... | ... | |
196 | 225 |
protected void checkData(FeatureStore sourceStore) throws Exception { |
197 | 226 |
FeatureStore targetStore = openTargetStore1(); |
198 | 227 |
|
228 |
FeatureType sourceFeatureType = sourceStore.getDefaultFeatureType(); |
|
229 |
FeatureType targetFeatureType = targetStore.getDefaultFeatureType(); |
|
230 |
|
|
199 | 231 |
List<Feature> sourceFeatures = sourceStore.getFeatures(); |
200 | 232 |
List<Feature> targetFeatures = targetStore.getFeatures(); |
233 |
|
|
201 | 234 |
assertEquals("Count features", sourceFeatures.size(), targetFeatures.size()); |
202 | 235 |
for (int i = 0; i < targetFeatures.size(); i++) { |
203 | 236 |
Feature sourceFeature = sourceFeatures.get(i); |
204 | 237 |
Feature targetFeature = targetFeatures.get(i); |
205 |
for (FeatureAttributeDescriptor sourceAttr : sourceStore.getDefaultFeatureType()) { |
|
238 |
for (FeatureAttributeDescriptor sourceAttr : sourceFeatureType) { |
|
239 |
FeatureAttributeDescriptor targetAttr = targetFeatureType.getAttributeDescriptor(sourceAttr.getName()); |
|
206 | 240 |
switch(sourceAttr.getType()) { |
207 | 241 |
case DataTypes.TIMESTAMP: |
208 | 242 |
assertEquals( |
... | ... | |
225 | 259 |
targetFeature.get(sourceAttr.getName()) |
226 | 260 |
); |
227 | 261 |
break; |
228 |
default:
|
|
262 |
case DataTypes.BYTE:
|
|
229 | 263 |
assertEquals( |
230 | 264 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
231 | 265 |
sourceFeature.get(sourceAttr.getName()), |
266 |
DataTypeUtils.coerce(DataTypes.BYTE, targetFeature.get(sourceAttr.getName()),null) |
|
267 |
); |
|
268 |
break; |
|
269 |
default: |
|
270 |
assertEquals( |
|
271 |
String.format("Feature %03d attribute %s (%s/%s)", i, sourceAttr.getName(), sourceAttr.getDataType().getName(), targetAttr.getDataType().getName() ), |
|
272 |
sourceFeature.get(sourceAttr.getName()), |
|
232 | 273 |
targetFeature.get(sourceAttr.getName()) |
233 | 274 |
); |
234 | 275 |
} |
... | ... | |
242 | 283 |
|
243 | 284 |
createFrom(sourceStore); |
244 | 285 |
|
245 |
checkTypes(sourceStore.getDefaultFeatureType()); |
|
286 |
checkTypes(sourceStore.getDefaultFeatureType(),true);
|
|
246 | 287 |
copyFrom(sourceStore, FeatureStore.MODE_APPEND); |
247 | 288 |
checkData(sourceStore); |
248 | 289 |
|
... | ... | |
258 | 299 |
createFrom(sourceStore); |
259 | 300 |
TestUtils.removeDALFile(this.getTargetFilename()); |
260 | 301 |
|
261 |
checkTypes(sourceStore.getDefaultFeatureType()); |
|
302 |
checkTypes(sourceStore.getDefaultFeatureType(),false);
|
|
262 | 303 |
copyFrom(sourceStore, FeatureStore.MODE_APPEND); |
263 | 304 |
TestUtils.removeDALFile(this.getTargetFilename()); |
264 | 305 |
checkData(sourceStore); |
Also available in: Unified diff