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 @ 2823
History | View | Annotate | Download (6.05 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.feature.EditableFeature; |
10 |
import org.gvsig.fmap.dal.feature.Feature; |
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
12 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
13 |
import org.gvsig.tools.dispose.DisposeUtils; |
14 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
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_CANT_COMMIT_WORKSPACE_OUTDATED; |
19 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR; |
20 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
21 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
22 |
import org.slf4j.Logger; |
23 |
import org.slf4j.LoggerFactory; |
24 |
|
25 |
public class Test09CommitOutdated extends TestCase { |
26 |
|
27 |
private static final Logger LOGGER = LoggerFactory.getLogger(Test09CommitOutdated.class); |
28 |
|
29 |
public Test09CommitOutdated(String testName) { |
30 |
super(testName);
|
31 |
} |
32 |
|
33 |
@Override
|
34 |
protected void setUp() throws Exception { |
35 |
super.setUp();
|
36 |
new DefaultLibrariesInitializer().fullInitialize();
|
37 |
} |
38 |
|
39 |
@Override
|
40 |
protected void tearDown() throws Exception { |
41 |
super.tearDown();
|
42 |
} |
43 |
|
44 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
45 |
// public void testHello() {}
|
46 |
|
47 |
public void testCommitOutdated() throws Exception { |
48 |
JDBCServerExplorer server = TestUtils.openServerExplorer("srv-commitoutdated");
|
49 |
File ws1file = TestUtils.getFile(FileUtils.getFile("test-dbs","ws1-commitoutdated")); |
50 |
File ws2file = TestUtils.getFile(FileUtils.getFile("test-dbs","ws2-commitoutdated")); |
51 |
|
52 |
|
53 |
VCSGisManager manager = VCSGisLocator.getVCSGisManager(); |
54 |
manager.setCodeGenerator(new SequentialCodeGenerator());
|
55 |
|
56 |
int r;
|
57 |
Feature f; |
58 |
EditableFeature ef; |
59 |
List<Feature> features;
|
60 |
FeatureStore store1; |
61 |
FeatureStore store2; |
62 |
|
63 |
// ------------------------------------------------------------
|
64 |
// Inicializamos el repositorio y lo abrimos
|
65 |
r = manager.initRepository(server.getParameters(), null);
|
66 |
assertEquals("init_server status", ERR_NO_ERROR, r);
|
67 |
|
68 |
VCSGisRepository repo = manager.openRepository(server.getParameters()); |
69 |
TestUtils.h2sql_repository(repo); |
70 |
|
71 |
// ------------------------------------------------------------
|
72 |
// Creamos workspace1 y lo abrimos.
|
73 |
r = manager.initWorkspace(ws1file, repo, "Test update1",null); |
74 |
assertEquals("init_ws1 status", ERR_NO_ERROR, r);
|
75 |
|
76 |
VCSGisWorkspace ws1 = manager.openWorkspace(ws1file); |
77 |
TestUtils.h2sql_workspace(ws1); |
78 |
|
79 |
// ------------------------------------------------------------
|
80 |
// Adicionamos al workspace1 la tabla "test" y la commitamos.
|
81 |
FeatureStore sourceTest = TestUtils.openSourceStore2(); |
82 |
r = ws1.add("test", sourceTest, "text"); |
83 |
assertEquals("ws1.add status", ERR_NO_ERROR, r);
|
84 |
r = ws1.commit(); |
85 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
|
86 |
DisposeUtils.disposeQuietly(sourceTest); |
87 |
|
88 |
|
89 |
// ------------------------------------------------------------
|
90 |
// Inicializamos el workspace2 asociandolo al mismo repositorio que
|
91 |
// workspace1 y lo abrimos.
|
92 |
r = manager.initWorkspace(ws2file, repo, "Test update2",null); |
93 |
assertEquals("init_ws2 status", ERR_NO_ERROR, r);
|
94 |
VCSGisWorkspace ws2 = manager.openWorkspace(ws2file); |
95 |
TestUtils.h2sql_workspace(ws2); |
96 |
|
97 |
// ------------------------------------------------------------
|
98 |
// Hacemos un checkout en workspace2 de la tabla "test" y comprobamos
|
99 |
// que tiene lo que toca.
|
100 |
r = ws2.checkout("test");
|
101 |
assertEquals("ws2-checkout status", ERR_NO_ERROR, r);
|
102 |
|
103 |
store2 = ws2.getFeatureStore("test");
|
104 |
assertEquals("ws2-checkout sizes", 3, store2.size64()); |
105 |
features = store2.getFeatures((Expression)null, "id", true); |
106 |
|
107 |
assertEquals(1 , features.get(0).getInt("id")); |
108 |
assertEquals("AAA", features.get(0).getString("text")); |
109 |
assertEquals(2 , features.get(1).getInt("id")); |
110 |
assertEquals("BBB", features.get(1).getString("text")); |
111 |
assertEquals(3 , features.get(2).getInt("id")); |
112 |
assertEquals("CCC", features.get(2).getString("text")); |
113 |
|
114 |
DisposeUtils.disposeQuietly(store2); |
115 |
|
116 |
// ------------------------------------------------------------
|
117 |
// Modificamos la tabla "test" en el workspace1 y la commitamos.
|
118 |
store1 = ws1.getFeatureStore("test");
|
119 |
store1.edit(); |
120 |
f = store1.findFirst("id=2");
|
121 |
ef = f.getEditable(); |
122 |
ef.set("text", "BB2"); |
123 |
store1.update(ef); |
124 |
|
125 |
ef = store1.createNewFeature(); |
126 |
ef.set("id",4); |
127 |
ef.set("text","DDD"); |
128 |
store1.insert(ef); |
129 |
store1.finishEditing(); |
130 |
DisposeUtils.disposeQuietly(store1); |
131 |
r = ws1.commit(); |
132 |
assertEquals("ws1.commit-2 status", ERR_NO_ERROR, r);
|
133 |
|
134 |
|
135 |
// ------------------------------------------------------------
|
136 |
// Modificamos la tabla "test" en el workspace2 y la commitamos.
|
137 |
// Debe fallar ya que hay cambios pendientes de actualizar desde el
|
138 |
// repositorio.
|
139 |
store2 = ws2.getFeatureStore("test");
|
140 |
store2.edit(); |
141 |
ef = store2.createNewFeature(); |
142 |
ef.set("id",5); |
143 |
ef.set("text","EEE"); |
144 |
store2.insert(ef); |
145 |
|
146 |
f = store2.findFirst("id=3");
|
147 |
store2.delete(f); |
148 |
store2.finishEditing(); |
149 |
DisposeUtils.disposeQuietly(store2); |
150 |
r = ws2.commit(); |
151 |
assertEquals("ws2.commit-1 status", ERR_CANT_COMMIT_WORKSPACE_OUTDATED, r);
|
152 |
|
153 |
DisposeUtils.disposeQuietly(store2); |
154 |
|
155 |
|
156 |
} |
157 |
} |