gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.swing / org.gvsig.vcsgis.swing.impl / src / test / java / org / gvsig / vcsgis / swing / impl / managehistory / Test02ImportHistory.java @ 5018
History | View | Annotate | Download (15.5 KB)
1 |
package org.gvsig.vcsgis.swing.impl.managehistory; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.sql.Timestamp; |
5 |
import java.time.temporal.ChronoUnit; |
6 |
import java.util.List; |
7 |
import java.util.Locale; |
8 |
import junit.framework.TestCase; |
9 |
import static junit.framework.TestCase.assertEquals; |
10 |
import org.apache.commons.io.FileUtils; |
11 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
12 |
import org.gvsig.fmap.dal.feature.Feature; |
13 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
14 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
15 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
16 |
import org.gvsig.tools.ToolsLocator; |
17 |
import org.gvsig.tools.dispose.DisposeUtils; |
18 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
19 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
20 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
21 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
22 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR; |
23 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK; |
24 |
import org.gvsig.vcsgis.lib.impl.AbstractTestUtils; |
25 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
26 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepositoryLocaldbApi; |
27 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
28 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
29 |
import org.gvsig.vcsgis.swing.impl.importhistory.ImportProcess; |
30 |
import static org.gvsig.vcsgis.swing.impl.importhistory.ImportProcess.MODE_BALANCED; |
31 |
import org.slf4j.Logger; |
32 |
import org.slf4j.LoggerFactory; |
33 |
import static org.gvsig.vcsgis.swing.impl.importhistory.ImportProcess.MODE_MINIMIZE_MEMORY; |
34 |
import static org.gvsig.vcsgis.swing.impl.importhistory.ImportProcess.MODE_MINIMIZE_TIME; |
35 |
import static org.gvsig.vcsgis.swing.impl.importhistory.ImportProcess.createImportHistoryProcessWithDate; |
36 |
import static org.gvsig.vcsgis.swing.impl.importhistory.ImportProcess.createImportHistoryProcessWithRevisionNumber; |
37 |
|
38 |
public class Test02ImportHistory extends TestCase { |
39 |
|
40 |
protected static final Logger LOGGER = LoggerFactory.getLogger(Test02ImportHistory.class); |
41 |
|
42 |
static {
|
43 |
Locale.setDefault(Locale.forLanguageTag("es-ES")); |
44 |
} |
45 |
|
46 |
public Test02ImportHistory(String testName) { |
47 |
super(testName);
|
48 |
} |
49 |
|
50 |
@Override
|
51 |
protected void setUp() throws Exception { |
52 |
super.setUp();
|
53 |
new DefaultLibrariesInitializer().fullInitialize();
|
54 |
} |
55 |
|
56 |
@Override
|
57 |
protected void tearDown() throws Exception { |
58 |
super.tearDown();
|
59 |
} |
60 |
|
61 |
private static class LocalTestUtilsH2Spatial extends org.gvsig.vcsgis.lib.impl.h2spatial.TestUtilsH2Spatial { |
62 |
// Esto fuerza a que el class loader de esta clase esta en este proyecto.
|
63 |
} |
64 |
|
65 |
private static LocalTestUtilsH2Spatial utils = null; |
66 |
|
67 |
public static AbstractTestUtils utils() { |
68 |
if (utils == null) { |
69 |
utils = new LocalTestUtilsH2Spatial();
|
70 |
} |
71 |
return utils;
|
72 |
} |
73 |
|
74 |
private VCSGisWorkspace prepareTest() throws Exception { |
75 |
int r;
|
76 |
|
77 |
VCSGisManager manager = VCSGisLocator.getVCSGisManager(); |
78 |
|
79 |
JDBCServerExplorer server = utils().openRepositoryServerExplorer("srv-ihmm");
|
80 |
File wsfile = utils().getFile(FileUtils.getFile("test-dbs", "ws-immm")); |
81 |
|
82 |
// ------------------------------------------------------------
|
83 |
// Inicializamos el repositorio y lo abrimos
|
84 |
r = manager.initRepository(server.getParameters(), null);
|
85 |
assertEquals("init_server status", ERR_NO_ERROR, r);
|
86 |
|
87 |
VCSGisRepository repo = manager.openRepository(server.getParameters()); |
88 |
utils().info_repository(repo); |
89 |
|
90 |
// ------------------------------------------------------------
|
91 |
// Creamos workspace1 y lo abrimos.
|
92 |
r = manager.initWorkspace(wsfile, repo, "Import History Minimize Memory", null); |
93 |
assertEquals("init_ws status", ERR_NO_ERROR, r);
|
94 |
|
95 |
VCSGisWorkspace ws = manager.openWorkspace(wsfile); |
96 |
utils().info_workspace(ws); |
97 |
|
98 |
// ------------------------------------------------------------
|
99 |
// Adicionamos al workspace la tabla "ENT_010101" sin commitarla.
|
100 |
FeatureStore store = utils().openCSVStore("/org/gvsig/vcsgis/swing/impl/importhistory/ENT_010101.csv");
|
101 |
r = ws.add("ENT_010101", store, "VCSGIS"); |
102 |
DisposeUtils.disposeQuietly(store); |
103 |
assertEquals("ws.add status", ERR_NO_ERROR, r);
|
104 |
|
105 |
return ws;
|
106 |
} |
107 |
|
108 |
private void check_the_import(VCSGisWorkspace ws) throws Exception { |
109 |
VCSGisRepositoryLocaldbApi repo = (VCSGisRepositoryLocaldbApi) ws.getRepository(); |
110 |
JDBCServerExplorer explorer = repo.getServerExplorer(); |
111 |
|
112 |
JDBCStoreParameters revisionsParams = explorer.get("VCSGISREPO_REVISIONS");
|
113 |
FeatureStore revisionsStore = (FeatureStore) explorer.open(revisionsParams); |
114 |
List<Feature> revisions = revisionsStore.getFeatures((String)null, "+REV_EFECTIVEDATE"); |
115 |
|
116 |
Timestamp[] expectedEfectiveDates = new Timestamp[] { |
117 |
Timestamp.valueOf("2012-12-04 09:25:37.0"), |
118 |
Timestamp.valueOf("2013-06-17 14:33:45.0"), |
119 |
Timestamp.valueOf("2017-04-19 14:44:41.0"), |
120 |
Timestamp.valueOf("2018-06-19 12:19:12.0"), |
121 |
Timestamp.valueOf("2020-05-14 19:42:51.0"), |
122 |
}; |
123 |
assertEquals("revisions", expectedEfectiveDates.length, revisions.size());
|
124 |
for (int i = 0; i < expectedEfectiveDates.length; i++) { |
125 |
Feature f = revisions.get(i); |
126 |
assertEquals("revision efective date["+i+"]", expectedEfectiveDates[i], f.getTimestamp("REV_EFECTIVEDATE")); |
127 |
} |
128 |
|
129 |
DisposeUtils.dispose(revisions); |
130 |
DisposeUtils.dispose(revisionsStore); |
131 |
|
132 |
JDBCStoreParameters dataParams = explorer.get("VCSGISREPO_DATA");
|
133 |
FeatureStore dataStore = (FeatureStore) explorer.open(dataParams); |
134 |
List<Feature> data = dataStore.getFeatures((String)null, "+DAT_EFECTIVEDATE"); |
135 |
|
136 |
final int DAT_OPERATION = 0; |
137 |
final int DAT_REVNUMBER = 1; |
138 |
final int DAT_FEATURERELATEDCODE = 2; |
139 |
final int DAT_EFECTIVEDATE = 3; |
140 |
Object[][] expectedData = new Object[][] { |
141 |
new Object[] { 2, 0, "HISTENT01010100000000000000001", Timestamp.valueOf("2012-12-04 09:25:37.0") }, |
142 |
new Object[] { 2, 0, "HISTENT01010100000000000000002", Timestamp.valueOf("2012-12-04 09:25:37.0") }, |
143 |
new Object[] { 2, 0, "HISTENT01010100000000000000003", Timestamp.valueOf("2012-12-04 09:25:37.0") }, |
144 |
new Object[] { 2, 0, "HISTENT01010100000000000000004", Timestamp.valueOf("2012-12-04 09:25:37.0") }, |
145 |
new Object[] { 2, 0, "HISTENT01010100000000000000005", Timestamp.valueOf("2012-12-04 09:25:37.0") }, |
146 |
new Object[] { 2, 0, "HISTENT01010100000000000000006", Timestamp.valueOf("2012-12-04 09:25:37.0") }, |
147 |
new Object[] { 2, 0, "HISTENT01010100000000000000007", Timestamp.valueOf("2012-12-04 09:25:37.0") }, |
148 |
new Object[] { 1, 1, "HISTENT01010100000000000000001", Timestamp.valueOf("2013-06-17 14:33:45.0") }, |
149 |
new Object[] { 1, 1, "HISTENT01010100000000000000002", Timestamp.valueOf("2013-06-17 14:33:45.0") }, |
150 |
new Object[] { 1, 1, "HISTENT01010100000000000000003", Timestamp.valueOf("2013-06-17 14:33:45.0") }, |
151 |
new Object[] { 1, 1, "HISTENT01010100000000000000004", Timestamp.valueOf("2013-06-17 14:33:45.0") }, |
152 |
new Object[] { 1, 1, "HISTENT01010100000000000000005", Timestamp.valueOf("2013-06-17 14:33:45.0") }, |
153 |
new Object[] { 1, 1, "HISTENT01010100000000000000006", Timestamp.valueOf("2013-06-17 14:33:45.0") }, |
154 |
new Object[] { 1, 1, "HISTENT01010100000000000000007", Timestamp.valueOf("2013-06-17 14:33:45.0") }, |
155 |
new Object[] { 1, 2, "HISTENT01010100000000000000007", Timestamp.valueOf("2017-04-19 14:44:41.0") }, |
156 |
new Object[] { 0, 3, "HISTENT01010100000000000000007", Timestamp.valueOf("2018-06-19 12:19:12.0") }, |
157 |
new Object[] { 2, 3, "HISTENT01010100000000000000011", Timestamp.valueOf("2018-06-19 12:19:12.0") }, |
158 |
new Object[] { 1, 4, "HISTENT01010100000000000000011", Timestamp.valueOf("2020-05-14 19:42:51.0") }, |
159 |
}; |
160 |
assertEquals("data", expectedData.length, data.size());
|
161 |
for (int i = 0; i < expectedData.length; i++) { |
162 |
Feature f = data.get(i); |
163 |
assertEquals("data["+i+"].DAT_OPERATION", expectedData[i][DAT_OPERATION], f.getInt("DAT_OPERATION")); |
164 |
assertEquals("data["+i+"].DAT_REVNUMBER", expectedData[i][DAT_REVNUMBER], f.getInt("DAT_REVNUMBER")); |
165 |
assertEquals("data["+i+"].DAT_FEATURERELATEDCODE", expectedData[i][DAT_FEATURERELATEDCODE], f.getString("DAT_FEATURERELATEDCODE")); |
166 |
assertEquals("data["+i+"].DAT_EFECTIVEDATE", expectedData[i][DAT_EFECTIVEDATE], f.getTimestamp("DAT_EFECTIVEDATE")); |
167 |
} |
168 |
DisposeUtils.dispose(data); |
169 |
DisposeUtils.dispose(dataStore); |
170 |
} |
171 |
|
172 |
private FeatureStore getStoreHistory() throws Exception { |
173 |
FeatureStore store_hist = utils().openCSVStore("/org/gvsig/vcsgis/swing/impl/importhistory/ENT_010101_HIST.csv");
|
174 |
return store_hist;
|
175 |
} |
176 |
|
177 |
private VCSGisEntity getEntity(VCSGisWorkspace ws) {
|
178 |
VCSGisWorkspaceEntity entity = ws.getWorkspaceEntityByName("ENT_010101");
|
179 |
return entity;
|
180 |
} |
181 |
|
182 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
183 |
// public void testHello() {}
|
184 |
|
185 |
public void testWithRevisionNumberAndMinimizeMemory() throws Exception { |
186 |
try {
|
187 |
int r;
|
188 |
|
189 |
utils().cleanRepositoryDatabase(); |
190 |
|
191 |
VCSGisWorkspace ws = prepareTest(); |
192 |
|
193 |
ImportProcess importer = createImportHistoryProcessWithRevisionNumber( |
194 |
false,
|
195 |
MODE_MINIMIZE_MEMORY, |
196 |
ws, |
197 |
getStoreHistory(), |
198 |
getEntity(ws), |
199 |
"VCSGISCODE",
|
200 |
"N_VERSION",
|
201 |
"FECHA",
|
202 |
null,
|
203 |
ExpressionUtils.createExpression("FECHA_BAJA IS NOT NULL"),
|
204 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("testWithRevisionNumberAndMinimizeMemory")
|
205 |
); |
206 |
|
207 |
r = importer.process(); |
208 |
assertEquals("Import by revision number minimize memory", ERR_OK, r);
|
209 |
|
210 |
check_the_import(ws); |
211 |
|
212 |
} catch (Exception ex) { |
213 |
LOGGER.warn("", ex);
|
214 |
throw ex;
|
215 |
} |
216 |
} |
217 |
|
218 |
public void testWithRevisionNumberAndMinimizeTime() throws Exception { |
219 |
try {
|
220 |
int r;
|
221 |
|
222 |
utils().cleanRepositoryDatabase(); |
223 |
|
224 |
VCSGisWorkspace ws = prepareTest(); |
225 |
|
226 |
ImportProcess importer = createImportHistoryProcessWithRevisionNumber( |
227 |
false,
|
228 |
MODE_MINIMIZE_TIME, |
229 |
ws, |
230 |
getStoreHistory(), |
231 |
getEntity(ws), |
232 |
"VCSGISCODE",
|
233 |
"N_VERSION",
|
234 |
"FECHA",
|
235 |
null,
|
236 |
ExpressionUtils.createExpression("FECHA_BAJA IS NOT NULL"),
|
237 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("testWithRevisionNumberAndMinimizeTime")
|
238 |
); |
239 |
|
240 |
r = importer.process(); |
241 |
assertEquals("Import by revision number minimize time", ERR_OK, r);
|
242 |
|
243 |
check_the_import(ws); |
244 |
|
245 |
} catch (Exception ex) { |
246 |
LOGGER.warn("", ex);
|
247 |
throw ex;
|
248 |
} |
249 |
} |
250 |
|
251 |
public void testWithRevisionNumberAndBalanced() throws Exception { |
252 |
try {
|
253 |
int r;
|
254 |
|
255 |
utils().cleanRepositoryDatabase(); |
256 |
|
257 |
VCSGisWorkspace ws = prepareTest(); |
258 |
|
259 |
ImportProcess importer = createImportHistoryProcessWithRevisionNumber( |
260 |
false,
|
261 |
MODE_BALANCED, |
262 |
ws, |
263 |
getStoreHistory(), |
264 |
getEntity(ws), |
265 |
"VCSGISCODE",
|
266 |
"N_VERSION",
|
267 |
"FECHA",
|
268 |
null,
|
269 |
ExpressionUtils.createExpression("FECHA_BAJA IS NOT NULL"),
|
270 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("testWithRevisionNumberAndBalanced")
|
271 |
); |
272 |
|
273 |
r = importer.process(); |
274 |
assertEquals("Import by revision number balanced", ERR_OK, r);
|
275 |
|
276 |
check_the_import(ws); |
277 |
|
278 |
} catch (Exception ex) { |
279 |
LOGGER.warn("", ex);
|
280 |
throw ex;
|
281 |
} |
282 |
} |
283 |
|
284 |
public void testWithRevisionDateAndMinimizeMemory() throws Exception { |
285 |
try {
|
286 |
int r;
|
287 |
|
288 |
utils().cleanRepositoryDatabase(); |
289 |
|
290 |
VCSGisWorkspace ws = prepareTest(); |
291 |
|
292 |
ImportProcess importer = createImportHistoryProcessWithDate( |
293 |
false,
|
294 |
MODE_MINIMIZE_MEMORY, |
295 |
ws, |
296 |
getStoreHistory(), |
297 |
getEntity(ws), |
298 |
"VCSGISCODE",
|
299 |
"FECHA",
|
300 |
null,
|
301 |
ExpressionUtils.createExpression("FECHA_BAJA IS NOT NULL"),
|
302 |
1, ChronoUnit.DAYS,
|
303 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("testWithRevisionDateAndMinimizeMemory")
|
304 |
); |
305 |
|
306 |
r = importer.process(); |
307 |
assertEquals("Import by revision date minimize memory", ERR_OK, r);
|
308 |
|
309 |
check_the_import(ws); |
310 |
|
311 |
} catch (Exception ex) { |
312 |
LOGGER.warn("", ex);
|
313 |
throw ex;
|
314 |
} |
315 |
} |
316 |
|
317 |
public void testWithRevisionDateAndMinimizeTime() throws Exception { |
318 |
try {
|
319 |
int r;
|
320 |
|
321 |
utils().cleanRepositoryDatabase(); |
322 |
|
323 |
VCSGisWorkspace ws = prepareTest(); |
324 |
|
325 |
ImportProcess importer = createImportHistoryProcessWithDate( |
326 |
false,
|
327 |
MODE_MINIMIZE_TIME, |
328 |
ws, |
329 |
getStoreHistory(), |
330 |
getEntity(ws), |
331 |
"VCSGISCODE",
|
332 |
"FECHA",
|
333 |
null,
|
334 |
ExpressionUtils.createExpression("FECHA_BAJA IS NOT NULL"),
|
335 |
1, ChronoUnit.DAYS,
|
336 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("testWithRevisionDateAndMinimizeTime")
|
337 |
); |
338 |
|
339 |
r = importer.process(); |
340 |
assertEquals("Import by revision date minimize time", ERR_OK, r);
|
341 |
|
342 |
check_the_import(ws); |
343 |
|
344 |
} catch (Exception ex) { |
345 |
LOGGER.warn("", ex);
|
346 |
throw ex;
|
347 |
} |
348 |
} |
349 |
|
350 |
public void testWithRevisionDateAndBalanced() throws Exception { |
351 |
try {
|
352 |
int r;
|
353 |
|
354 |
utils().cleanRepositoryDatabase(); |
355 |
|
356 |
VCSGisWorkspace ws = prepareTest(); |
357 |
|
358 |
ImportProcess importer = createImportHistoryProcessWithDate( |
359 |
false,
|
360 |
MODE_BALANCED, |
361 |
ws, |
362 |
getStoreHistory(), |
363 |
getEntity(ws), |
364 |
"VCSGISCODE",
|
365 |
"FECHA",
|
366 |
null,
|
367 |
ExpressionUtils.createExpression("FECHA_BAJA IS NOT NULL"),
|
368 |
1, ChronoUnit.DAYS,
|
369 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("testWithRevisionDateAndBalanced")
|
370 |
); |
371 |
|
372 |
r = importer.process(); |
373 |
assertEquals("Import by revision date balanced", ERR_OK, r);
|
374 |
|
375 |
check_the_import(ws); |
376 |
|
377 |
} catch (Exception ex) { |
378 |
LOGGER.warn("", ex);
|
379 |
throw ex;
|
380 |
} |
381 |
} |
382 |
|
383 |
|
384 |
} |