Revision 7867

View differences:

org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.91/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/pom.xml
1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
    <modelVersion>4.0.0</modelVersion>
3
    <parent>
4
        <groupId>org.gvsig</groupId>
5
        <artifactId>org.gvsig.vcsgis.lib</artifactId>
6
        <version>1.0.91</version>
7
    </parent>
8
    <artifactId>org.gvsig.vcsgis.lib.impl</artifactId>
9
    <name>${project.artifactId}</name>
10
    <dependencies>
11
        <dependency>
12
            <groupId>org.gvsig</groupId>
13
            <artifactId>org.gvsig.vcsgis.lib.api</artifactId>
14
            <scope>compile</scope>
15
        </dependency>
16
        <dependency>
17
            <groupId>org.gvsig</groupId>
18
            <artifactId>org.gvsig.fmap.dal.impl</artifactId>
19
            <scope>test</scope>
20
        </dependency>
21
        <dependency>
22
            <groupId>org.gvsig</groupId>
23
            <!--<artifactId>${org.gvsig.h2spatial.provider}</artifactId>-->
24
            <artifactId>org.gvsig.h2spatial.h2gis132.provider</artifactId>
25
            <scope>compile</scope>
26
            <exclusions>
27
                <exclusion>
28
                    <!-- postgis-jts-osgi-5.0.1.jar  -->
29
                    <groupId>org.orbisgis</groupId>
30
                    <artifactId>postgis-jts-osgi</artifactId>
31
                </exclusion>
32
            </exclusions>
33
        </dependency>            
34
        <dependency>
35
            <groupId>org.gvsig</groupId>
36
            <artifactId>org.gvsig.fmap.dal.file.csv</artifactId>
37
            <scope>compile</scope>
38
        </dependency>
39
        <dependency>
40
            <groupId>org.gvsig</groupId>
41
            <artifactId>${org.gvsig.fmap.geometry.impl}</artifactId>
42
            <scope>test</scope>
43
        </dependency>    
44
        <dependency>
45
            <groupId>org.gvsig</groupId>
46
            <artifactId>org.gvsig.expressionevaluator.lib.impl</artifactId>
47
            <scope>test</scope>
48
        </dependency>    
49
        <dependency>
50
            <groupId>org.gvsig</groupId>
51
            <artifactId>org.gvsig.expressionevaluator.geometry.lib.impl</artifactId>
52
            <scope>test</scope>
53
        </dependency>    
54
        <dependency>
55
            <groupId>org.gvsig</groupId>
56
            <artifactId>org.gvsig.expressionevaluator.swing.impl</artifactId>
57
            <scope>test</scope>
58
        </dependency>    
59
        <dependency>
60
            <groupId>org.gvsig</groupId>
61
            <artifactId>${org.gvsig.proj.lib.impl}</artifactId>
62
            <scope>test</scope>
63
        </dependency>
64
        <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.compat.se</artifactId>
67
            <scope>test</scope>
68
        </dependency>
69
        <dependency>
70
            <groupId>org.gvsig</groupId>
71
            <artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
72
            <scope>test</scope>
73
        </dependency>      
74
        <dependency>
75
            <groupId>org.gvsig</groupId>
76
            <artifactId>org.gvsig.timesupport.lib.impl</artifactId>
77
            <scope>test</scope>
78
        </dependency>
79
<!--        <dependency>
80
            <groupId>org.gvsig</groupId>
81
            <artifactId>org.gvsig.fmap.dal.file.csv</artifactId>
82
            <scope>test</scope>
83
        </dependency>-->
84
        <dependency>
85
            <groupId>org.gvsig</groupId>
86
            <artifactId>org.gvsig.tools.lib</artifactId>
87
            <scope>test</scope>
88
            <type>test-jar</type>
89
        </dependency>
90
        <dependency>
91
            <groupId>org.gvsig</groupId>
92
            <artifactId>org.gvsig.tools.util.impl</artifactId>
93
            <scope>test</scope>
94
        </dependency>
95
        <dependency>
96
            <groupId>org.gvsig</groupId>
97
            <artifactId>org.gvsig.tools.swing.impl</artifactId>
98
            <scope>test</scope>
99
        </dependency>
100
        <dependency>
101
            <groupId>org.apache.httpcomponents</groupId>
102
            <artifactId>httpclient</artifactId>
103
            <scope>compile</scope>
104
        </dependency>
105
        <dependency>
106
            <groupId>org.gvsig</groupId>
107
            <artifactId>org.gvsig.tools.dynform.spi</artifactId>
108
            <scope>compile</scope>
109
        </dependency>
110
        <dependency>
111
            <groupId>org.gvsig</groupId>
112
            <artifactId>org.gvsig.tools.dynform.impl</artifactId>
113
            <scope>test</scope>
114
        </dependency>
115
        <dependency>
116
            <groupId>org.gvsig</groupId>
117
            <artifactId>org.gvsig.tools.dynform.services</artifactId>
118
            <scope>test</scope>
119
        </dependency>
120
        <dependency>
121
            <groupId>org.gvsig</groupId>
122
            <artifactId>org.gvsig.fmap.mapcontext.impl</artifactId>
123
            <scope>test</scope>
124
        </dependency>
125
        <dependency>
126
            <groupId>org.gvsig</groupId>
127
            <artifactId>org.gvsig.raster.lib.buffer.impl</artifactId>
128
            <scope>test</scope>
129
        </dependency>
130
        <dependency>
131
            <groupId>org.gvsig</groupId>
132
            <artifactId>org.gvsig.raster.lib.buffer.spi</artifactId>
133
            <scope>test</scope>
134
        </dependency>
135
                
136
        <dependency>
137
            <groupId>org.gvsig</groupId>
138
            <artifactId>org.gvsig.fmap.dal.swing.api</artifactId>
139
            <scope>compile</scope>
140
        </dependency>
141
        <dependency>
142
            <groupId>org.gvsig</groupId>
143
            <artifactId>org.gvsig.fmap.dal.swing.impl</artifactId>
144
            <scope>test</scope>
145
        </dependency>
146

  
147
        <dependency>
148
            <groupId>javax.servlet</groupId>
149
            <artifactId>javax.servlet-api</artifactId>
150
            <scope>compile</scope>
151
        </dependency>
152

  
153
        <dependency>
154
            <groupId>commons-io</groupId>
155
            <artifactId>commons-io</artifactId>
156
            <scope>compile</scope>
157
        </dependency>
158

  
159
        <dependency>
160
            <groupId>org.gvsig</groupId>
161
            <artifactId>org.gvsig.oracle.provider</artifactId>
162
            <scope>test</scope>
163
        </dependency>
164
        <dependency>
165
            <groupId>org.gvsig</groupId>
166
            <artifactId>org.gvsig.postgresql.provider</artifactId>
167
            <scope>test</scope>
168
        </dependency>
169
    </dependencies>
170
    <build>
171
        <plugins>
172

  
173
            <plugin>
174
                <groupId>org.apache.maven.plugins</groupId>
175
                <artifactId>maven-surefire-plugin</artifactId>
176
                <configuration>
177
                    <!-- Skip test execution ? -->
178
                    <skipTests>true</skipTests>
179
                    <!-- Ignore test execution failure ? -->
180
                    <testFailureIgnore>false</testFailureIgnore>
181
                </configuration>
182
            </plugin>
183
        
184
            <!-- Skip test compilation ? -->
185
            <plugin>
186
                <groupId>org.apache.maven.plugins</groupId>
187
                <artifactId>maven-compiler-plugin</artifactId>
188
                <executions>
189
                    <execution>
190
                        <id>default-testCompile</id>
191
                        <phase>process-test-sources</phase>
192
                        <goals>
193
                            <goal>testCompile</goal>
194
                        </goals>
195
                        <configuration>
196
                            <skip>false</skip>
197
                        </configuration>
198
                    </execution>
199
                </executions>
200
            </plugin>
201
            <plugin>
202
                <groupId>org.apache.maven.plugins</groupId>
203
                <artifactId>maven-jar-plugin</artifactId>
204
                <configuration>
205
                </configuration>
206
                <executions>
207
                    <!-- Generates a jar file only with the test classes -->
208
                    <execution>
209
                        <goals>
210
                            <goal>test-jar</goal>
211
                        </goals>
212
                    </execution>
213
                </executions>
214
            </plugin>
215
        </plugins>
216
    </build>
217

  
218
</project>
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.91/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/test/java/org/gvsig/vcsgis/lib/impl/AbstractTest14UpdateWithConflict.java
1
package org.gvsig.vcsgis.lib.impl;
2

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

  
29
public abstract class AbstractTest14UpdateWithConflict extends AbstractTestVCSGIS {
30

  
31
    public AbstractTest14UpdateWithConflict(String testName) {
32
        super(testName);
33
    }
34

  
35
    @Override
36
    protected void setUp() throws Exception {
37
        super.setUp();
38
    }
39

  
40
    @Override
41
    protected void tearDown() throws Exception {
42
        super.tearDown();
43
    }
44

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

  
70
    private void check(FeatureStore store2, String relatedFeatureCode, int id, String text) throws Exception {
71
        Feature f = store2.findFirst("VCSGISCODE = '"+relatedFeatureCode+"'");
72
        assertEquals(id, f.getInt("id"));
73
        assertEquals(text, f.getString("text"));
74
    }
75
    
76
    private void selectRemoteChange(VCSGisWorkspace ws, boolean select, int id, String text, VCSGisWorkspace wsSource) throws Exception {
77
        Feature fTest;
78
        FeatureStore testStore = ws.openFeatureStore("test",false);
79
        FeatureStore testStoreSource = wsSource.openFeatureStore("test",false);
80
        
81
        fTest = testStoreSource.findFirst("id = "+id);
82

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

  
112
    private VCSGisWorkspace[] initTest() throws Exception{
113
        utils().cleanRepositoryDatabase();
114
        
115
        VCSGisManager manager = VCSGisLocator.getVCSGisManager();
116
        JDBCServerExplorer server = utils().openRepositoryServerExplorer("srv-update");
117
        File ws1file = utils().getFile(FileUtils.getFile("test-dbs","ws1-update")); 
118
        File ws2file = utils().getFile(FileUtils.getFile("test-dbs","ws2-update")); 
119
        File ws3file = utils().getFile(FileUtils.getFile("test-dbs","ws3-update")); 
120
        
121
        manager.setCodeGenerator(new SequentialCodeGenerator());
122
        
123
        int r;
124
        List<Feature> features;
125
        FeatureStore store2;
126
        FeatureStore store3;
127

  
128
        // ------------------------------------------------------------
129
        // Inicializamos el repositorio y lo abrimos
130
        r = manager.initRepository(server.getParameters(), null);
131
        assertEquals("init_server status", ERR_NO_ERROR, r);
132
        
133
        VCSGisRepository repo = manager.openRepository(server.getParameters());
134
        utils().info_repository(repo);
135

  
136
        // ------------------------------------------------------------
137
        // Creamos workspace1 y lo abrimos.
138
        r = manager.initWorkspace(ws1file, repo, "Test update1",null);
139
        assertEquals("init_ws1 status", ERR_NO_ERROR, r);
140
        
141
        VCSGisWorkspace ws1 = manager.openWorkspace(ws1file);
142
        utils().info_workspace(ws1);
143

  
144
        // ------------------------------------------------------------
145
        // Adicionamos al workspace1 la tabla "test" y la commitamos.
146
        //REV 0
147
        FeatureStore sourceTest = utils().openSourceStore2();
148
        r = ws1.add("test", sourceTest, "text");
149
        DisposeUtils.disposeQuietly(sourceTest);
150
        assertEquals("ws1.add status", ERR_NO_ERROR, r);
151

  
152
        r = ws1.commit();
153
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
154

  
155

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

  
182

  
183

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

  
239
        // Añadimos al workspace2 una feature con la misma id
240
        store2 = ws2.openFeatureStore("test",false);
241
        store2.edit();
242
        update(store2, 3, "CC2");
243
        
244
        store2.finishEditing();
245
        DisposeUtils.disposeQuietly(store2);
246

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

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

  
268
    }
269

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

  
297
        // Editamos en el workspace2 la feature con la misma id
298
        store2 = ws2.openFeatureStore("test",false);
299
        store2.edit();
300
        update(store2, 3, "CC2");
301
        
302
        store2.finishEditing();
303
        DisposeUtils.disposeQuietly(store2);
304

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

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

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

  
356
        DisposeUtils.disposeQuietly(store3);
357

  
358
    }
359

  
360

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

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

  
386
        // Añadimos al workspace2 una feature con la misma id
387
        store2 = ws2.openFeatureStore("test",false);
388
        store2.edit();
389
        update(store2, 3, "CC2");
390
        
391
        store2.finishEditing();
392
        DisposeUtils.disposeQuietly(store2);
393

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

  
406
        //Seleccionar el cambio conflictivo id=4
407
        selectRemoteChange(ws2, true, 3, "CC1", ws1);
408

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

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

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

  
449
        // Añadimos al workspace2 una feature con la misma id
450
        store2 = ws2.openFeatureStore("test",false);
451
        store2.edit();
452
        f = insert(store2, 4, "DD2");
453
        String code_id4_DD2 = f.getString("VCSGISCODE");
454
        
455
        store2.finishEditing();
456
        DisposeUtils.disposeQuietly(store2);
457

  
458
        
459
        // ------------------------------------------------------------
460
        // Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 
461
        // comprobamos que funciona y que tiene lo que toca.
462
        r = ws2.updatePrepare("test");
463
        assertEquals("ws2.updatePrepare-1 status", ERR_NO_ERROR, r);
464
        
465
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
466
        checkLocalChange(store2, changes, code_id4_DD2, OP_INSERT, 4, "DD2", STATE_CONFLICT);
467
        DisposeUtils.dispose(changes);
468
        
469
        // Actualizamos (update) la tabla "test" en el workspace2 
470
        // comprobamos que no falla
471
        r = ws2.update("test");
472
        assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r);
473

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

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

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

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

  
495
    }
496

  
497
    protected 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.openFeatureStore("test",false);
515
        store1.edit();
516
        f = insert(store1, 4, "DD1");
517
        String code_id4_DD1 = f.getString("VCSGISCODE");
518
        
519
        store1.finishEditing();
520
        DisposeUtils.disposeQuietly(store1);
521
        
522
        r = ws1.commit();
523
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
524
        
525

  
526
        // Añadimos al workspace2 una feature con la misma id
527
        store2 = ws2.openFeatureStore("test",false);
528
        store2.edit();
529
        f = insert(store2, 4, "DD2");
530
        String code_id4_DD2 = f.getString("VCSGISCODE");
531
        
532
        store2.finishEditing();
533
        DisposeUtils.disposeQuietly(store2);
534

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

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

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

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

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

  
565
        checkLocalChange(store2, changes, code_id4_DD1, OP_DELETE, 4, "DD1", -1);
566
        
567
        checkLocalChange(store2, changes, code_id4_DD2, OP_INSERT, 4, "DD2", -1);
568
        DisposeUtils.dispose(changes);
569

  
570
    }
571

  
572

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

  
599
        // Borramos en el workspace2 la feature con la misma id
600
        store2 = ws2.openFeatureStore("test",false);
601
        store2.edit();
602
        delete(store2, 3, "CCC");
603
        
604
        store2.finishEditing();
605
        DisposeUtils.disposeQuietly(store2);
606

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

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

  
624

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

  
632
        store2 = ws2.openFeatureStore("test",false);
633
        assertEquals("ws2-update sizes", 3, store2.size64());
634
        features = store2.getFeatures((Expression)null, "id", true);
635
        
636
        check(features, 0, 1, "AAA");
637
        check(features, 1, 2, "BBB");
638
        check(features, 2, 3, "CC1");
639

  
640
        //Comprobar que en la tabla de cambios locales no hay nada
641
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
642
        assertEquals("ws2-changes size", 0, changes.size64());
643
        DisposeUtils.dispose(changes);
644
    }
645
    
646

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

  
673
        // Borramos en el workspace2 la feature con la misma id
674
        store2 = ws2.openFeatureStore("test",false);
675
        store2.edit();
676
        delete(store2, 3, "CCC");
677
        
678
        store2.finishEditing();
679
        DisposeUtils.disposeQuietly(store2);
680

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

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

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

  
707
        //Comprobar que en la tabla de cambios locales permanece el cambio
708
        FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
709
        assertEquals("ws2-changes size", 1, changes.size64());
710
        DisposeUtils.dispose(changes);
711

  
712
    }
713

  
714

  
715
}
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.91/org.gvsig.vcsgis.lib/org.gvsig.vcsgis.lib.impl/src/test/java/org/gvsig/vcsgis/lib/impl/AbstractTest20ExportToEffectiveDate.java
1
package org.gvsig.vcsgis.lib.impl;
2

  
3
import java.io.File;
4
import java.sql.Timestamp;
5
import java.util.List;
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 org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
14
import org.gvsig.tools.dispose.DisposeUtils;
15
import org.gvsig.vcsgis.lib.SequentialCodeGenerator;
16
import org.gvsig.vcsgis.lib.VCSGisLocator;
17
import org.gvsig.vcsgis.lib.VCSGisManager;
18
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR;
19
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
20
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace;
21

  
22
public abstract class AbstractTest20ExportToEffectiveDate extends AbstractTestVCSGIS {
23

  
24
    public AbstractTest20ExportToEffectiveDate(String testName) {
25
        super(testName);
26
    }
27

  
28
    @Override
29
    protected void setUp() throws Exception {
30
        super.setUp();
31
    }
32

  
33
    @Override
34
    protected void tearDown() throws Exception {
35
        super.tearDown();
36
    }
37

  
38
    // TODO add test methods here. The name must begin with 'test'. For example:
39
    // public void testHello() {}
40

  
41
    private void insert(FeatureStore store, int id, String text) throws DataException{
42
        EditableFeature ef = store.createNewFeature();
43
        ef.set("id",id);
44
        ef.set("text",text);
45
        store.insert(ef);
46
    }
47
    
48
    private void update(FeatureStore store, int id, String text) throws DataException{
49
        Feature f = store.findFirst("id="+id);
50
        EditableFeature ef = f.getEditable();
51
        ef.set("text", text);
52
        store.update(ef);
53
    }
54
    
55
    private void delete(FeatureStore store, int id, String text) throws DataException{
56
        Feature f = store.findFirst("id="+id);
57
        store.delete(f);
58
    }
59
    
60
    private void check(List<Feature> features, int index, int id, String text){
61
        assertEquals(id    , features.get(index).getInt("id"));
62
        assertEquals(text, features.get(index).getString("text"));
63
    }
64

  
65
    private void check(FeatureStore store2, String relatedFeatureCode, int id, String text) throws Exception {
66
        Feature f = store2.findFirst("VCSGISCODE = '"+relatedFeatureCode+"'");
67
        assertEquals(id, f.getInt("id"));
68
        assertEquals(text, f.getString("text"));
69
    }
70

  
71
    protected void testExportToEffectiveDateConsecutive() throws Exception {
72
        utils().cleanRepositoryDatabase();
73
        
74
        VCSGisManager manager = VCSGisLocator.getVCSGisManager();
75
        manager.setCodeGenerator(new SequentialCodeGenerator());
76
        
77
        JDBCServerExplorer server = utils().openRepositoryServerExplorer("srv-update");
78
        File ws1file = utils().getFile(FileUtils.getFile("test-dbs","ws1-update")); 
79
        File ws2file = utils().getFile(FileUtils.getFile("test-dbs","ws2-update")); 
80
        
81
        int r;
82
        Feature f;
83
        EditableFeature ef;
84
        List<Feature> features;
85
        FeatureStore store1;
86
        FeatureStore store2;
87
        
88
        // ------------------------------------------------------------
89
        // Inicializamos el repositorio y lo abrimos
90
        r = manager.initRepository(server.getParameters(), null);
91
        assertEquals("init_server status", ERR_NO_ERROR, r);
92
        
93
        VCSGisRepository repo = manager.openRepository(server.getParameters());
94
        utils().info_repository(repo);
95

  
96
        // ------------------------------------------------------------
97
        // Creamos workspace1 y lo abrimos.
98
        r = manager.initWorkspace(ws1file, repo, "Test update1",null);
99
        assertEquals("init_ws1 status", ERR_NO_ERROR, r);
100
        
101
        VCSGisWorkspace ws1 = manager.openWorkspace(ws1file);
102
        utils().info_workspace(ws1);
103

  
104
        // ------------------------------------------------------------
105
        // Adicionamos al workspace1 la tabla "test" y la commitamos.
106
        //REV 0
107
        FeatureStore sourceTest = utils().openSourceStore2();
108
        r = ws1.add("test", sourceTest, "text");
109
        DisposeUtils.disposeQuietly(sourceTest);
110
        assertEquals("ws1.add status", ERR_NO_ERROR, r);
111

  
112
        store1 = ws1.openFeatureStore("test",false);
113
        store1.edit();
114
        insert(store1, 4, "DDD");
115
        insert(store1, 5, "EEE");
116
        
117
        store1.finishEditing();
118
        DisposeUtils.disposeQuietly(store1);
119
        
120
        r = ws1.commit(null, Timestamp.valueOf("2021-01-01 00:00:00.000"), "2021-01-01 00:00:00.000", null);
121
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
122

  
123
        //REV 1
124
        store1 = ws1.openFeatureStore("test",false);
125
        store1.edit();
126
        insert(store1, 6, "FFF");
127
        insert(store1, 7, "GGG");
128
        insert(store1, 8, "HHH");
129
        insert(store1, 9, "III");
130
        insert(store1, 10, "JJJ");
131
        delete(store1, 5, "EEE");
132
        update(store1, 2, "BB2");
133
        update(store1, 4, "DD2");
134
        
135
        store1.finishEditing();
136
        DisposeUtils.disposeQuietly(store1);
137
        
138
        r = ws1.commit(null, Timestamp.valueOf("2021-02-01 00:00:00.000"), "2021-02-01 00:00:00.000", null);
139
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
140

  
141
        //REV 2
142
        
143
        store1 = ws1.openFeatureStore("test",false);
144
        store1.edit();
145
        insert(store1, 11, "KKK");
146
        insert(store1, 12, "LLL");
147
        insert(store1, 13, "MMM");
148
        delete(store1, 4, "DD2");
149
        delete(store1, 7, "GGG");
150
        
151
        store1.finishEditing();
152
        DisposeUtils.disposeQuietly(store1);
153
        
154
        r = ws1.commit(null, Timestamp.valueOf("2021-03-01 00:00:00.000"), "2021-03-01 00:00:00.000", null);
155
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
156
        
157
        
158
        //REV 3
159
        
160
        store1 = ws1.openFeatureStore("test",false);
161
        store1.edit();
162
        
163
        insert(store1, 14, "NNN");
164
        insert(store1, 15, "OOO");
165
        insert(store1, 16, "PPP");
166
        insert(store1, 17, "QQQ");
167
        delete(store1, 3, "CCC");
168
        delete(store1, 10, "JJJ");
169
        update(store1, 13, "MM2");
170
        
171
        store1.finishEditing();
172
        DisposeUtils.disposeQuietly(store1);
173
        
174
        r = ws1.commit(null, Timestamp.valueOf("2021-04-01 00:00:00.000"), "2021-04-01 00:00:00.000", null);
175
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
176
        
177
        //REV 4
178
        
179
        store1 = ws1.openFeatureStore("test",false);
180
        store1.edit();
181
        
182
        insert(store1, 18, "RRR");
183
        insert(store1, 19, "SSS");
184
        insert(store1, 20, "TTT");
185
        insert(store1, 21, "UUU");
186
        delete(store1, 9, "III");
187
        update(store1, 17, "QQ2");
188
        delete(store1, 16, "PPP");
189
        
190
        store1.finishEditing();
191
        DisposeUtils.disposeQuietly(store1);
192
        
193
        r = ws1.commit(null, Timestamp.valueOf("2021-05-01 00:00:00.000"), "2021-05-01 00:00:00.000", null);
194
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
195

  
196
        //REV 5
197
        
198
        store1 = ws1.openFeatureStore("test",false);
199
        store1.edit();
200
        
201
        insert(store1, 22, "VVV");
202
        insert(store1, 23, "WWW");
203
        insert(store1, 24, "XXX");
204
        insert(store1, 25, "YYY");
205
        insert(store1, 26, "ZZZ");
206
        delete(store1, 13, "MM2");
207
        delete(store1, 19, "SSS");
208
        
209
        store1.finishEditing();
210
        DisposeUtils.disposeQuietly(store1);
211
        
212
        r = ws1.commit(null, Timestamp.valueOf("2021-06-01 00:00:00.000"), "2021-06-01 00:00:00.000", null);
213
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
214

  
215
        //Export enero
216
        r = ws1.export("test", "exp_enero", null, Timestamp.valueOf("2021-01-15 00:00:00.000"), null, null);
217
        assertEquals("ws1.export-1 status", 0, r);
218
        store2 = ws1.openFeatureStore("exp_enero",false);
219
        features = store2.getFeatures((Expression)null, "id", true);
220
        
221
        check(features, 0, 1, "AAA");
222
        check(features, 1, 2, "BBB");
223
        check(features, 2, 3, "CCC");
224
        check(features, 3, 4, "DDD");
225
        check(features, 4, 5, "EEE");
226
        
227
        DisposeUtils.disposeQuietly(features);
228
        DisposeUtils.disposeQuietly(store2);
229

  
230
        //Export febrero
231
        r = ws1.export("test", "exp_febrero", null, Timestamp.valueOf("2021-02-15 00:00:00.000"), null, null);
232
        assertEquals("ws1.export-1 status", 0, r);
233
        store2 = ws1.openFeatureStore("exp_febrero",false);
234
        features = store2.getFeatures((Expression)null, "id", true);
235
        
236
        check(features, 0, 1, "AAA");
237
        check(features, 1, 2, "BB2");
238
        check(features, 2, 3, "CCC");
239
        check(features, 3, 4, "DD2");
240
        check(features, 4, 6, "FFF");
241
        check(features, 5, 7, "GGG");
242
        check(features, 6, 8, "HHH");
243
        check(features, 7, 9, "III");
244
        check(features, 8, 10, "JJJ");
245

  
246
        
247
        DisposeUtils.disposeQuietly(features);
248
        DisposeUtils.disposeQuietly(store2);
249

  
250

  
251
        //Export marzo
252
        r = ws1.export("test", "exp_marzo", null, Timestamp.valueOf("2021-03-15 00:00:00.000"), null, null);
253
        assertEquals("ws1.export-1 status", 0, r);
254
        store2 = ws1.openFeatureStore("exp_marzo",false);
255
        features = store2.getFeatures((Expression)null, "id", true);
256
        
257
        check(features, 0, 1, "AAA");
258
        check(features, 1, 2, "BB2");
259
        check(features, 2, 3, "CCC");
260
        check(features, 3, 6, "FFF");
261
        check(features, 4, 8, "HHH");
262
        check(features, 5, 9, "III");
263
        check(features, 6, 10, "JJJ");
264
        check(features, 7, 11, "KKK");
265
        check(features, 8, 12, "LLL");
266
        check(features, 9, 13, "MMM");
267

  
268
        DisposeUtils.disposeQuietly(features);
269
        DisposeUtils.disposeQuietly(store2);
270

  
271

  
272
        //Export abril
273
        r = ws1.export("test", "exp_abril", null, Timestamp.valueOf("2021-04-15 00:00:00.000"), null, null);
274
        assertEquals("ws1.export-1 status", 0, r);
275
        store2 = ws1.openFeatureStore("exp_abril",false);
276
        features = store2.getFeatures((Expression)null, "id", true);
277
        
278
        check(features, 0, 1, "AAA");
279
        check(features, 1, 2, "BB2");
280
        check(features, 2, 6, "FFF");
281
        check(features, 3, 8, "HHH");
282
        check(features, 4, 9, "III");
283
        check(features, 5, 11, "KKK");
284
        check(features, 6, 12, "LLL");
285
        check(features, 7, 13, "MM2");
286
        check(features, 8, 14, "NNN");
287
        check(features, 9, 15, "OOO");
288
        check(features, 10, 16, "PPP");
289
        check(features, 11, 17, "QQQ");
290

  
291
        
292
        DisposeUtils.disposeQuietly(features);
293
        DisposeUtils.disposeQuietly(store2);
294

  
295
        //Export mayo
296
        r = ws1.export("test", "exp_mayo", null, Timestamp.valueOf("2021-05-15 00:00:00.000"), null, null);
297
        assertEquals("ws1.export-1 status", 0, r);
298
        store2 = ws1.openFeatureStore("exp_mayo",false);
299
        features = store2.getFeatures((Expression)null, "id", true);
300
        
301
        check(features, 0, 1, "AAA");
302
        check(features, 1, 2, "BB2");
303
        check(features, 2, 6, "FFF");
304
        check(features, 3, 8, "HHH");
305
        check(features, 4, 11, "KKK");
306
        check(features, 5, 12, "LLL");
307
        check(features, 6, 13, "MM2");
308
        check(features, 7, 14, "NNN");
309
        check(features, 8, 15, "OOO");
310
        check(features, 9, 17, "QQ2");
311
        check(features, 10, 18, "RRR");
312
        check(features, 11, 19, "SSS");
313
        check(features, 12, 20, "TTT");
314
        check(features, 13, 21, "UUU");
315

  
316
        
317
        DisposeUtils.disposeQuietly(features);
318
        DisposeUtils.disposeQuietly(store2);
319

  
320
        //Export junio
321
        r = ws1.export("test", "exp_junio", null, Timestamp.valueOf("2021-06-15 00:00:00.000"), null, null);
322
        assertEquals("ws1.export-2 status", 0, r);
323
        store2 = ws1.openFeatureStore("exp_junio",false);
324
        features = store2.getFeatures((Expression)null, "id", true);
325
        
326
        int n=0;
327
        check(features, 0, 1, "AAA");
328
        check(features, 1, 2, "BB2");
329
        check(features, 2, 6, "FFF");
330
        check(features, 3, 8, "HHH");
331
        check(features, 4, 11, "KKK");
332
        check(features, 5, 12, "LLL");
333
        check(features, 6, 14, "NNN");
334
        check(features, 7, 15, "OOO");
335
        check(features, 8, 17, "QQ2");
336
        check(features, 9, 18, "RRR");
337
        check(features, 10, 20, "TTT");
338
        check(features, 11, 21, "UUU");
339
        check(features, 12, 22, "VVV");
340
        check(features, 13, 23, "WWW");
341
        check(features, 14, 24, "XXX");
342
        check(features, 15, 25, "YYY");
343
        check(features, 16, 26, "ZZZ");
344

  
345
        DisposeUtils.disposeQuietly(features);
346
        DisposeUtils.disposeQuietly(store2);
347
    }
348

  
349
    protected void testExportToEffectiveDateAlteredOrder() throws Exception {
350
        utils().cleanRepositoryDatabase();
351
        
352
        VCSGisManager manager = VCSGisLocator.getVCSGisManager();
353
        manager.setCodeGenerator(new SequentialCodeGenerator());
354
        
355
        JDBCServerExplorer server = utils().openRepositoryServerExplorer("srv-update");
356
        File ws1file = utils().getFile(FileUtils.getFile("test-dbs","ws1-update")); 
357
        File ws2file = utils().getFile(FileUtils.getFile("test-dbs","ws2-update")); 
358
        
359
        int r;
360
        Feature f;
361
        EditableFeature ef;
362
        List<Feature> features;
363
        FeatureStore store1;
364
        FeatureStore store2;
365
        
366
        // ------------------------------------------------------------
367
        // Inicializamos el repositorio y lo abrimos
368
        r = manager.initRepository(server.getParameters(), null);
369
        assertEquals("init_server status", ERR_NO_ERROR, r);
370
        
371
        VCSGisRepository repo = manager.openRepository(server.getParameters());
372
        utils().info_repository(repo);
373

  
374
        // ------------------------------------------------------------
375
        // Creamos workspace1 y lo abrimos.
376
        r = manager.initWorkspace(ws1file, repo, "Test update1",null);
377
        assertEquals("init_ws1 status", ERR_NO_ERROR, r);
378
        
379
        VCSGisWorkspace ws1 = manager.openWorkspace(ws1file);
380
        utils().info_workspace(ws1);
381

  
382
        // ------------------------------------------------------------
383
        // Adicionamos al workspace1 la tabla "test" y la commitamos.
384
        //REV 0
385
        FeatureStore sourceTest = utils().openSourceStore2();
386
        r = ws1.add("test", sourceTest, "text");
387
        DisposeUtils.disposeQuietly(sourceTest);
388
        assertEquals("ws1.add status", ERR_NO_ERROR, r);
389

  
390
        store1 = ws1.openFeatureStore("test",false);
391
        store1.edit();
392
        insert(store1, 4, "DDD");
393
        insert(store1, 5, "EEE");
394
        
395
        store1.finishEditing();
396
        DisposeUtils.disposeQuietly(store1);
397
        
398
        r = ws1.commit(null, Timestamp.valueOf("2021-01-01 00:00:00.000"), "2021-01-01 00:00:00.000", null);
399
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
400

  
401
        //REV 1
402
        store1 = ws1.openFeatureStore("test",false);
403
        store1.edit();
404
        insert(store1, 6, "FFF");
405
        insert(store1, 7, "GGG");
406
        insert(store1, 8, "HHH");
407
        insert(store1, 9, "III");
408
        insert(store1, 10, "JJJ");
409
        
410
        delete(store1, 5, "EEE");
411
        update(store1, 2, "BB2");
412
        update(store1, 4, "DD2");
413
        
414
        store1.finishEditing();
415
        DisposeUtils.disposeQuietly(store1);
416
        
417
        r = ws1.commit(null, Timestamp.valueOf("2021-02-01 00:00:00.000"), "2021-02-01 00:00:00.000", null);
418
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
419

  
420
        //REV 2
421
        
422
        store1 = ws1.openFeatureStore("test",false);
423
        store1.edit();
424
        insert(store1, 11, "KKK");
425
        insert(store1, 12, "LLL");
426
        insert(store1, 13, "MMM");
427
        
428
        delete(store1, 4, "DD2");
429
        delete(store1, 7, "GGG");
430
        
431
        store1.finishEditing();
432
        DisposeUtils.disposeQuietly(store1);
433
        
434
        r = ws1.commit(null, Timestamp.valueOf("2021-04-01 00:00:00.000"), "2021-04-01 00:00:00.000", null);
435
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
436
        
437
        
438
        //REV 3
439
        
440
        store1 = ws1.openFeatureStore("test",false);
441
        store1.edit();
442
        
443
        insert(store1, 14, "NNN");
444
        insert(store1, 15, "OOO");
445
        insert(store1, 16, "PPP");
446
        insert(store1, 17, "QQQ");
447
        delete(store1, 3, "CCC");
448
        delete(store1, 10, "JJJ");
449
        update(store1, 13, "MM2");
450
        
451
        store1.finishEditing();
452
        DisposeUtils.disposeQuietly(store1);
453
        
454
        r = ws1.commit(null, Timestamp.valueOf("2021-03-01 00:00:00.000"), "2021-03-01 00:00:00.000", null);
455
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
456
        
457
        //REV 4
458
        
459
        store1 = ws1.openFeatureStore("test",false);
460
        store1.edit();
461
        
462
        insert(store1, 18, "RRR");
463
        insert(store1, 19, "SSS");
464
        insert(store1, 20, "TTT");
465
        insert(store1, 21, "UUU");
466
        
467
        delete(store1, 9, "III");
468
        update(store1, 17, "QQ2");
469
        delete(store1, 16, "PPP");
470
        
471
        store1.finishEditing();
472
        DisposeUtils.disposeQuietly(store1);
473
        
474
        r = ws1.commit(null, Timestamp.valueOf("2021-06-01 00:00:00.000"), "2021-06-01 00:00:00.000", null);
475
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
476

  
477
        //REV 5
478
        
479
        store1 = ws1.openFeatureStore("test",false);
480
        store1.edit();
481
        
482
        insert(store1, 22, "VVV");
483
        insert(store1, 23, "WWW");
484
        insert(store1, 24, "XXX");
485
        insert(store1, 25, "YYY");
486
        insert(store1, 26, "ZZZ");
487
        delete(store1, 13, "MM2");
488
        delete(store1, 19, "SSS");
489
        
490
        store1.finishEditing();
491
        DisposeUtils.disposeQuietly(store1);
492
        
493
        r = ws1.commit(null, Timestamp.valueOf("2021-05-01 00:00:00.000"), "2021-05-01 00:00:00.000", null);
494
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
495

  
496
        //Export enero
497
        r = ws1.export("test", "exp_enero", null, Timestamp.valueOf("2021-01-15 00:00:00.000"), null, null);
498
        assertEquals("ws1.export-1 status", 0, r);
499
        store2 = ws1.openFeatureStore("exp_enero",false);
500
        features = store2.getFeatures((Expression)null, "id", true);
501
        
502
        check(features, 0, 1, "AAA");
503
        check(features, 1, 2, "BBB");
504
        check(features, 2, 3, "CCC");
505
        check(features, 3, 4, "DDD");
506
        check(features, 4, 5, "EEE");
507
        
508
        DisposeUtils.disposeQuietly(features);
509
        DisposeUtils.disposeQuietly(store2);
510

  
511
        //Export febrero
512
        r = ws1.export("test", "exp_febrero", null, Timestamp.valueOf("2021-02-15 00:00:00.000"), null, null);
513
        assertEquals("ws1.export-1 status", 0, r);
514
        store2 = ws1.openFeatureStore("exp_febrero",false);
515
        features = store2.getFeatures((Expression)null, "id", true);
516
        
517
        check(features, 0, 1, "AAA");
518
        check(features, 1, 2, "BB2");
519
        check(features, 2, 3, "CCC");
520
        check(features, 3, 4, "DD2");
521
        check(features, 4, 6, "FFF");
522
        check(features, 5, 7, "GGG");
523
        check(features, 6, 8, "HHH");
524
        check(features, 7, 9, "III");
525
        check(features, 8, 10, "JJJ");
526

  
527
        
528
        DisposeUtils.disposeQuietly(features);
529
        DisposeUtils.disposeQuietly(store2);
530

  
531

  
532
        //Export marzo
533
        r = ws1.export("test", "exp_marzo", null, Timestamp.valueOf("2021-03-15 00:00:00.000"), null, null);
534
        assertEquals("ws1.export-1 status", 0, r);
535
        store2 = ws1.openFeatureStore("exp_marzo",false);
536
        features = store2.getFeatures((Expression)null, "id", true);
537
        
538
        check(features, 0, 1, "AAA");
539
        check(features, 1, 2, "BB2");
540
        check(features, 2, 4, "DD2");
541
        check(features, 3, 6, "FFF");
542
        check(features, 4, 7, "GGG");
543
        check(features, 5, 8, "HHH");
544
        check(features, 6, 9, "III");
545
        check(features, 7, 13, "MM2");
546
        check(features, 8, 14, "NNN");
547
        check(features, 9, 15, "OOO");
548
        check(features, 10, 16, "PPP");
549
        check(features, 11, 17, "QQQ");
550
        
551
//        update(store1, 13, "MM2");
552

  
553
        
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff