svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.jdbc / src / test / java / org / gvsig / fmap / dal / store / jdbc2 / AbstractTestExport2db.java @ 46109
History | View | Annotate | Download (6.86 KB)
1 | 46101 | jjdelcerro | package org.gvsig.fmap.dal.store.jdbc2; |
---|---|---|---|
2 | 45472 | jjdelcerro | |
3 | import junit.framework.TestCase; |
||
4 | import static junit.framework.TestCase.assertEquals; |
||
5 | 46101 | jjdelcerro | import org.gvsig.fmap.dal.DatabaseWorkspaceManager; |
6 | 45472 | jjdelcerro | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
7 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
8 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
9 | 46050 | omartinez | import org.gvsig.tools.dispose.DisposeUtils; |
10 | 45472 | jjdelcerro | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
11 | import org.slf4j.Logger; |
||
12 | import org.slf4j.LoggerFactory; |
||
13 | |||
14 | 46101 | jjdelcerro | public abstract class AbstractTestExport2db extends TestCase { |
15 | |||
16 | protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractTestExport2db.class); |
||
17 | |||
18 | protected AbstractTestUtils utils;
|
||
19 | |||
20 | public AbstractTestExport2db(String testName) { |
||
21 | 45472 | jjdelcerro | super(testName);
|
22 | } |
||
23 | 46101 | jjdelcerro | |
24 | 45472 | jjdelcerro | @Override
|
25 | protected void setUp() throws Exception { |
||
26 | super.setUp();
|
||
27 | new DefaultLibrariesInitializer().fullInitialize();
|
||
28 | } |
||
29 | 46101 | jjdelcerro | |
30 | 45472 | jjdelcerro | @Override
|
31 | protected void tearDown() throws Exception { |
||
32 | super.tearDown();
|
||
33 | } |
||
34 | |||
35 | 46101 | jjdelcerro | public AbstractTestUtils utils() {
|
36 | if (this.utils == null) { |
||
37 | this.utils = this.createUtils(); |
||
38 | 45472 | jjdelcerro | } |
39 | 46101 | jjdelcerro | return this.utils; |
40 | 45472 | jjdelcerro | } |
41 | |||
42 | 46101 | jjdelcerro | protected abstract AbstractTestUtils createUtils(); |
43 | 45472 | jjdelcerro | |
44 | 46101 | jjdelcerro | // TODO add test methods here. The name must begin with 'test'. For example:
|
45 | // public void testHello() {}
|
||
46 | 46109 | omartinez | protected void testExport1() throws Exception { |
47 | 45472 | jjdelcerro | try {
|
48 | 46101 | jjdelcerro | if (!utils().isTheDatabaseAvailable()) {
|
49 | return;
|
||
50 | 45472 | jjdelcerro | } |
51 | 46101 | jjdelcerro | FeatureStore sourceStore = utils().openCSVStore("/org/gvsig/fmap/dal/store/jdbc2/continentes_nogeom.csv");
|
52 | JDBCServerExplorer explorer = utils().openServerExplorer("testExport1");
|
||
53 | 45472 | jjdelcerro | |
54 | 46101 | jjdelcerro | utils().info_jdbc(explorer); |
55 | 45472 | jjdelcerro | |
56 | 46101 | jjdelcerro | // Importamos el CSV en la bbdd
|
57 | utils().drop_tables(explorer, "continentes", DatabaseWorkspaceManager.TABLE_RESOURCES_NAME);
|
||
58 | utils().create_table_from(explorer, "continentes", sourceStore);
|
||
59 | utils().insert_into_from(explorer, "continentes", sourceStore, FeatureStore.MODE_APPEND);
|
||
60 | 46050 | omartinez | |
61 | 46101 | jjdelcerro | // Le ponemos como Pk el campo ID
|
62 | FeatureStore dbstore = utils().openStore(explorer, "continentes");
|
||
63 | dbstore.edit(); |
||
64 | FeatureType featureType = dbstore.getDefaultFeatureType(); |
||
65 | EditableFeatureType eFeatureType = featureType.getEditable(); |
||
66 | eFeatureType.getEditableAttributeDescriptor("ID").setIsPrimaryKey(true); |
||
67 | dbstore.update(eFeatureType); |
||
68 | dbstore.finishEditing(); |
||
69 | DisposeUtils.dispose(dbstore); |
||
70 | |||
71 | // Comprobamos los campos que tiene la tabla de la bbdd.
|
||
72 | utils().removeResource(explorer, "continentes", "dal"); |
||
73 | |||
74 | dbstore = utils().openStore(explorer, "continentes");
|
||
75 | featureType = dbstore.getDefaultFeatureType(); |
||
76 | assertEquals("Fields count", 2, featureType.size()); |
||
77 | |||
78 | assertEquals("Field(0).name", "ID", featureType.getAttributeDescriptor(0).getName()); |
||
79 | assertEquals("Field(1).name", "NAME", featureType.getAttributeDescriptor(1).getName()); |
||
80 | |||
81 | assertEquals("Field(ID).isPrimaryKey", true, featureType.getAttributeDescriptor(0).isPrimaryKey()); |
||
82 | assertEquals("Field(NAME).isPrimaryKey", false, featureType.getAttributeDescriptor(1).isPrimaryKey()); |
||
83 | assertEquals("Field(ID).isIndexed", true, featureType.getAttributeDescriptor(0).isIndexed()); |
||
84 | assertEquals("Field(NAME).isIndexed", false, featureType.getAttributeDescriptor(1).isIndexed()); |
||
85 | |||
86 | // Le ponemos como Pk el campo NAME y lo quitamos del ID
|
||
87 | dbstore = utils().openStore(explorer, "continentes");
|
||
88 | dbstore.edit(); |
||
89 | featureType = dbstore.getDefaultFeatureType(); |
||
90 | eFeatureType = featureType.getEditable(); |
||
91 | eFeatureType.getEditableAttributeDescriptor("ID").setIsPrimaryKey(false); |
||
92 | eFeatureType.getEditableAttributeDescriptor("NAME").setIsPrimaryKey(true); |
||
93 | dbstore.update(eFeatureType); |
||
94 | dbstore.finishEditing(); |
||
95 | DisposeUtils.dispose(dbstore); |
||
96 | |||
97 | // Comprobamos los campos que tiene la tabla de la bbdd.
|
||
98 | utils().removeResource(explorer, "continentes", "dal"); |
||
99 | |||
100 | dbstore = utils().openStore(explorer, "continentes");
|
||
101 | featureType = dbstore.getDefaultFeatureType(); |
||
102 | assertEquals("Fields count", 2, featureType.size()); |
||
103 | |||
104 | assertEquals("Field(0).name", "ID", featureType.getAttributeDescriptor(0).getName()); |
||
105 | assertEquals("Field(1).name", "NAME", featureType.getAttributeDescriptor(1).getName()); |
||
106 | |||
107 | assertEquals("Field(ID).isPrimaryKey", false, featureType.getAttributeDescriptor(0).isPrimaryKey()); |
||
108 | assertEquals("Field(NAME).isPrimaryKey", true, featureType.getAttributeDescriptor(1).isPrimaryKey()); |
||
109 | assertEquals("Field(ID).isIndexed", false, featureType.getAttributeDescriptor(0).isIndexed()); |
||
110 | assertEquals("Field(NAME).isIndexed", true, featureType.getAttributeDescriptor(1).isIndexed()); |
||
111 | |||
112 | DisposeUtils.dispose(dbstore); |
||
113 | |||
114 | // Le ponemos como Pk el campo NAME y lo quitamos del ID
|
||
115 | dbstore = utils().openStore(explorer, "continentes");
|
||
116 | dbstore.edit(); |
||
117 | featureType = dbstore.getDefaultFeatureType(); |
||
118 | eFeatureType = featureType.getEditable(); |
||
119 | eFeatureType.getEditableAttributeDescriptor("ID").setIsPrimaryKey(false); |
||
120 | eFeatureType.getEditableAttributeDescriptor("NAME").setIsPrimaryKey(true); |
||
121 | |||
122 | eFeatureType.getEditableAttributeDescriptor("ID").setIsIndexed(true); |
||
123 | eFeatureType.getEditableAttributeDescriptor("NAME").setIsIndexed(true); |
||
124 | dbstore.update(eFeatureType); |
||
125 | dbstore.finishEditing(); |
||
126 | DisposeUtils.dispose(dbstore); |
||
127 | |||
128 | // Comprobamos los campos que tiene la tabla de la bbdd.
|
||
129 | utils().removeResource(explorer, "continentes", "dal"); |
||
130 | |||
131 | dbstore = utils().openStore(explorer, "continentes");
|
||
132 | featureType = dbstore.getDefaultFeatureType(); |
||
133 | assertEquals("Fields count", 2, featureType.size()); |
||
134 | |||
135 | assertEquals("Field(0).name", "ID", featureType.getAttributeDescriptor(0).getName()); |
||
136 | assertEquals("Field(1).name", "NAME", featureType.getAttributeDescriptor(1).getName()); |
||
137 | |||
138 | assertEquals("Field(ID).isPrimaryKey", false, featureType.getAttributeDescriptor(0).isPrimaryKey()); |
||
139 | assertEquals("Field(NAME).isPrimaryKey", true, featureType.getAttributeDescriptor(1).isPrimaryKey()); |
||
140 | assertEquals("Field(ID).isIndexed", true, featureType.getAttributeDescriptor(0).isIndexed()); |
||
141 | assertEquals("Field(NAME).isIndexed", true, featureType.getAttributeDescriptor(1).isIndexed()); |
||
142 | |||
143 | |||
144 | DisposeUtils.dispose(dbstore); |
||
145 | } catch (Throwable th) { |
||
146 | LOGGER.warn("", th);
|
||
147 | throw th;
|
||
148 | } |
||
149 | 45472 | jjdelcerro | } |
150 | |||
151 | } |