root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / test / Persistence.java @ 1837
History | View | Annotate | Download (3.13 KB)
1 |
package com.iver.cit.gvsig.test; |
---|---|
2 |
|
3 |
import java.awt.Dimension; |
4 |
import java.io.File; |
5 |
|
6 |
import junit.framework.TestCase; |
7 |
|
8 |
import org.cresques.cts.ProjectionPool; |
9 |
|
10 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
11 |
import com.iver.cit.gvsig.ProjectExtension; |
12 |
import com.iver.cit.gvsig.fmap.FMap; |
13 |
import com.iver.cit.gvsig.fmap.ViewPort; |
14 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
15 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
16 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
17 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
18 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
19 |
import com.iver.cit.gvsig.project.Project; |
20 |
import com.iver.cit.gvsig.project.ProjectTable; |
21 |
import com.iver.cit.gvsig.project.ProjectView; |
22 |
|
23 |
/**
|
24 |
* @author Fernando Gonz?lez Cort?s
|
25 |
*/
|
26 |
public class Persistence extends TestCase { |
27 |
private ProjectExtension pe;
|
28 |
|
29 |
/*
|
30 |
* @see TestCase#setUp()
|
31 |
*/
|
32 |
protected void setUp() throws Exception { |
33 |
pe = new ProjectExtension();
|
34 |
// pe.inicializar();
|
35 |
LayerFactory.setDriversPath( |
36 |
"/root/workspace/Andami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
|
37 |
|
38 |
LayerFactory.getDataSourceFactory().addFileDataSource("gdbms dbf driver", "prueba", |
39 |
"test/cities.dbf", "test/cities.dbf", null); |
40 |
|
41 |
} |
42 |
|
43 |
public void testPersist() throws Throwable { |
44 |
Project p = new Project();
|
45 |
|
46 |
/*
|
47 |
* A?adimos una vista con una capa
|
48 |
*/
|
49 |
ProjectView v = new ProjectView();
|
50 |
ViewPort vp = new ViewPort(ProjectionPool.get("EPSG:23030")); |
51 |
vp.setImageSize(new Dimension(500, 500)); |
52 |
|
53 |
FMap fmap = new FMap(vp);
|
54 |
v.setMapContext(fmap); |
55 |
FLayer l = LayerFactory.createLayer("Vias",
|
56 |
(VectorialFileDriver) LayerFactory.getDM().getDriver("gvSIG shp driver"),
|
57 |
new File("test/cities.shp"), |
58 |
ProjectionPool.get("EPSG:23030"));
|
59 |
fmap.getLayers().addLayer(l); |
60 |
|
61 |
/*
|
62 |
* A?adimos la tabla del tema anterior
|
63 |
*/
|
64 |
SelectableDataSource sds1 = ((AlphanumericData) l).getRecordset(); |
65 |
ProjectTable pt1 = ProjectTable.createTable("tabla", sds1);
|
66 |
p.addTable(pt1); |
67 |
|
68 |
/*
|
69 |
* A?adimos otra tabla
|
70 |
*/
|
71 |
SelectableDataSource sds2 = new SelectableDataSource(LayerFactory.getDataSourceFactory().createRandomDataSource("prueba", DataSourceFactory.MANUAL_MODE)); |
72 |
ProjectTable pt2 = ProjectTable.createTable("tabla2", sds2);
|
73 |
p.addTable(pt2); |
74 |
|
75 |
/*
|
76 |
* Creamos un join
|
77 |
*/
|
78 |
String sql = "custom com_iver_cit_gvsig_arcjoin tables '"+ |
79 |
sds1.getName()+"', '"+sds1.getName()+"' values(NAME,NAME);"; |
80 |
|
81 |
SelectableDataSource result = new SelectableDataSource(
|
82 |
LayerFactory.getDataSourceFactory() |
83 |
.executeSQL(sql, DataSourceFactory.MANUAL_MODE)); |
84 |
pt1.replaceDataSource(result); |
85 |
|
86 |
/*
|
87 |
* Guardamos y cargamos
|
88 |
*/
|
89 |
File temp = File.createTempFile("junit-", ".gvp"); |
90 |
temp.deleteOnExit(); |
91 |
pe.escribirProyecto(temp, p); |
92 |
|
93 |
Project p2 = pe.leerProyecto(temp); |
94 |
|
95 |
/*
|
96 |
* Comprobamos que las dos tablas son id?nticas
|
97 |
*/
|
98 |
assertTrue(((ProjectTable)p2.getTables().get(0)).getModelo().getAsString().equals(((ProjectTable)p.getTables().get(0)).getModelo().getAsString())); |
99 |
assertTrue(((ProjectTable)p2.getTables().get(1)).getModelo().getAsString().equals(((ProjectTable)p.getTables().get(1)).getModelo().getAsString())); |
100 |
} |
101 |
} |