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 / Test09CommitOutdated.java @ 2697

History | View | Annotate | Download (5.74 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.fmap.dal.feature.FeatureStore;
9
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
10
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13
import org.gvsig.vcsgis.lib.vcsgisadmin;
14
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
15
import org.gvsig.vcsgis.lib.client.VCSGisWorkspace;
16
import org.gvsig.fmap.dal.feature.EditableFeature;
17
import org.gvsig.fmap.dal.feature.Feature;
18
import org.gvsig.tools.dispose.DisposeUtils;
19
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_CANT_COMMIT_WORKSPACE_OUTDATED;
20
import static org.gvsig.vcsgis.lib.client.VCSGisWorkspace.ERR_NO_ERROR;
21
import org.gvsig.vcsgis.lib.vcsgis;
22

    
23
public class Test09CommitOutdated extends TestCase {
24

    
25
    private static final Logger LOGGER = LoggerFactory.getLogger(Test09CommitOutdated.class);
26

    
27
    public Test09CommitOutdated(String testName) {
28
        super(testName);
29
    }
30

    
31
    @Override
32
    protected void setUp() throws Exception {
33
        super.setUp();
34
        new DefaultLibrariesInitializer().fullInitialize();
35
    }
36

    
37
    @Override
38
    protected void tearDown() throws Exception {
39
        super.tearDown();
40
    }
41

    
42
    // TODO add test methods here. The name must begin with 'test'. For example:
43
    // public void testHello() {}
44

    
45
    public void testCommitOutdated() throws Exception {
46
        JDBCServerExplorer server = TestUtils.openServerExplorer("srv-commitoutdated");
47
        File ws1file = TestUtils.getFile(FileUtils.getFile("test-dbs","ws1-commitoutdated")); 
48
        File ws2file = TestUtils.getFile(FileUtils.getFile("test-dbs","ws2-commitoutdated")); 
49
        
50
        int r;
51
        Feature f;
52
        EditableFeature ef;
53
        List<Feature> features;
54
        FeatureStore store1;
55
        FeatureStore store2;
56

    
57
        // ------------------------------------------------------------
58
        // Inicializamos el repositorio y lo abrimos
59
        r = vcsgisadmin.init_repository(server);
60
        assertEquals("init_server status", ERR_NO_ERROR, r);
61
        
62
        VCSGisRepository repo = vcsgisadmin.open_repository(server);
63
        TestUtils.h2sql_repository(repo);
64

    
65
        // ------------------------------------------------------------
66
        // Creamos workspace1 y lo abrimos.
67
        r = vcsgis.init_workspace(ws1file, repo, "Test update1");
68
        assertEquals("init_ws1 status", ERR_NO_ERROR, r);
69
        
70
        VCSGisWorkspace ws1 = vcsgis.open_workspace(ws1file);
71
        TestUtils.h2sql_workspace(ws1);
72

    
73
        // ------------------------------------------------------------
74
        // A?adimos al workspace1 la tabla "test" y la commitamos.
75
        FeatureStore sourceTest = TestUtils.openSourceStore2();
76
        r = ws1.add("test", sourceTest, "text");
77
        assertEquals("ws1.add status", ERR_NO_ERROR, r);
78
        r = ws1.commit();
79
        assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
80
        DisposeUtils.disposeQuietly(sourceTest);
81

    
82
        
83
        // ------------------------------------------------------------
84
        // Inicializamos el workspace2 asociandolo al mismo repositorio que 
85
        // workspace1 y lo abrimos.
86
        r = vcsgis.init_workspace(ws2file, repo, "Test update2");
87
        assertEquals("init_ws2 status", ERR_NO_ERROR, r);
88
        VCSGisWorkspace ws2 = vcsgis.open_workspace(ws2file);
89
        TestUtils.h2sql_workspace(ws2);
90
        
91
        // ------------------------------------------------------------
92
        // Hacemos un checkout en workspace2 de la tabla "test" y comprobamos
93
        // que tiene lo que toca.
94
        r = ws2.checkout("test");
95
        assertEquals("ws2-checkout status", ERR_NO_ERROR, r);
96

    
97
        store2 = ws2.getFeatureStore("test");
98
        assertEquals("ws2-checkout sizes", 3, store2.size64());
99
        features = store2.getFeatures();
100
        assertEquals(1    , features.get(0).getInt("id"));
101
        assertEquals("AAA", features.get(0).getString("text"));
102
        assertEquals(2    , features.get(1).getInt("id"));
103
        assertEquals("BBB", features.get(1).getString("text"));
104
        assertEquals(3    , features.get(2).getInt("id"));
105
        assertEquals("CCC", features.get(2).getString("text"));
106
        
107
        DisposeUtils.disposeQuietly(store2);
108
        
109
        // ------------------------------------------------------------
110
        // Modificamos la tabla "test" en el workspace1 y la commitamos.
111
        store1 = ws1.getFeatureStore("test");
112
        store1.edit();
113
        f = store1.findFirst("id=2");
114
        ef = f.getEditable();
115
        ef.set("text", "BB2");
116
        store1.update(ef);
117
        
118
        ef = store1.createNewFeature();
119
        ef.set("id",4);
120
        ef.set("text","DDD");
121
        store1.insert(ef);
122
        store1.finishEditing();
123
        DisposeUtils.disposeQuietly(store1);
124
        r = ws1.commit();
125
        assertEquals("ws1.commit-2 status", ERR_NO_ERROR, r);
126
        
127
        
128
        // ------------------------------------------------------------
129
        // Modificamos la tabla "test" en el workspace2 y la commitamos.
130
        // Debe fallar ya que hay cambios pendientes de actualizar desde el 
131
        // repositorio.
132
        store2 = ws2.getFeatureStore("test");
133
        store2.edit();
134
        ef = store2.createNewFeature();
135
        ef.set("id",5);
136
        ef.set("text","EEE");
137
        store2.insert(ef);
138

    
139
        f = store2.findFirst("id=3");
140
        store2.delete(f);        
141
        store2.finishEditing();
142
        DisposeUtils.disposeQuietly(store2);
143
        r = ws2.commit();
144
        assertEquals("ws2.commit-1 status", ERR_CANT_COMMIT_WORKSPACE_OUTDATED, r);
145

    
146
        DisposeUtils.disposeQuietly(store2);
147

    
148
        
149
    }
150
}