Revision 23303 branches/v2_0_0_prep/libraries/libFMap_dataFile/src-test/org/gvsig/fmap/data/feature/file/DataStoreTest.java
DataStoreTest.java | ||
---|---|---|
6 | 6 |
import junit.framework.TestCase; |
7 | 7 |
|
8 | 8 |
import org.cresques.cts.IProjection; |
9 |
import org.gvsig.tools.exception.BaseException; |
|
10 | 9 |
import org.gvsig.fmap.crs.CRSFactory; |
11 | 10 |
import org.gvsig.fmap.data.CloseException; |
12 | 11 |
import org.gvsig.fmap.data.DataCollection; |
... | ... | |
38 | 37 |
import org.gvsig.fmap.data.feature.visitor.PrintlnFeaturesVisitor; |
39 | 38 |
import org.gvsig.fmap.geom.Geometry; |
40 | 39 |
import org.gvsig.fmap.geom.handler.Handler; |
40 |
import org.gvsig.tools.exception.BaseException; |
|
41 | 41 |
import org.gvsig.tools.observer.Observer; |
42 | 42 |
|
43 | 43 |
import com.iver.utiles.XMLEntity; |
... | ... | |
975 | 975 |
String order, boolean testEdit) { |
976 | 976 |
DataManager dsm = DataManager.getManager(); |
977 | 977 |
|
978 |
|
|
978 | 979 |
// DataStoreParameters dsp=dsm.createDataStoreParameters(DriverStore.DATASTORE_NAME); |
979 | 980 |
|
980 | 981 |
// ((IDriverStoreParameters)dsp).setDriverParameters(dp); |
... | ... | |
1476 | 1477 |
} |
1477 | 1478 |
|
1478 | 1479 |
} |
1480 |
|
|
1481 |
public void cloneFeatureTypeTest() { |
|
1482 |
|
|
1483 |
org.gvsig.fmap.data.feature.file.dbf.Register.selfRegister(); |
|
1484 |
|
|
1485 |
DataManager dsm = DataManager.getManager(); |
|
1486 |
|
|
1487 |
DataStoreParameters dp; |
|
1488 |
try { |
|
1489 |
dp = dsm.createDataStoreParameters(DBFStore.DATASTORE_NAME); |
|
1490 |
} catch (InitializeException e1) { |
|
1491 |
e1.printStackTrace(); |
|
1492 |
fail(); |
|
1493 |
return; |
|
1494 |
} |
|
1495 |
((DBFStoreParameters) dp).setFile(dbffile); |
|
1496 |
|
|
1497 |
FeatureStore fs = null; |
|
1498 |
try { |
|
1499 |
fs = (FeatureStore) dsm.createDataStore(dp); |
|
1500 |
} catch (InitializeException e) { |
|
1501 |
e.printStackTrace(); |
|
1502 |
fail("Exception:" + e); |
|
1503 |
return; |
|
1504 |
} |
|
1505 |
assertNotNull("Can't create Feature Store", fs); |
|
1506 |
|
|
1507 |
compareFeatureType(fs.getDefaultFeatureType(), fs |
|
1508 |
.getDefaultFeatureType() |
|
1509 |
.cloneFeatureType()); |
|
1510 |
|
|
1511 |
FeatureCollection fc = null; |
|
1512 |
|
|
1513 |
try { |
|
1514 |
fc = (FeatureCollection) fs.getDataCollection(); |
|
1515 |
} catch (ReadException e1) { |
|
1516 |
e1.printStackTrace(); |
|
1517 |
fail(); |
|
1518 |
return; |
|
1519 |
} |
|
1520 |
|
|
1521 |
|
|
1522 |
compareFeatureType(fs.getDefaultFeatureType(), fc.getFeatureType()); |
|
1523 |
|
|
1524 |
|
|
1525 |
|
|
1526 |
fc.dispose(); |
|
1527 |
|
|
1528 |
try { |
|
1529 |
fs.addEvaluatedAttribute(null, "eva1", |
|
1530 |
FeatureAttributeDescriptor.TYPE_STRING, "lower(' ')", null); |
|
1531 |
} catch (ReadException e1) { |
|
1532 |
e1.printStackTrace(); |
|
1533 |
fail(); |
|
1534 |
return; |
|
1535 |
} |
|
1536 |
|
|
1537 |
|
|
1538 |
compareFeatureType(fs.getDefaultFeatureType(), fs |
|
1539 |
.getDefaultFeatureType().cloneFeatureType()); |
|
1540 |
|
|
1541 |
try { |
|
1542 |
fs.dispose(); |
|
1543 |
} catch (CloseException e) { |
|
1544 |
e.printStackTrace(); |
|
1545 |
fail(); |
|
1546 |
return; |
|
1547 |
} |
|
1548 |
} |
|
1549 |
|
|
1550 |
private void compareFeatureType(FeatureType original, FeatureType copy) { |
|
1551 |
AttributeDescriptor attr1, attr2; |
|
1552 |
|
|
1553 |
assertEquals(original.size(), copy.size()); |
|
1554 |
assertEquals(original.getDefaultGeometry(), copy.getDefaultGeometry()); |
|
1555 |
|
|
1556 |
int i = 0; |
|
1557 |
|
|
1558 |
for (i = 0; i < original.size(); i++) { |
|
1559 |
attr1 = (AttributeDescriptor) original.get(i); |
|
1560 |
attr2 = (AttributeDescriptor) copy.get(i); |
|
1561 |
|
|
1562 |
assertEquals(attr1.getName(), attr2.getName()); |
|
1563 |
assertEquals(attr1.getDataType(), attr2.getDataType()); |
|
1564 |
assertEquals(attr1.getDefaultValue(), attr2.getDefaultValue()); |
|
1565 |
assertEquals(attr1.ordinal(), attr2.ordinal()); |
|
1566 |
assertEquals(attr1.originalPosition(), attr2.originalPosition()); |
|
1567 |
assertEquals(attr1.isEvaluated(), attr2.isEvaluated()); |
|
1568 |
assertEquals(attr1.getGeometryType(), attr2.getGeometryType()); |
|
1569 |
assertEquals(attr1.getSize(), attr2.getSize()); |
|
1570 |
assertEquals(attr1.getSRS(), attr2.getSRS()); |
|
1571 |
assertEquals(attr1.getPrecision(), attr2.getPrecision()); |
|
1572 |
assertEquals(attr1.getExpression(), attr2.getExpression()); |
|
1573 |
assertEquals(attr1.isAllowNull(), attr2.isAllowNull()); |
|
1574 |
assertEquals(attr1.isPrimaryKey(), attr2.isPrimaryKey()); |
|
1575 |
assertEquals(attr1.isReadOnly(), attr2.isReadOnly()); |
|
1576 |
} |
|
1577 |
|
|
1578 |
} |
|
1479 | 1579 |
} |
Also available in: Unified diff