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 / Test12Commit.java @ 2742
History | View | Annotate | Download (6.59 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.EditableFeature; |
9 |
import org.gvsig.fmap.dal.feature.Feature; |
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
11 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
12 |
import org.gvsig.tools.dispose.DisposeUtils; |
13 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
14 |
import org.gvsig.tools.util.GetItemWithSize64; |
15 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
16 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
17 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR; |
18 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
19 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
20 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceChange; |
21 |
import org.slf4j.Logger; |
22 |
import org.slf4j.LoggerFactory; |
23 |
|
24 |
public class Test12Commit extends TestCase { |
25 |
|
26 |
private static final Logger LOGGER = LoggerFactory.getLogger(Test12Commit.class); |
27 |
|
28 |
public Test12Commit(String testName) { |
29 |
super(testName);
|
30 |
} |
31 |
|
32 |
@Override
|
33 |
protected void setUp() throws Exception { |
34 |
super.setUp();
|
35 |
new DefaultLibrariesInitializer().fullInitialize();
|
36 |
} |
37 |
|
38 |
@Override
|
39 |
protected void tearDown() throws Exception { |
40 |
super.tearDown();
|
41 |
} |
42 |
|
43 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
44 |
// public void testHello() {}
|
45 |
|
46 |
public void testCommit() throws Exception { |
47 |
VCSGisManager manager = VCSGisLocator.getVCSGisManager(); |
48 |
JDBCServerExplorer server = TestUtils.openServerExplorer("srv-update");
|
49 |
File ws1file = TestUtils.getFile(FileUtils.getFile("test-dbs","ws1-update")); |
50 |
|
51 |
int r;
|
52 |
Feature f; |
53 |
EditableFeature ef; |
54 |
List<Feature> features;
|
55 |
FeatureStore store1; |
56 |
|
57 |
// ------------------------------------------------------------
|
58 |
// Inicializamos el repositorio y lo abrimos
|
59 |
r = manager.initRepository(server.getParameters(), null);
|
60 |
assertEquals("init_server status", ERR_NO_ERROR, r);
|
61 |
|
62 |
VCSGisRepository repo = manager.openRepository(server.getParameters()); |
63 |
TestUtils.h2sql_repository(repo); |
64 |
|
65 |
// ------------------------------------------------------------
|
66 |
// Creamos workspace1 y lo abrimos.
|
67 |
r = manager.initWorkspace(ws1file, repo, "Test update1",null); |
68 |
assertEquals("init_ws1 status", ERR_NO_ERROR, r);
|
69 |
|
70 |
VCSGisWorkspace ws1 = manager.openWorkspace(ws1file); |
71 |
TestUtils.h2sql_workspace(ws1); |
72 |
|
73 |
// ------------------------------------------------------------
|
74 |
// Adicionamos al workspace1 la tabla "test" y la commitamos.
|
75 |
FeatureStore sourceTest = TestUtils.openSourceStore2(); |
76 |
r = ws1.add("test", sourceTest, "ID"); |
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 |
// Modificamos la tabla "test" en el workspace1 y la commitamos.
|
85 |
store1 = ws1.getFeatureStore("test");
|
86 |
store1.edit(); |
87 |
f = store1.findFirst("id=2");
|
88 |
ef = f.getEditable(); |
89 |
ef.set("text", "BB2"); |
90 |
store1.update(ef); |
91 |
|
92 |
f = store1.findFirst("id=2");
|
93 |
ef = f.getEditable(); |
94 |
ef.set("text", "BB3"); |
95 |
store1.update(ef); |
96 |
|
97 |
store1.finishEditing(); |
98 |
DisposeUtils.disposeQuietly(store1); |
99 |
|
100 |
GetItemWithSize64<VCSGisWorkspaceChange> localChanges = ws1.getLocalChangesByEntityName("test");
|
101 |
assertEquals("ws1.localChangesSize", 1, localChanges.size64()); |
102 |
|
103 |
ws1.commit(); |
104 |
assertEquals("ws1.commit-2 status", ERR_NO_ERROR, r);
|
105 |
|
106 |
localChanges = ws1.getLocalChangesByEntityName("test");
|
107 |
assertEquals("ws1.localChangesSize 2", 0, localChanges.size64()); |
108 |
|
109 |
|
110 |
store1 = ws1.getFeatureStore("test");
|
111 |
store1.edit(); |
112 |
f = store1.findFirst("id=2");
|
113 |
ef = f.getEditable(); |
114 |
ef.set("text", "BB4"); |
115 |
store1.update(ef); |
116 |
|
117 |
store1.finishEditing(); |
118 |
store1.edit(); |
119 |
|
120 |
f = store1.findFirst("id=2");
|
121 |
ef = f.getEditable(); |
122 |
ef.set("text", "BB5"); |
123 |
store1.update(ef); |
124 |
|
125 |
store1.finishEditing(); |
126 |
DisposeUtils.disposeQuietly(store1); |
127 |
|
128 |
localChanges = ws1.getLocalChangesByEntityName("test");
|
129 |
assertEquals("ws1.localChangesSize 3", 1, localChanges.size64()); |
130 |
|
131 |
r = ws1.commit(); |
132 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
|
133 |
|
134 |
store1 = ws1.getFeatureStore("test");
|
135 |
store1.edit(FeatureStore.MODE_APPEND); |
136 |
|
137 |
ef = store1.createNewFeature(); |
138 |
ef.set("id",4); |
139 |
ef.set("text","DDD"); |
140 |
store1.insert(ef); |
141 |
|
142 |
ef = store1.createNewFeature(); |
143 |
ef.set("id",5); |
144 |
ef.set("text","EEE"); |
145 |
store1.insert(ef); |
146 |
|
147 |
|
148 |
store1.finishEditing(); |
149 |
DisposeUtils.disposeQuietly(store1); |
150 |
|
151 |
localChanges = ws1.getLocalChangesByEntityName("test");
|
152 |
assertEquals("ws1.localChangesSize 4", 2, localChanges.size64()); |
153 |
|
154 |
r = ws1.commit(); |
155 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
|
156 |
|
157 |
store1 = ws1.getFeatureStore("test");
|
158 |
store1.edit(); |
159 |
|
160 |
ef = store1.createNewFeature(); |
161 |
ef.set("id",6); |
162 |
ef.set("text","FFF"); |
163 |
store1.insert(ef); |
164 |
|
165 |
f = store1.findFirst("id=6");
|
166 |
store1.delete(f); |
167 |
|
168 |
store1.finishEditing(); |
169 |
DisposeUtils.disposeQuietly(store1); |
170 |
|
171 |
localChanges = ws1.getLocalChangesByEntityName("test");
|
172 |
assertEquals("ws1.localChangesSize 4", 0, localChanges.size64()); |
173 |
|
174 |
r = ws1.commit(); |
175 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r);
|
176 |
|
177 |
store1 = ws1.getFeatureStore("test");
|
178 |
store1.edit(); |
179 |
|
180 |
ef = store1.createNewFeature(); |
181 |
ef.set("id",7); |
182 |
ef.set("text","FFF"); |
183 |
store1.insert(ef); |
184 |
|
185 |
f = store1.findFirst("id=7");
|
186 |
ef = f.getEditable(); |
187 |
ef.set("text", "FF2"); |
188 |
store1.update(ef); |
189 |
|
190 |
f = store1.findFirst("id=7");
|
191 |
store1.delete(f); |
192 |
|
193 |
store1.finishEditing(); |
194 |
DisposeUtils.disposeQuietly(store1); |
195 |
|
196 |
localChanges = ws1.getLocalChangesByEntityName("test");
|
197 |
assertEquals("ws1.localChangesSize 4", 0, localChanges.size64()); |
198 |
|
199 |
|
200 |
} |
201 |
} |