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