Statistics
| Revision:

gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.lib / org.gvsig.vcsgis.lib.impl / src / test / java / org / gvsig / vcsgis / lib / impl / Test14UpdateWithConflict.java @ 3391

History | View | Annotate | Download (26.2 KB)

1
package org.gvsig.vcsgis.lib.impl;
2

    
3
import java.io.File;
4
import java.util.List;
5
import junit.framework.TestCase;
6
import static junit.framework.TestCase.assertEquals;
7
import org.apache.commons.io.FileUtils;
8
import org.gvsig.expressionevaluator.Expression;
9
import org.gvsig.fmap.dal.exception.DataException;
10
import org.gvsig.fmap.dal.feature.EditableFeature;
11
import org.gvsig.fmap.dal.feature.Feature;
12
import org.gvsig.fmap.dal.feature.FeatureStore;
13
import static org.gvsig.fmap.dal.feature.FeatureStore.MODE_PASS_THROUGH;
14
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
15
import org.gvsig.tools.dispose.DisposeUtils;
16
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
17
import org.gvsig.vcsgis.lib.SequentialCodeGenerator;
18
import org.gvsig.vcsgis.lib.VCSGisLocator;
19
import org.gvsig.vcsgis.lib.VCSGisManager;
20
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR;
21
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_UPDATE_NEED_MERGE;
22
import static org.gvsig.vcsgis.lib.VCSGisManager.FEATURECODE_FIELD_NAME;
23
import static org.gvsig.vcsgis.lib.VCSGisManager.OP_DELETE;
24
import static org.gvsig.vcsgis.lib.VCSGisManager.OP_INSERT;
25
import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_CONFLICT;
26
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
27
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace;
28
import org.gvsig.vcsgis.lib.workspace.tables.RemoteChangesTable;
29
import org.gvsig.vcsgis.lib.workspace.tables.WorkspaceChangesTable;
30
import org.slf4j.Logger;
31
import org.slf4j.LoggerFactory;
32

    
33
public class Test14UpdateWithConflict extends TestCase {
34

    
35
    private static final Logger LOGGER = LoggerFactory.getLogger(Test14UpdateWithConflict.class);
36

    
37
    public Test14UpdateWithConflict(String testName) {
38
        super(testName);
39
    }
40

    
41
    @Override
42
    protected void setUp() throws Exception {
43
        super.setUp();
44
        new DefaultLibrariesInitializer().fullInitialize();
45
    }
46

    
47
    @Override
48
    protected void tearDown() throws Exception {
49
        super.tearDown();
50
    }
51

    
52
    private void insert(FeatureStore store, int id, String text) throws DataException{
53
        EditableFeature ef = store.createNewFeature();
54
        ef.set("id",id);
55
        ef.set("text",text);
56
        store.insert(ef);
57
    }
58
    
59
    private void update(FeatureStore store, int id, String text) throws DataException{
60
        Feature f = store.findFirst("id="+id);
61
        EditableFeature ef = f.getEditable();
62
        ef.set("text", text);
63
        store.update(ef);
64
    }
65
    
66
    private void delete(FeatureStore store, int id, String text) throws DataException{
67
        Feature f = store.findFirst("id="+id);
68
        store.delete(f);
69
    }
70
    
71
    private void check(List<Feature> features, int index, int id, String text){
72
        assertEquals(id    , features.get(index).getInt("id"));
73
        assertEquals(text, features.get(index).getString("text"));
74
    }
75

    
76
    private void check(FeatureStore store2, String relatedFeatureCode, int id, String text) throws Exception {
77
        Feature f = store2.findFirst("VCSGISCODE = '"+relatedFeatureCode+"'");
78
        assertEquals(id, f.getInt("id"));
79
        assertEquals(text, f.getString("text"));
80
    }
81
    
82
    private void selectRemoteChange(VCSGisWorkspace ws, boolean select, int id, String text, VCSGisWorkspace wsSource) throws Exception {
83
        Feature fTest;
84
        FeatureStore testStore = ws.getFeatureStore("test");
85
        FeatureStore testStoreSource = wsSource.getFeatureStore("test");
86
        
87
        fTest = testStoreSource.findFirst("id = "+id);
88

    
89
        FeatureStore rchangesStore = ws.getFeatureStore(RemoteChangesTable.TABLE_NAME);
90
        Feature fChanges = rchangesStore.findFirst("RCH_DATACODE = '"+fTest.getString(FEATURECODE_FIELD_NAME)+"'");
91
        EditableFeature efChanges = fChanges.getEditable();
92
        rchangesStore.edit(MODE_PASS_THROUGH);
93
        efChanges.set("RCH_SELECTED",select);
94
        rchangesStore.update(efChanges);
95
        rchangesStore.finishEditing();
96
        DisposeUtils.dispose(testStore);
97
        DisposeUtils.dispose(testStoreSource);
98
        DisposeUtils.dispose(rchangesStore);
99
    }
100
    
101
    private void checkLocalChange(FeatureStore data, FeatureStore changes, String code, int operation, int id, String text, int status) throws DataException{
102
        Feature change = changes.findFirst("WSCH_FEATURECODE = '"+code+"'");
103
        assertNotNull("Change code not exists", change);
104
        assertEquals(operation, change.getInt(WorkspaceChangesTable.OPERATION));
105
        if(status >=0){
106
            assertEquals(status, change.getInt(WorkspaceChangesTable.STATUS));
107
        }
108
        // Uf, ojo con operation delete, no tiene data. en la primera pasada lo saltaria, y a ver que pasa con
109
        // los inserts y updates.
110
//        if(operation != OP_DELETE){
111
//            Feature f = data.findFirst("VCSGISCODE = '"+code+"'");
112
//            assertEquals(id  , f.getInt("id"));
113
//            assertEquals(text, f.getString("text"));
114
//        }
115
        
116
    }
117

    
118
    private VCSGisWorkspace[] initTest() throws Exception{
119

    
120
        VCSGisManager manager = VCSGisLocator.getVCSGisManager();
121
        JDBCServerExplorer server = TestUtils.openServerExplorer("srv-update");
122
        File ws1file = TestUtils.getFile(FileUtils.getFile("test-dbs","ws1-update")); 
123
        File ws2file = TestUtils.getFile(FileUtils.getFile("test-dbs","ws2-update")); 
124
        File ws3file = TestUtils.getFile(FileUtils.getFile("test-dbs","ws3-update")); 
125
        
126
        manager.setCodeGenerator(new SequentialCodeGenerator());
127
        
128
        int r;
129
        List<Feature> features;
130
        FeatureStore store2;
131
        FeatureStore store3;
132

    
133
        // ------------------------------------------------------------
134
        // Inicializamos el repositorio y lo abrimos
135
        r = manager.initRepository(server.getParameters(), null);
136
        assertEquals("init_server status", ERR_NO_ERROR, r);
137
        
138
        VCSGisRepository repo = manager.openRepository(server.getParameters());
139
        TestUtils.h2sql_repository(repo);
140

    
141
        // ------------------------------------------------------------
142
        // Creamos workspace1 y lo abrimos.
143
        r = manager.initWorkspace(ws1file, repo, "Test update1",null);
144
        assertEquals("init_ws1 status", ERR_NO_ERROR, r);
145
        
146
        VCSGisWorkspace ws1 = manager.openWorkspace(ws1file);
147
        TestUtils.h2sql_workspace(ws1);
148

    
149
        // ------------------------------------------------------------
150
        // Adicionamos al workspace1 la tabla "test" y la commitamos.
151
        //REV 0
152
        FeatureStore sourceTest = TestUtils.openSourceStore2();
153
        r = ws1.add("test", sourceTest, "text");
154
        DisposeUtils.disposeQuietly(sourceTest);
155
        assertEquals("ws1.add status", ERR_NO_ERROR, r);
156

    
157
        r = ws1.commit();
158
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
159

    
160

    
161
        // ------------------------------------------------------------
162
        // Inicializamos el workspace2 asociandolo al mismo repositorio que 
163
        // workspace1 y lo abrimos.
164
        r = manager.initWorkspace(ws2file, repo, "Test update2",null);
165
        assertEquals("init_ws2 status", ERR_NO_ERROR, r);
166
        VCSGisWorkspace ws2 = manager.openWorkspace(ws2file);
167
        TestUtils.h2sql_workspace(ws2);
168
        
169
        
170
        // ------------------------------------------------------------
171
        // Actualizamos (update) la tabla "test" en el workspace2 
172
        // y comprobamos que tiene lo que toca.
173
        r = ws2.checkout("test");
174
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
175
        
176
        store2 = ws2.getFeatureStore("test");
177
        assertEquals("ws2-upfate sizes", 3, store2.size64());
178
        features = store2.getFeatures((Expression)null, "id", true);
179
        
180
        check(features, 0, 1, "AAA");
181
        check(features, 1, 2, "BBB");
182
        check(features, 2, 3, "CCC");
183
        
184
        DisposeUtils.disposeQuietly(features);
185
        DisposeUtils.disposeQuietly(store2);
186

    
187

    
188

    
189
        // ------------------------------------------------------------
190
        // Inicializamos el workspace3 asociandolo al mismo repositorio que 
191
        // workspace1 y lo abrimos.
192
        r = manager.initWorkspace(ws3file, repo, "Test update2",null);
193
        assertEquals("init_ws2 status", ERR_NO_ERROR, r);
194
        VCSGisWorkspace ws3 = manager.openWorkspace(ws3file);
195
        TestUtils.h2sql_workspace(ws3);
196
        
197
        
198
        // ------------------------------------------------------------
199
        // Actualizamos (update) la tabla "test" en el workspace3
200
        // y comprobamos que tiene lo que toca.
201
        r = ws3.checkout("test");
202
        assertEquals("ws3.update-1 status", ERR_NO_ERROR, r);
203
        
204
        store3 = ws3.getFeatureStore("test");
205
        assertEquals("ws3-upfate sizes", 3, store3.size64());
206
        features = store3.getFeatures((Expression)null, "id", true);
207
        
208
        check(features, 0, 1, "AAA");
209
        check(features, 1, 2, "BBB");
210
        check(features, 2, 3, "CCC");
211
        
212
        DisposeUtils.disposeQuietly(features);
213
        DisposeUtils.disposeQuietly(store2);
214
        DisposeUtils.disposeQuietly(store3);
215
        
216
        return new VCSGisWorkspace[] {ws1, ws2, ws3};
217
    }
218
    
219
    public void testTwoUpdatesAndMerge() throws Exception {
220
        
221
        VCSGisWorkspace[] wss = initTest();
222
        VCSGisWorkspace ws1 = wss[0];
223
        VCSGisWorkspace ws2 = wss[1];
224
        
225
        int r;
226
        Feature f;
227
        EditableFeature ef;
228
        FeatureStore store1;
229
        FeatureStore store2;
230
        
231
        // Añadimos al workspace1 una feature con una id concreta y la commitamos
232
        
233
        store1 = ws1.getFeatureStore("test");
234
        store1.edit();
235
        update(store1, 3, "CC1");
236
        
237
        store1.finishEditing();
238
        DisposeUtils.disposeQuietly(store1);
239
        
240
        r = ws1.commit();
241
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
242
        
243

    
244
        // Añadimos al workspace2 una feature con la misma id
245
        store2 = ws2.getFeatureStore("test");
246
        store2.edit();
247
        update(store2, 3, "CC2");
248
        
249
        store2.finishEditing();
250
        DisposeUtils.disposeQuietly(store2);
251

    
252
        // ------------------------------------------------------------
253
        // Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 
254
        // comprobamos que funciona y que tiene lo que toca.
255
        r = ws2.updatePrepare("test");
256
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
257
        
258
//        assertTrue(false);
259
        // Actualizamos (update) la tabla "test" en el workspace2 
260
        // comprobamos que falla
261
        r = ws2.update("test");
262
        assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r);
263

    
264
        // Actualizamos (merge) la tabla "test" en el workspace2 
265
        // comprobamos que no falla
266
        r = ws2.merge("test");
267
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
268
        
269
        //Comprobar que en la tabla de cambios locales hay 1 elemento
270
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
271
        assertEquals("ws2-changes size", 1, changes.size64());
272

    
273
    }
274

    
275
    public void testTwoUpdatesMergeAndUpdate() throws Exception {
276
        
277
        VCSGisWorkspace[] wss = initTest();
278
        VCSGisWorkspace ws1 = wss[0];
279
        VCSGisWorkspace ws2 = wss[1];
280
        VCSGisWorkspace ws3 = wss[2];
281
        
282
        int r;
283
        Feature f;
284
        EditableFeature ef;
285
        FeatureStore store1;
286
        FeatureStore store2;
287
        FeatureStore store3;
288
        
289
        // Editamos en el workspace1 una feature con una id concreta y la commitamos
290
        
291
        store1 = ws1.getFeatureStore("test");
292
        store1.edit();
293
        update(store1, 3, "CC1");
294
        
295
        store1.finishEditing();
296
        DisposeUtils.disposeQuietly(store1);
297
        
298
        r = ws1.commit();
299
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
300
        
301

    
302
        // Editamos en el workspace2 la feature con la misma id
303
        store2 = ws2.getFeatureStore("test");
304
        store2.edit();
305
        update(store2, 3, "CC2");
306
        
307
        store2.finishEditing();
308
        DisposeUtils.disposeQuietly(store2);
309

    
310
        // ------------------------------------------------------------
311
        // Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 
312
        // comprobamos que funciona y que tiene lo que toca.
313
        r = ws2.updatePrepare("test");
314
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
315
        
316
//        assertTrue(false);
317
        // Actualizamos (update) la tabla "test" en el workspace2 
318
        // comprobamos que falla
319
        r = ws2.update("test");
320
        assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r);
321
        
322
        // Actualizamos (merge) la tabla "test" en el workspace2 
323
        // comprobamos que no falla
324
        r = ws2.merge("test");
325
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
326
        
327
        //Comprobar que en la tabla de cambios locales hay 1 elemento
328
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
329
        assertEquals("ws2-changes size", 1, changes.size64());
330
        
331
        // Commitamos el workspace2
332
        r = ws2.commit();
333
        assertEquals("ws2.commit-1 status", ERR_NO_ERROR, r);
334
        
335

    
336
        // ------------------------------------------------------------
337
        // Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace3
338
        // comprobamos que funciona y que tiene lo que toca.
339
        r = ws3.updatePrepare("test");
340
        assertEquals("ws3.update-1 status", ERR_NO_ERROR, r);
341
        
342
        //Comprobar que en la tabla de cambios remotos hay 1 elemento
343
        FeatureStore remoteChanges = ws3.getFeatureStore(RemoteChangesTable.TABLE_NAME);
344
        assertEquals("ws3-remoteChanges size", 1, remoteChanges.size64());
345
        
346
        // Actualizamos (update) la tabla "test" en el workspace3 
347
        // comprobamos que no falla
348
        r = ws3.update("test");
349
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
350

    
351
        store3 = ws3.getFeatureStore("test");
352
        assertEquals("ws3-update sizes", 3, store3.size64());
353
        List<Feature> features = store3.getFeatures((Expression)null, "id", true);
354
        
355
        check(features, 0, 1, "AAA");
356
        check(features, 1, 2, "BBB");
357
        check(features, 2, 3, "CC2");
358

    
359
        DisposeUtils.disposeQuietly(store3);
360

    
361
    }
362

    
363

    
364
    public void testTwoUpdatesAndUpdate() throws Exception {
365
        
366
        VCSGisWorkspace[] wss = initTest();
367
        VCSGisWorkspace ws1 = wss[0];
368
        VCSGisWorkspace ws2 = wss[1];
369
        
370
        int r;
371
        Feature f;
372
        EditableFeature ef;
373
        FeatureStore store1;
374
        FeatureStore store2;
375

    
376
        // Añadimos al workspace1 una feature con una id concreta y la commitamos
377
        
378
        store1 = ws1.getFeatureStore("test");
379
        store1.edit();
380
        update(store1, 3, "CC1");
381
        
382
        store1.finishEditing();
383
        DisposeUtils.disposeQuietly(store1);
384
        
385
        r = ws1.commit();
386
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
387
        
388

    
389
        // Añadimos al workspace2 una feature con la misma id
390
        store2 = ws2.getFeatureStore("test");
391
        store2.edit();
392
        update(store2, 3, "CC2");
393
        
394
        store2.finishEditing();
395
        DisposeUtils.disposeQuietly(store2);
396

    
397
        // ------------------------------------------------------------
398
        // Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 
399
        // comprobamos que funciona y que tiene lo que toca.
400
        r = ws2.updatePrepare("test");
401
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
402
        
403
//        assertTrue(false);
404
        // Actualizamos (update) la tabla "test" en el workspace2 
405
        // comprobamos que falla
406
        r = ws2.update("test");
407
        assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r);
408

    
409
        //Seleccionar el cambio conflictivo id=4
410
        selectRemoteChange(ws2, true, 3, "CC1", ws1);
411

    
412
        
413
        // Actualizamos (merge) la tabla "test" en el workspace2 
414
        // comprobamos que no falla
415
        r = ws2.update("test");
416
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
417
        
418
        //Comprobar que en la tabla de cambios locales no hay nada
419
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
420
        assertEquals("ws2-changes size", 0, changes.size64());
421

    
422
    }
423
    
424
    
425
    public void testTwoInsertsAndUpdate() throws Exception {
426
        
427
        VCSGisWorkspace[] wss = initTest();
428
        VCSGisWorkspace ws1 = wss[0];
429
        VCSGisWorkspace ws2 = wss[1];
430
        
431
        int r;
432
        Feature f;
433
        EditableFeature ef;
434
        List<Feature> features;
435
        FeatureStore store1;
436
        FeatureStore store2;
437

    
438
                // Añadimos al workspace1 una feature con una id concreta y la commitamos
439
        
440
        store1 = ws1.getFeatureStore("test");
441
        store1.edit();
442
        insert(store1, 4, "DD1");
443
        
444
        store1.finishEditing();
445
        DisposeUtils.disposeQuietly(store1);
446
        
447
        r = ws1.commit();
448
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
449
        
450

    
451
        // Añadimos al workspace2 una feature con la misma id
452
        store2 = ws2.getFeatureStore("test");
453
        store2.edit();
454
        insert(store2, 4, "DD2");
455
        
456
        store2.finishEditing();
457
        DisposeUtils.disposeQuietly(store2);
458

    
459
        
460
        // ------------------------------------------------------------
461
        // Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 
462
        // comprobamos que funciona y que tiene lo que toca.
463
        r = ws2.updatePrepare("test");
464
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
465
        
466
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
467
        checkLocalChange(store2, changes, "00000000000037abcdef0123456789", OP_INSERT, 4, "DD2", STATE_CONFLICT);
468

    
469
        
470
        // Actualizamos (update) la tabla "test" en el workspace2 
471
        // comprobamos que no falla
472
        r = ws2.update("test");
473
        assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r);
474

    
475
        //Seleccionar el cambio conflictivo id=4
476
        selectRemoteChange(ws2, true, 4, "DD1", ws1);
477

    
478
        //update y comprobar que funciona y se ha borrado la feature conflictiva nuestra
479
        r = ws2.update("test");
480
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
481

    
482
        store2 = ws2.getFeatureStore("test");
483
        assertEquals("ws2-upfate sizes", 4, store2.size64());
484
        features = store2.getFeatures((Expression)null, "id", true);
485
        
486
        check(features, 0, 1, "AAA");
487
        check(features, 1, 2, "BBB");
488
        check(features, 2, 3, "CCC");
489
        check(features, 3, 4, "DD1");
490

    
491
        //Comprobar que en la tabla de cambios locales no hay nada
492
        changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
493
        assertEquals("ws2-changes size", 0, changes.size64());
494

    
495
    }
496

    
497
    public void testTwoInsertsAndMerge() throws Exception {
498
        
499
        VCSGisWorkspace[] wss = initTest();
500
        VCSGisWorkspace ws1 = wss[0];
501
        VCSGisWorkspace ws2 = wss[1];
502
        
503
        int r;
504
        Feature f;
505
        EditableFeature ef;
506
        List<Feature> features;
507
        FeatureStore store1;
508
        FeatureStore store2;
509

    
510
                //Insertamos dos registros nuevos y repetirlo todo sin seleccionar cambio conflictivo y hacer un merge y que funcione
511

    
512
        // Añadimos al workspace1 una feature con una id concreta y la commitamos
513
        
514
        store1 = ws1.getFeatureStore("test");
515
        store1.edit();
516
        insert(store1, 4, "DD1");
517
        
518
        store1.finishEditing();
519
        DisposeUtils.disposeQuietly(store1);
520
        
521
        r = ws1.commit();
522
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
523
        
524

    
525
        // Añadimos al workspace2 una feature con la misma id
526
        store2 = ws2.getFeatureStore("test");
527
        store2.edit();
528
        insert(store2, 4, "DD2");
529
        
530
        store2.finishEditing();
531
        DisposeUtils.disposeQuietly(store2);
532

    
533
        
534
        // ------------------------------------------------------------
535
        // Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 
536
        // comprobamos que funciona y que tiene lo que toca.
537
        r = ws2.updatePrepare("test");
538
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
539
        
540
        // Actualizamos (update) la tabla "test" en el workspace2 
541
        // comprobamos que no falla
542
        r = ws2.update("test");
543
        assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r);
544

    
545
        //merge y comprobar que funciona y no se insertado el cambio conflictivo
546
        r = ws2.merge("test");
547
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
548

    
549
        store2 = ws2.getFeatureStore("test");
550
        assertEquals("ws2-upfate sizes", 4, store2.size64());
551
        features = store2.getFeatures((Expression)null, "id", true);
552
        
553
        check(features, 0, 1, "AAA");
554
        check(features, 1, 2, "BBB");
555
        check(features, 2, 3, "CCC");
556
        check(features, 3, 4, "DD2");
557

    
558
        //Comprobamos que se ha añadido a la tabla de cambios local el delete del cambio conflictivo
559

    
560
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
561
        assertEquals("ws2-changes size", 2, changes.size64());
562

    
563
        checkLocalChange(store2, changes, "00000000000029abcdef0123456789", OP_DELETE, 4, "DD1", -1);
564
        
565
        checkLocalChange(store2, changes, "00000000000037abcdef0123456789", OP_INSERT, 4, "DD2", -1);
566

    
567
    }
568

    
569

    
570
    public void testOneCommitAndUpdateOverDeleted() throws Exception {
571
        
572
        VCSGisWorkspace[] wss = initTest();
573
        VCSGisWorkspace ws1 = wss[0];
574
        VCSGisWorkspace ws2 = wss[1];
575
        List<Feature> features;
576
        
577
        int r;
578
        Feature f;
579
        EditableFeature ef;
580
        FeatureStore store1;
581
        FeatureStore store2;
582
        
583
        // Modificamos en workspace1 una feature con una id concreta y la commitamos
584
        
585
        store1 = ws1.getFeatureStore("test");
586
        store1.edit();
587
        update(store1, 3, "CC1");
588
        
589
        store1.finishEditing();
590
        DisposeUtils.disposeQuietly(store1);
591
        
592
        r = ws1.commit();
593
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
594
        
595

    
596
        // Borramos en el workspace2 la feature con la misma id
597
        store2 = ws2.getFeatureStore("test");
598
        store2.edit();
599
        delete(store2, 3, "CCC");
600
        
601
        store2.finishEditing();
602
        DisposeUtils.disposeQuietly(store2);
603

    
604
        // ------------------------------------------------------------
605
        // Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 
606
        // comprobamos que funciona y que tiene lo que toca.
607
        r = ws2.updatePrepare("test");
608
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
609
        
610
//        assertTrue(false);
611
        // Actualizamos (update) la tabla "test" en el workspace2 
612
        // comprobamos que falla
613
        r = ws2.update("test");
614
        assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r);
615

    
616
//        // Actualizamos (merge) la tabla "test" en el workspace2 
617
//        // comprobamos que no falla
618
//        r = ws2.merge("test");
619
//        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
620

    
621

    
622
        //Seleccionar el cambio conflictivo id=4
623
        selectRemoteChange(ws2, true, 3, "CC1", ws1);
624
        
625
        //update y comprobar que funciona y no se ha insertado la feature conflictiva
626
        r = ws2.update("test");
627
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
628

    
629
        store2 = ws2.getFeatureStore("test");
630
        assertEquals("ws2-update sizes", 3, store2.size64());
631
        features = store2.getFeatures((Expression)null, "id", true);
632
        
633
        check(features, 0, 1, "AAA");
634
        check(features, 1, 2, "BBB");
635
        check(features, 2, 3, "CC1");
636

    
637
        //Comprobar que en la tabla de cambios locales no hay nada
638
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
639
        assertEquals("ws2-changes size", 0, changes.size64());
640

    
641
    }
642
    
643

    
644
    public void testOneCommitAndMergeOverDeleted() throws Exception {
645
        
646
        VCSGisWorkspace[] wss = initTest();
647
        VCSGisWorkspace ws1 = wss[0];
648
        VCSGisWorkspace ws2 = wss[1];
649
        List<Feature> features;
650
        
651
        int r;
652
        Feature f;
653
        EditableFeature ef;
654
        FeatureStore store1;
655
        FeatureStore store2;
656
        
657
        // Modificamos en workspace1 una feature con una id concreta y la commitamos
658
        
659
        store1 = ws1.getFeatureStore("test");
660
        store1.edit();
661
        update(store1, 3, "CC1");
662
        
663
        store1.finishEditing();
664
        DisposeUtils.disposeQuietly(store1);
665
        
666
        r = ws1.commit();
667
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
668
        
669

    
670
        // Borramos en el workspace2 la feature con la misma id
671
        store2 = ws2.getFeatureStore("test");
672
        store2.edit();
673
        delete(store2, 3, "CCC");
674
        
675
        store2.finishEditing();
676
        DisposeUtils.disposeQuietly(store2);
677

    
678
        // ------------------------------------------------------------
679
        // Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 
680
        // comprobamos que funciona y que tiene lo que toca.
681
        r = ws2.updatePrepare("test");
682
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
683
        
684
//        assertTrue(false);
685
        // Actualizamos (update) la tabla "test" en el workspace2 
686
        // comprobamos que falla
687
//        r = ws2.update("test");
688
//        assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r);
689

    
690
        // Actualizamos (merge) la tabla "test" en el workspace2 
691
        // comprobamos que no falla
692
        r = ws2.merge("test");
693
        assertEquals("ws2.update-1 status", ERR_NO_ERROR, r);
694

    
695
        //Comprobamos que en workspace2 hay lo que toca
696
        store2 = ws2.getFeatureStore("test");
697
        assertEquals("ws2-update sizes", 2, store2.size64());
698
        features = store2.getFeatures((Expression)null, "id", true);
699
        
700
        check(features, 0, 1, "AAA");
701
        check(features, 1, 2, "BBB");
702
//        check(features, 2, 3, "CC1");
703

    
704
        //Comprobar que en la tabla de cambios locales permanece el cambio
705
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
706
        assertEquals("ws2-changes size", 1, changes.size64());
707

    
708
    }
709

    
710

    
711
}