Revision 7819
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.90/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.server/buildNumber.properties | ||
---|---|---|
1 |
#Wed Feb 08 09:09:55 CET 2023 |
|
2 |
buildNumber=100 |
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.90/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.server/src/test/java/org/gvsig/vcsgis/app/server/TestServerUtils.java | ||
---|---|---|
1 |
package org.gvsig.vcsgis.app.server; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.OutputStreamWriter; |
|
5 |
import java.net.URL; |
|
6 |
import org.apache.commons.io.FileUtils; |
|
7 |
import org.eclipse.jetty.server.Server; |
|
8 |
import org.gvsig.fmap.dal.DataStore; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
10 |
import static org.gvsig.vcsgis.app.server.VCSGisJettyServerUtils.SERVER_PORT; |
|
11 |
import org.gvsig.vcsgis.lib.impl.AbstractTestUtils; |
|
12 |
import org.gvsig.vcsgis.lib.server.VCSGisServerUtils; |
|
13 |
import org.slf4j.Logger; |
|
14 |
import org.slf4j.LoggerFactory; |
|
15 |
|
|
16 |
public class TestServerUtils { |
|
17 |
|
|
18 |
public static final Logger LOGGER = LoggerFactory.getLogger(TestServerUtils.class); |
|
19 |
|
|
20 |
public static final String PROVIDER_NAME = DataStore.H2SPATIAL_PROVIDER_NAME; |
|
21 |
|
|
22 |
static Server createServer(AbstractTestUtils utils, JDBCServerExplorerParameters explorerParams) throws Exception { |
|
23 |
URL config_url = TestServerUtils.class.getResource("/server/vcsgisserver.config"); |
|
24 |
OutputStreamWriter consoleWriter = new OutputStreamWriter(System.out); |
|
25 |
VCSGisServerUtils.setConsoleWriter(consoleWriter); |
|
26 |
VCSGisServerUtils.setConfiguration(config_url); |
|
27 |
VCSGisServerUtils.setConnectionParameters(explorerParams); |
|
28 |
VCSGisServerUtils.writeConfiguration(config_url); |
|
29 |
|
|
30 |
File rootFolder = utils().getFile(new File("static")); |
|
31 |
Server server = VCSGisJettyServerUtils.createServer(SERVER_PORT, null, rootFolder.getAbsolutePath()); |
|
32 |
return server; |
|
33 |
} |
|
34 |
|
|
35 |
private static class LocalTestUtilsH2Spatial extends org.gvsig.vcsgis.lib.impl.h2spatial.TestUtilsH2Spatial { |
|
36 |
// Esto fuerza a que el class loader de esta clase esta en este proyecto. |
|
37 |
} |
|
38 |
|
|
39 |
private static LocalTestUtilsH2Spatial utils = null; |
|
40 |
|
|
41 |
public static AbstractTestUtils utils() { |
|
42 |
if( utils==null ) { |
|
43 |
utils = new LocalTestUtilsH2Spatial(); |
|
44 |
} |
|
45 |
return utils; |
|
46 |
} |
|
47 |
} |
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.90/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.server/src/test/java/org/gvsig/vcsgis/app/server/TestSrv01AddCommit.java | ||
---|---|---|
1 |
package org.gvsig.vcsgis.app.server; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.Locale; |
|
6 |
import junit.framework.TestCase; |
|
7 |
import static junit.framework.TestCase.assertEquals; |
|
8 |
import org.apache.commons.io.FileUtils; |
|
9 |
import org.eclipse.jetty.server.Server; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
11 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
12 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
13 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
14 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.createServer; |
|
15 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.utils; |
|
16 |
import static org.gvsig.vcsgis.app.server.VCSGisJettyServerUtils.SERVER_PORT; |
|
17 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
|
18 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
|
19 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
|
20 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
|
21 |
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldbImpl; |
|
22 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.DataRepoTable; |
|
23 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
|
24 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
|
25 |
import org.slf4j.Logger; |
|
26 |
import org.slf4j.LoggerFactory; |
|
27 |
|
|
28 |
public class TestSrv01AddCommit extends TestCase { |
|
29 |
|
|
30 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestSrv01AddCommit.class); |
|
31 |
|
|
32 |
static{ |
|
33 |
Locale.setDefault(Locale.forLanguageTag("es-ES")); |
|
34 |
} |
|
35 |
|
|
36 |
public TestSrv01AddCommit(String testName) { |
|
37 |
super(testName); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
protected void setUp() throws Exception { |
|
42 |
super.setUp(); |
|
43 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
protected void tearDown() throws Exception { |
|
48 |
super.tearDown(); |
|
49 |
} |
|
50 |
|
|
51 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
52 |
// public void testHello() {} |
|
53 |
public void testAddCommit() throws Exception { |
|
54 |
final String testid = "ServerAddCommit"; |
|
55 |
final URL serverUrl = new URL("http://localhost:" + SERVER_PORT + "/"); |
|
56 |
|
|
57 |
VCSGisManager vcsgismanager = VCSGisLocator.getVCSGisManager(); |
|
58 |
JDBCServerExplorerParameters explorerParams = utils().getRepositoryServerExplorerParameters("srv-" + testid); |
|
59 |
File wsfile = utils().getFile(FileUtils.getFile("test-dbs", "ws-" + testid)); |
|
60 |
|
|
61 |
// --------------------------------------------------------- |
|
62 |
// Creamos el server y obtenemos el repositorio del server |
|
63 |
int r = vcsgismanager.initRepository(explorerParams, null); |
|
64 |
assertEquals("srv-init status", 0, r); |
|
65 |
|
|
66 |
Server server = createServer(utils(),explorerParams); |
|
67 |
VCSGisWorkspaceEntity lentity = null; |
|
68 |
long expectedRows = -1; |
|
69 |
try { |
|
70 |
server.start(); |
|
71 |
|
|
72 |
VCSGisRepository repositoryRemote = vcsgismanager.openRepository(serverUrl); |
|
73 |
|
|
74 |
// --------------------------------------------------------- |
|
75 |
// Creamos un workspace y preparamos los datos en el para hacer un commit |
|
76 |
r = vcsgismanager.initWorkspace(wsfile, repositoryRemote, "Test add and commit", null); |
|
77 |
assertEquals("ws-init status", 0, r); |
|
78 |
|
|
79 |
VCSGisWorkspace ws = vcsgismanager.openWorkspace(wsfile); |
|
80 |
utils().info_workspace(ws); |
|
81 |
|
|
82 |
FeatureStore sourceStore = utils().openSourceStore1(); |
|
83 |
expectedRows = sourceStore.getFeatureCount(); |
|
84 |
|
|
85 |
r = ws.add("sourceStore1", sourceStore, "id"); |
|
86 |
assertEquals("ws-add status", 0, r); |
|
87 |
|
|
88 |
DisposeUtils.disposeQuietly(sourceStore); |
|
89 |
|
|
90 |
r = ws.commit(); |
|
91 |
assertEquals("ws-commit status", 0, r); |
|
92 |
|
|
93 |
lentity = ws.getWorkspaceEntity("sourceStore1"); |
|
94 |
} finally { |
|
95 |
server.stop(); |
|
96 |
} |
|
97 |
// --------------------------------------------------------- |
|
98 |
// Comprobamos que la tabla adicionada al espacio ed trabajo contiene |
|
99 |
// los mismos registros que la original. |
|
100 |
|
|
101 |
VCSGisRepositoryLocaldbImpl repositoryLocal = (VCSGisRepositoryLocaldbImpl) vcsgismanager.openRepository(explorerParams); |
|
102 |
VCSGisEntity rentity = repositoryLocal.getEntityByName("sourceStore1"); |
|
103 |
|
|
104 |
assertEquals("Check revision codes 1", lentity.getLocalRevisionCode(), rentity.getRepositoryRevisionCode()); |
|
105 |
assertEquals("Check revision codes 2", lentity.getRepositoryRevisionCode(), rentity.getRepositoryRevisionCode()); |
|
106 |
|
|
107 |
FeatureStore dataStore = repositoryLocal.getFeatureStore(DataRepoTable.TABLE_NAME, true); |
|
108 |
assertEquals("DataStore", expectedRows, dataStore.size64()); |
|
109 |
|
|
110 |
DisposeUtils.disposeQuietly(dataStore); |
|
111 |
|
|
112 |
repositoryLocal.dispose(); |
|
113 |
} |
|
114 |
} |
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.90/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.server/src/test/java/org/gvsig/vcsgis/app/server/TestSrv06Authenticate.java | ||
---|---|---|
1 |
package org.gvsig.vcsgis.app.server; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Locale; |
|
7 |
import junit.framework.TestCase; |
|
8 |
import static junit.framework.TestCase.assertEquals; |
|
9 |
import org.apache.commons.io.FileUtils; |
|
10 |
import org.eclipse.jetty.server.Server; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
12 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
13 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
14 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
15 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.createServer; |
|
16 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.utils; |
|
17 |
import static org.gvsig.vcsgis.app.server.VCSGisJettyServerUtils.SERVER_PORT; |
|
18 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
|
19 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
|
20 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
|
21 |
import org.gvsig.vcsgis.lib.VCSGisUserIdentificationRequester; |
|
22 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
|
23 |
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldbImpl; |
|
24 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.ConfigRepoTable; |
|
25 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.UsersRepoTable; |
|
26 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
|
27 |
import org.slf4j.Logger; |
|
28 |
import org.slf4j.LoggerFactory; |
|
29 |
|
|
30 |
public class TestSrv06Authenticate extends TestCase { |
|
31 |
|
|
32 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestSrv06Authenticate.class); |
|
33 |
|
|
34 |
static{ |
|
35 |
Locale.setDefault(Locale.forLanguageTag("es-ES")); |
|
36 |
} |
|
37 |
|
|
38 |
public TestSrv06Authenticate(String testName) { |
|
39 |
super(testName); |
|
40 |
} |
|
41 |
|
|
42 |
@Override |
|
43 |
protected void setUp() throws Exception { |
|
44 |
super.setUp(); |
|
45 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
protected void tearDown() throws Exception { |
|
50 |
super.tearDown(); |
|
51 |
} |
|
52 |
|
|
53 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
54 |
// public void testHello() {} |
|
55 |
public void testAuthenticatedCommit() throws Exception { |
|
56 |
final String testid = "ServerAddCommit"; |
|
57 |
final URL serverUrl = new URL("http://localhost:" + SERVER_PORT + "/"); |
|
58 |
|
|
59 |
VCSGisManager vcsgismanager = VCSGisLocator.getVCSGisManager(); |
|
60 |
JDBCServerExplorerParameters explorerParams = utils().getRepositoryServerExplorerParameters("srv-" + testid); |
|
61 |
File wsfile = utils().getFile(FileUtils.getFile("test-dbs", "ws-" + testid)); |
|
62 |
|
|
63 |
// --------------------------------------------------------- |
|
64 |
// Creamos el server y obtenemos el repositorio del server |
|
65 |
int r = vcsgismanager.initRepository(explorerParams, null); |
|
66 |
assertEquals("srv-init status", 0, r); |
|
67 |
|
|
68 |
VCSGisRepositoryLocaldbImpl repositoryLocal = (VCSGisRepositoryLocaldbImpl) vcsgismanager.openRepository(explorerParams); |
|
69 |
enableAuthentication(repositoryLocal); |
|
70 |
repositoryLocal.dispose(); |
|
71 |
|
|
72 |
Server server = createServer(utils(),explorerParams); |
|
73 |
try { |
|
74 |
server.start(); |
|
75 |
|
|
76 |
VCSGisRepository repositoryRemote = vcsgismanager.openRepository(serverUrl); |
|
77 |
|
|
78 |
// --------------------------------------------------------- |
|
79 |
// Creamos un workspace y preparamos los datos en el para hacer un commit |
|
80 |
r = vcsgismanager.initWorkspace(wsfile, repositoryRemote, "Test add and commit", null); |
|
81 |
assertEquals("ws-init status", 0, r); |
|
82 |
|
|
83 |
VCSGisWorkspace ws = vcsgismanager.openWorkspace(wsfile); |
|
84 |
utils().info_workspace(ws); |
|
85 |
|
|
86 |
ws.setUserIdentificationRequester(new VCSGisUserIdentificationRequester() { |
|
87 |
int retries = 0; |
|
88 |
|
|
89 |
@Override |
|
90 |
public boolean requestIdentification() { |
|
91 |
if (retries++ > 5) { |
|
92 |
return false; |
|
93 |
} |
|
94 |
return true; |
|
95 |
} |
|
96 |
|
|
97 |
@Override |
|
98 |
public String getUserId() { |
|
99 |
return "test"; |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public String getPassword() { |
|
104 |
return "password"; |
|
105 |
} |
|
106 |
}); |
|
107 |
|
|
108 |
FeatureStore sourceStore = utils().openSourceStore1(); |
|
109 |
long expectedRows = sourceStore.getFeatureCount(); |
|
110 |
|
|
111 |
r = ws.add("sourceStore1", sourceStore, "ID"); |
|
112 |
assertEquals("ws-add status", 0, r); |
|
113 |
|
|
114 |
DisposeUtils.disposeQuietly(sourceStore); |
|
115 |
|
|
116 |
r = ws.commit(); |
|
117 |
assertEquals("ws-commit status", 0, r); |
|
118 |
|
|
119 |
// --------------------------------------------------------- |
|
120 |
// Comprobamos que en el server esta la tabla que acabamos de adicionar |
|
121 |
ws.updateEntitiesFromRepository(null); |
|
122 |
List<VCSGisEntity> rentities = ws.getRepositoryEntities(); |
|
123 |
assertEquals("Num entities in server", 1, rentities.size()); |
|
124 |
assertEquals("Name of the entity in server", "sourceStore1", rentities.get(0).getEntityName()); |
|
125 |
} finally { |
|
126 |
|
|
127 |
server.stop(); |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
private void enableAuthentication(VCSGisRepositoryLocaldbImpl repo) { |
|
132 |
ConfigRepoTable varsTable = new ConfigRepoTable(); |
|
133 |
varsTable.set(repo, "AUTHENTICATION", String.valueOf(true)); |
|
134 |
|
|
135 |
UsersRepoTable.UserRepoRow userRow = new UsersRepoTable.UserRepoRow(repo); |
|
136 |
userRow.setIdentifier("test"); |
|
137 |
userRow.setPassword("password"); |
|
138 |
userRow.insert(); |
|
139 |
|
|
140 |
} |
|
141 |
|
|
142 |
} |
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.90/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.server/src/test/java/org/gvsig/vcsgis/app/server/TestSrv14UpdateWithConflict.java | ||
---|---|---|
1 |
package org.gvsig.vcsgis.app.server; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Locale; |
|
7 |
import junit.framework.TestCase; |
|
8 |
import static junit.framework.TestCase.assertEquals; |
|
9 |
import org.apache.commons.io.FileUtils; |
|
10 |
import org.eclipse.jetty.server.Server; |
|
11 |
import org.gvsig.expressionevaluator.Expression; |
|
12 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
13 |
import org.gvsig.fmap.dal.feature.Feature; |
|
14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
15 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
16 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
17 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
18 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.createServer; |
|
19 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.utils; |
|
20 |
import static org.gvsig.vcsgis.app.server.VCSGisJettyServerUtils.SERVER_PORT; |
|
21 |
import org.gvsig.vcsgis.lib.SequentialCodeGenerator; |
|
22 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
|
23 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
|
24 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR; |
|
25 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_UPDATE_NEED_MERGE; |
|
26 |
import static org.gvsig.vcsgis.lib.VCSGisManager.OP_DELETE; |
|
27 |
import static org.gvsig.vcsgis.lib.VCSGisManager.OP_INSERT; |
|
28 |
import static org.gvsig.vcsgis.lib.VCSGisManager.STATE_CONFLICT; |
|
29 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
|
30 |
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldbImpl; |
|
31 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
|
32 |
import org.gvsig.vcsgis.lib.workspace.tables.RemoteChangesTable; |
|
33 |
import org.gvsig.vcsgis.lib.workspace.tables.WorkspaceChangesTable; |
|
34 |
import org.slf4j.Logger; |
|
35 |
import org.slf4j.LoggerFactory; |
|
36 |
|
|
37 |
public class TestSrv14UpdateWithConflict extends TestCase { |
|
38 |
|
|
39 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestSrv14UpdateWithConflict.class); |
|
40 |
private Server server; |
|
41 |
|
|
42 |
static{ |
|
43 |
Locale.setDefault(Locale.forLanguageTag("es-ES")); |
|
44 |
} |
|
45 |
|
|
46 |
public TestSrv14UpdateWithConflict(String testName) { |
|
47 |
super(testName); |
|
48 |
} |
|
49 |
|
|
50 |
@Override |
|
51 |
protected void setUp() throws Exception { |
|
52 |
super.setUp(); |
|
53 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
protected void tearDown() throws Exception { |
|
58 |
super.tearDown(); |
|
59 |
} |
|
60 |
|
|
61 |
private VCSGisWorkspace[] initTest() throws Exception { |
|
62 |
|
|
63 |
final String testid = "ServerUpdateWithConflict"; |
|
64 |
final URL serverUrl = new URL("http://localhost:" + SERVER_PORT + "/"); |
|
65 |
|
|
66 |
VCSGisManager vcsgismanager = VCSGisLocator.getVCSGisManager(); |
|
67 |
// JDBCServerExplorer server = TestUtils.openServerExplorer("srv-update"); |
|
68 |
SequentialCodeGenerator.reset(); |
|
69 |
|
|
70 |
JDBCServerExplorerParameters explorerParams = utils().getRepositoryServerExplorerParameters("srv-" + testid); |
|
71 |
File wsfile = utils().getFile(FileUtils.getFile("test-dbs", "ws-" + testid)); |
|
72 |
|
|
73 |
// --------------------------------------------------------- |
|
74 |
// Creamos el server y obtenemos el repositorio del server |
|
75 |
int r = vcsgismanager.initRepository(explorerParams, null); |
|
76 |
assertEquals("srv-init status", 0, r); |
|
77 |
|
|
78 |
VCSGisRepositoryLocaldbImpl repositoryLocal = (VCSGisRepositoryLocaldbImpl) vcsgismanager.openRepository(explorerParams); |
|
79 |
|
|
80 |
repositoryLocal.setAllowAssignTheRevisionDate(true); |
|
81 |
|
|
82 |
utils().info_repository(repositoryLocal); |
|
83 |
|
|
84 |
repositoryLocal.dispose(); |
|
85 |
|
|
86 |
server = createServer(utils(), explorerParams); |
|
87 |
|
|
88 |
server.start(); |
|
89 |
|
|
90 |
VCSGisRepository repo = vcsgismanager.openRepository(serverUrl); |
|
91 |
|
|
92 |
File ws1file = utils().getFile(FileUtils.getFile("test-dbs", "ws1-update")); |
|
93 |
File ws2file = utils().getFile(FileUtils.getFile("test-dbs", "ws2-update")); |
|
94 |
File ws3file = utils().getFile(FileUtils.getFile("test-dbs", "ws3-update")); |
|
95 |
|
|
96 |
vcsgismanager.setCodeGenerator(new SequentialCodeGenerator()); |
|
97 |
|
|
98 |
List<Feature> features; |
|
99 |
FeatureStore store2; |
|
100 |
FeatureStore store3; |
|
101 |
|
|
102 |
// ------------------------------------------------------------ |
|
103 |
// Creamos workspace1 y lo abrimos. |
|
104 |
r = vcsgismanager.initWorkspace(ws1file, repo, "Test update1", null); |
|
105 |
assertEquals("init_ws1 status", ERR_NO_ERROR, r); |
|
106 |
|
|
107 |
VCSGisWorkspace ws1 = vcsgismanager.openWorkspace(ws1file); |
|
108 |
utils().info_workspace(ws1); |
|
109 |
|
|
110 |
// ------------------------------------------------------------ |
|
111 |
// Adicionamos al workspace1 la tabla "test" y la commitamos. |
|
112 |
//REV 0 |
|
113 |
FeatureStore sourceTest = utils().openSourceStore2(); |
|
114 |
r = ws1.add("test", sourceTest, "text"); |
|
115 |
DisposeUtils.disposeQuietly(sourceTest); |
|
116 |
assertEquals("ws1.add status", ERR_NO_ERROR, r); |
|
117 |
|
|
118 |
r = ws1.commit(); |
|
119 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r); |
|
120 |
|
|
121 |
// ------------------------------------------------------------ |
|
122 |
// Inicializamos el workspace2 asociandolo al mismo repositorio que |
|
123 |
// workspace1 y lo abrimos. |
|
124 |
r = vcsgismanager.initWorkspace(ws2file, repo, "Test update2", null); |
|
125 |
assertEquals("init_ws2 status", ERR_NO_ERROR, r); |
|
126 |
VCSGisWorkspace ws2 = vcsgismanager.openWorkspace(ws2file); |
|
127 |
utils().info_workspace(ws2); |
|
128 |
|
|
129 |
// ------------------------------------------------------------ |
|
130 |
// Actualizamos (update) la tabla "test" en el workspace2 |
|
131 |
// y comprobamos que tiene lo que toca. |
|
132 |
r = ws2.checkout("test"); |
|
133 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
134 |
|
|
135 |
store2 = ws2.openFeatureStore("test",false); |
|
136 |
assertEquals("ws2-upfate sizes", 3, store2.size64()); |
|
137 |
features = store2.getFeatures((Expression) null, "id", true); |
|
138 |
|
|
139 |
utils().test_check(features, 0, 1, "AAA"); |
|
140 |
utils().test_check(features, 1, 2, "BBB"); |
|
141 |
utils().test_check(features, 2, 3, "CCC"); |
|
142 |
|
|
143 |
DisposeUtils.disposeQuietly(features); |
|
144 |
DisposeUtils.disposeQuietly(store2); |
|
145 |
|
|
146 |
// ------------------------------------------------------------ |
|
147 |
// Inicializamos el workspace3 asociandolo al mismo repositorio que |
|
148 |
// workspace1 y lo abrimos. |
|
149 |
r = vcsgismanager.initWorkspace(ws3file, repo, "Test update2", null); |
|
150 |
assertEquals("init_ws2 status", ERR_NO_ERROR, r); |
|
151 |
VCSGisWorkspace ws3 = vcsgismanager.openWorkspace(ws3file); |
|
152 |
utils().info_workspace(ws3); |
|
153 |
|
|
154 |
// ------------------------------------------------------------ |
|
155 |
// Actualizamos (update) la tabla "test" en el workspace3 |
|
156 |
// y comprobamos que tiene lo que toca. |
|
157 |
r = ws3.checkout("test"); |
|
158 |
assertEquals("ws3.update-1 status", ERR_NO_ERROR, r); |
|
159 |
|
|
160 |
store3 = ws3.openFeatureStore("test",false); |
|
161 |
assertEquals("ws3-upfate sizes", 3, store3.size64()); |
|
162 |
features = store3.getFeatures((Expression) null, "id", true); |
|
163 |
|
|
164 |
utils().test_check(features, 0, 1, "AAA"); |
|
165 |
utils().test_check(features, 1, 2, "BBB"); |
|
166 |
utils().test_check(features, 2, 3, "CCC"); |
|
167 |
|
|
168 |
DisposeUtils.disposeQuietly(features); |
|
169 |
DisposeUtils.disposeQuietly(store2); |
|
170 |
DisposeUtils.disposeQuietly(store3); |
|
171 |
|
|
172 |
return new VCSGisWorkspace[]{ws1, ws2, ws3}; |
|
173 |
} |
|
174 |
|
|
175 |
public void testTwoUpdatesAndMerge() throws Exception { |
|
176 |
|
|
177 |
try { |
|
178 |
VCSGisWorkspace[] wss = initTest(); |
|
179 |
VCSGisWorkspace ws1 = wss[0]; |
|
180 |
VCSGisWorkspace ws2 = wss[1]; |
|
181 |
|
|
182 |
int r; |
|
183 |
Feature f; |
|
184 |
EditableFeature ef; |
|
185 |
FeatureStore store1; |
|
186 |
FeatureStore store2; |
|
187 |
|
|
188 |
// Añadimos al workspace1 una feature con una id concreta y la commitamos |
|
189 |
store1 = ws1.openFeatureStore("test",false); |
|
190 |
store1.edit(); |
|
191 |
utils().test_update(store1, 3, "CC1"); |
|
192 |
|
|
193 |
store1.finishEditing(); |
|
194 |
DisposeUtils.disposeQuietly(store1); |
|
195 |
|
|
196 |
r = ws1.commit(); |
|
197 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r); |
|
198 |
|
|
199 |
// Añadimos al workspace2 una feature con la misma id |
|
200 |
store2 = ws2.openFeatureStore("test",false); |
|
201 |
store2.edit(); |
|
202 |
utils().test_update(store2, 3, "CC2"); |
|
203 |
|
|
204 |
store2.finishEditing(); |
|
205 |
DisposeUtils.disposeQuietly(store2); |
|
206 |
|
|
207 |
// ------------------------------------------------------------ |
|
208 |
// Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 |
|
209 |
// comprobamos que funciona y que tiene lo que toca. |
|
210 |
r = ws2.updatePrepare("test"); |
|
211 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
212 |
|
|
213 |
// assertTrue(false); |
|
214 |
// Actualizamos (update) la tabla "test" en el workspace2 |
|
215 |
// comprobamos que falla |
|
216 |
r = ws2.update("test"); |
|
217 |
assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r); |
|
218 |
|
|
219 |
// Actualizamos (merge) la tabla "test" en el workspace2 |
|
220 |
// comprobamos que no falla |
|
221 |
r = ws2.merge("test"); |
|
222 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
223 |
|
|
224 |
//Comprobar que en la tabla de cambios locales hay 1 elemento |
|
225 |
FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME); |
|
226 |
assertEquals("ws2-changes size", 1, changes.size64()); |
|
227 |
DisposeUtils.disposeQuietly(changes); |
|
228 |
} finally { |
|
229 |
server.stop(); |
|
230 |
} |
|
231 |
|
|
232 |
} |
|
233 |
|
|
234 |
public void testTwoUpdatesMergeAndUpdate() throws Exception { |
|
235 |
try { |
|
236 |
VCSGisWorkspace[] wss = initTest(); |
|
237 |
VCSGisWorkspace ws1 = wss[0]; |
|
238 |
VCSGisWorkspace ws2 = wss[1]; |
|
239 |
VCSGisWorkspace ws3 = wss[2]; |
|
240 |
|
|
241 |
int r; |
|
242 |
Feature f; |
|
243 |
EditableFeature ef; |
|
244 |
FeatureStore store1; |
|
245 |
FeatureStore store2; |
|
246 |
FeatureStore store3; |
|
247 |
|
|
248 |
// Editamos en el workspace1 una feature con una id concreta y la commitamos |
|
249 |
store1 = ws1.openFeatureStore("test",false); |
|
250 |
store1.edit(); |
|
251 |
utils().test_update(store1, 3, "CC1"); |
|
252 |
|
|
253 |
store1.finishEditing(); |
|
254 |
DisposeUtils.disposeQuietly(store1); |
|
255 |
|
|
256 |
r = ws1.commit(); |
|
257 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r); |
|
258 |
|
|
259 |
// Editamos en el workspace2 la feature con la misma id |
|
260 |
store2 = ws2.openFeatureStore("test",false); |
|
261 |
store2.edit(); |
|
262 |
utils().test_update(store2, 3, "CC2"); |
|
263 |
|
|
264 |
store2.finishEditing(); |
|
265 |
DisposeUtils.disposeQuietly(store2); |
|
266 |
|
|
267 |
// ------------------------------------------------------------ |
|
268 |
// Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 |
|
269 |
// comprobamos que funciona y que tiene lo que toca. |
|
270 |
r = ws2.updatePrepare("test"); |
|
271 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
272 |
|
|
273 |
// assertTrue(false); |
|
274 |
// Actualizamos (update) la tabla "test" en el workspace2 |
|
275 |
// comprobamos que falla |
|
276 |
r = ws2.update("test"); |
|
277 |
assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r); |
|
278 |
|
|
279 |
// Actualizamos (merge) la tabla "test" en el workspace2 |
|
280 |
// comprobamos que no falla |
|
281 |
r = ws2.merge("test"); |
|
282 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
283 |
|
|
284 |
//Comprobar que en la tabla de cambios locales hay 1 elemento |
|
285 |
FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME); |
|
286 |
assertEquals("ws2-changes size", 1, changes.size64()); |
|
287 |
DisposeUtils.disposeQuietly(changes); |
|
288 |
|
|
289 |
// Commitamos el workspace2 |
|
290 |
r = ws2.commit(); |
|
291 |
assertEquals("ws2.commit-1 status", ERR_NO_ERROR, r); |
|
292 |
|
|
293 |
// ------------------------------------------------------------ |
|
294 |
// Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace3 |
|
295 |
// comprobamos que funciona y que tiene lo que toca. |
|
296 |
r = ws3.updatePrepare("test"); |
|
297 |
assertEquals("ws3.update-1 status", ERR_NO_ERROR, r); |
|
298 |
|
|
299 |
//Comprobar que en la tabla de cambios remotos hay 1 elemento |
|
300 |
FeatureStore remoteChanges = ws3.getFeatureStore(RemoteChangesTable.TABLE_NAME); |
|
301 |
assertEquals("ws3-remoteChanges size", 1, remoteChanges.size64()); |
|
302 |
DisposeUtils.disposeQuietly(remoteChanges); |
|
303 |
|
|
304 |
// Actualizamos (update) la tabla "test" en el workspace3 |
|
305 |
// comprobamos que no falla |
|
306 |
r = ws3.update("test"); |
|
307 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
308 |
|
|
309 |
store3 = ws3.openFeatureStore("test",false); |
|
310 |
assertEquals("ws3-update sizes", 3, store3.size64()); |
|
311 |
List<Feature> features = store3.getFeatures((Expression) null, "id", true); |
|
312 |
|
|
313 |
utils().test_check(features, 0, 1, "AAA"); |
|
314 |
utils().test_check(features, 1, 2, "BBB"); |
|
315 |
utils().test_check(features, 2, 3, "CC2"); |
|
316 |
|
|
317 |
DisposeUtils.disposeQuietly(store3); |
|
318 |
} finally { |
|
319 |
server.stop(); |
|
320 |
} |
|
321 |
|
|
322 |
} |
|
323 |
|
|
324 |
public void testTwoUpdatesAndUpdate() throws Exception { |
|
325 |
try { |
|
326 |
|
|
327 |
VCSGisWorkspace[] wss = initTest(); |
|
328 |
VCSGisWorkspace ws1 = wss[0]; |
|
329 |
VCSGisWorkspace ws2 = wss[1]; |
|
330 |
|
|
331 |
int r; |
|
332 |
Feature f; |
|
333 |
EditableFeature ef; |
|
334 |
FeatureStore store1; |
|
335 |
FeatureStore store2; |
|
336 |
|
|
337 |
// Añadimos al workspace1 una feature con una id concreta y la commitamos |
|
338 |
store1 = ws1.openFeatureStore("test",false); |
|
339 |
store1.edit(); |
|
340 |
utils().test_update(store1, 3, "CC1"); |
|
341 |
|
|
342 |
store1.finishEditing(); |
|
343 |
DisposeUtils.disposeQuietly(store1); |
|
344 |
|
|
345 |
r = ws1.commit(); |
|
346 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r); |
|
347 |
|
|
348 |
// Añadimos al workspace2 una feature con la misma id |
|
349 |
store2 = ws2.openFeatureStore("test",false); |
|
350 |
store2.edit(); |
|
351 |
utils().test_update(store2, 3, "CC2"); |
|
352 |
|
|
353 |
store2.finishEditing(); |
|
354 |
DisposeUtils.disposeQuietly(store2); |
|
355 |
|
|
356 |
// ------------------------------------------------------------ |
|
357 |
// Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 |
|
358 |
// comprobamos que funciona y que tiene lo que toca. |
|
359 |
r = ws2.updatePrepare("test"); |
|
360 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
361 |
|
|
362 |
// Actualizamos (update) la tabla "test" en el workspace2 |
|
363 |
// comprobamos que falla |
|
364 |
r = ws2.update("test"); |
|
365 |
assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r); |
|
366 |
|
|
367 |
//Seleccionar el cambio conflictivo id=4 |
|
368 |
utils().test_selectRemoteChange(ws2, true, 3, "CC1", ws1); |
|
369 |
|
|
370 |
// Actualizamos (merge) la tabla "test" en el workspace2 |
|
371 |
// comprobamos que no falla |
|
372 |
r = ws2.update("test"); |
|
373 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
374 |
|
|
375 |
//Comprobar que en la tabla de cambios locales no hay nada |
|
376 |
FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME); |
|
377 |
assertEquals("ws2-changes size", 0, changes.size64()); |
|
378 |
DisposeUtils.disposeQuietly(changes); |
|
379 |
|
|
380 |
} finally { |
|
381 |
server.stop(); |
|
382 |
} |
|
383 |
|
|
384 |
} |
|
385 |
|
|
386 |
public void testTwoInsertsAndUpdate() throws Exception { |
|
387 |
try { |
|
388 |
|
|
389 |
VCSGisWorkspace[] wss = initTest(); |
|
390 |
VCSGisWorkspace ws1 = wss[0]; |
|
391 |
VCSGisWorkspace ws2 = wss[1]; |
|
392 |
|
|
393 |
int r; |
|
394 |
Feature f; |
|
395 |
EditableFeature ef; |
|
396 |
List<Feature> features; |
|
397 |
FeatureStore store1; |
|
398 |
FeatureStore store2; |
|
399 |
|
|
400 |
// Añadimos al workspace1 una feature con una id concreta y la commitamos |
|
401 |
store1 = ws1.openFeatureStore("test",false); |
|
402 |
store1.edit(); |
|
403 |
utils().test_insert(store1, 4, "DD1"); |
|
404 |
|
|
405 |
store1.finishEditing(); |
|
406 |
DisposeUtils.disposeQuietly(store1); |
|
407 |
|
|
408 |
r = ws1.commit(); |
|
409 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r); |
|
410 |
|
|
411 |
// Añadimos al workspace2 una feature con la misma id |
|
412 |
store2 = ws2.openFeatureStore("test",false); |
|
413 |
store2.edit(); |
|
414 |
utils().test_insert(store2, 4, "DD2"); |
|
415 |
|
|
416 |
store2.finishEditing(); |
|
417 |
DisposeUtils.disposeQuietly(store2); |
|
418 |
|
|
419 |
// ------------------------------------------------------------ |
|
420 |
// Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 |
|
421 |
// comprobamos que funciona y que tiene lo que toca. |
|
422 |
r = ws2.updatePrepare("test"); |
|
423 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
424 |
|
|
425 |
FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME); |
|
426 |
// See in console debug message with |
|
427 |
// "===: UPDATE_PREPARE: conflicts. { "id":4, ..." |
|
428 |
// and use here the value of the field VCSGISCODE |
|
429 |
utils().test_checkLocalChange(store2, changes, "00000000000036abcdef0123456789", OP_INSERT, 4, "DD2", STATE_CONFLICT); |
|
430 |
DisposeUtils.disposeQuietly(changes); |
|
431 |
|
|
432 |
// Actualizamos (update) la tabla "test" en el workspace2 |
|
433 |
// comprobamos que no falla |
|
434 |
r = ws2.update("test"); |
|
435 |
assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r); |
|
436 |
|
|
437 |
//Seleccionar el cambio conflictivo id=4 |
|
438 |
utils().test_selectRemoteChange(ws2, true, 4, "DD1", ws1); |
|
439 |
|
|
440 |
//update y comprobar que funciona y se ha borrado la feature conflictiva nuestra |
|
441 |
r = ws2.update("test"); |
|
442 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
443 |
|
|
444 |
store2 = ws2.openFeatureStore("test",false); |
|
445 |
assertEquals("ws2-upfate sizes", 4, store2.size64()); |
|
446 |
features = store2.getFeatures((Expression) null, "id", true); |
|
447 |
|
|
448 |
utils().test_check(features, 0, 1, "AAA"); |
|
449 |
utils().test_check(features, 1, 2, "BBB"); |
|
450 |
utils().test_check(features, 2, 3, "CCC"); |
|
451 |
utils().test_check(features, 3, 4, "DD1"); |
|
452 |
|
|
453 |
//Comprobar que en la tabla de cambios locales no hay nada |
|
454 |
changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME); |
|
455 |
assertEquals("ws2-changes size", 0, changes.size64()); |
|
456 |
DisposeUtils.disposeQuietly(changes); |
|
457 |
} finally { |
|
458 |
server.stop(); |
|
459 |
} |
|
460 |
|
|
461 |
} |
|
462 |
|
|
463 |
public void testTwoInsertsAndMerge() throws Exception { |
|
464 |
try { |
|
465 |
|
|
466 |
VCSGisWorkspace[] wss = initTest(); |
|
467 |
VCSGisWorkspace ws1 = wss[0]; |
|
468 |
VCSGisWorkspace ws2 = wss[1]; |
|
469 |
|
|
470 |
int r; |
|
471 |
Feature f; |
|
472 |
EditableFeature ef; |
|
473 |
List<Feature> features; |
|
474 |
FeatureStore store1; |
|
475 |
FeatureStore store2; |
|
476 |
|
|
477 |
//Insertamos dos registros nuevos y repetirlo todo sin seleccionar cambio conflictivo y hacer un merge y que funcione |
|
478 |
// Añadimos al workspace1 una feature con una id concreta y la commitamos |
|
479 |
store1 = ws1.openFeatureStore("test",false); |
|
480 |
store1.edit(); |
|
481 |
utils().test_insert(store1, 4, "DD1"); |
|
482 |
|
|
483 |
store1.finishEditing(); |
|
484 |
DisposeUtils.disposeQuietly(store1); |
|
485 |
|
|
486 |
r = ws1.commit(); |
|
487 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r); |
|
488 |
|
|
489 |
// Añadimos al workspace2 una feature con la misma id |
|
490 |
store2 = ws2.openFeatureStore("test",false); |
|
491 |
store2.edit(); |
|
492 |
utils().test_insert(store2, 4, "DD2"); |
|
493 |
|
|
494 |
store2.finishEditing(); |
|
495 |
DisposeUtils.disposeQuietly(store2); |
|
496 |
|
|
497 |
// ------------------------------------------------------------ |
|
498 |
// Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 |
|
499 |
// comprobamos que funciona y que tiene lo que toca. |
|
500 |
r = ws2.updatePrepare("test"); |
|
501 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
502 |
|
|
503 |
// Actualizamos (update) la tabla "test" en el workspace2 |
|
504 |
// comprobamos que falla |
|
505 |
r = ws2.update("test"); |
|
506 |
assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r); |
|
507 |
|
|
508 |
//merge y comprobar que funciona y no se insertado el cambio conflictivo |
|
509 |
r = ws2.merge("test"); |
|
510 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
511 |
|
|
512 |
store2 = ws2.openFeatureStore("test",false); |
|
513 |
assertEquals("ws2-upfate sizes", 4, store2.size64()); |
|
514 |
features = store2.getFeatures((Expression) null, "id", true); |
|
515 |
|
|
516 |
utils().test_check(features, 0, 1, "AAA"); |
|
517 |
utils().test_check(features, 1, 2, "BBB"); |
|
518 |
utils().test_check(features, 2, 3, "CCC"); |
|
519 |
utils().test_check(features, 3, 4, "DD2"); |
|
520 |
|
|
521 |
//Comprobamos que se ha añadido a la tabla de cambios local el delete del cambio conflictivo |
|
522 |
FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME); |
|
523 |
assertEquals("ws2-changes size", 2, changes.size64()); |
|
524 |
|
|
525 |
// See in console debug message with |
|
526 |
// "===: UPDATE: add delete operation to RelatedFeatureCode ..." |
|
527 |
// and use here the value RelatedFeatureCode |
|
528 |
utils().test_checkLocalChange(store2, changes, "00000000000028abcdef0123456789", OP_DELETE, 4, "DD1", -1); |
|
529 |
|
|
530 |
// See in console debug message with |
|
531 |
// "===: UPDATE_PREPARE: conflicts. { "id":4, "text":"DD2"" |
|
532 |
// and use here the value of the field VCSGISCODE |
|
533 |
utils().test_checkLocalChange(store2, changes, "00000000000036abcdef0123456789", OP_INSERT, 4, "DD2", -1); |
|
534 |
DisposeUtils.disposeQuietly(changes); |
|
535 |
} finally { |
|
536 |
server.stop(); |
|
537 |
} |
|
538 |
|
|
539 |
} |
|
540 |
|
|
541 |
public void testOneCommitAndUpdateOverDeleted() throws Exception { |
|
542 |
try { |
|
543 |
|
|
544 |
VCSGisWorkspace[] wss = initTest(); |
|
545 |
VCSGisWorkspace ws1 = wss[0]; |
|
546 |
VCSGisWorkspace ws2 = wss[1]; |
|
547 |
List<Feature> features; |
|
548 |
|
|
549 |
int r; |
|
550 |
Feature f; |
|
551 |
EditableFeature ef; |
|
552 |
FeatureStore store1; |
|
553 |
FeatureStore store2; |
|
554 |
|
|
555 |
// Modificamos en workspace1 una feature con una id concreta y la commitamos |
|
556 |
store1 = ws1.openFeatureStore("test",false); |
|
557 |
store1.edit(); |
|
558 |
utils().test_update(store1, 3, "CC1"); |
|
559 |
|
|
560 |
store1.finishEditing(); |
|
561 |
DisposeUtils.disposeQuietly(store1); |
|
562 |
|
|
563 |
r = ws1.commit(); |
|
564 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r); |
|
565 |
|
|
566 |
// Borramos en el workspace2 la feature con la misma id |
|
567 |
store2 = ws2.openFeatureStore("test",false); |
|
568 |
store2.edit(); |
|
569 |
utils().test_delete(store2, 3, "CCC"); |
|
570 |
|
|
571 |
store2.finishEditing(); |
|
572 |
DisposeUtils.disposeQuietly(store2); |
|
573 |
|
|
574 |
// ------------------------------------------------------------ |
|
575 |
// Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 |
|
576 |
// comprobamos que funciona y que tiene lo que toca. |
|
577 |
r = ws2.updatePrepare("test"); |
|
578 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
579 |
|
|
580 |
// assertTrue(false); |
|
581 |
// Actualizamos (update) la tabla "test" en el workspace2 |
|
582 |
// comprobamos que falla |
|
583 |
r = ws2.update("test"); |
|
584 |
assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r); |
|
585 |
|
|
586 |
// // Actualizamos (merge) la tabla "test" en el workspace2 |
|
587 |
// // comprobamos que no falla |
|
588 |
// r = ws2.merge("test"); |
|
589 |
// assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
590 |
//Seleccionar el cambio conflictivo id=4 |
|
591 |
utils().test_selectRemoteChange(ws2, true, 3, "CC1", ws1); |
|
592 |
|
|
593 |
//update y comprobar que funciona y no se ha insertado la feature conflictiva |
|
594 |
r = ws2.update("test"); |
|
595 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
596 |
|
|
597 |
store2 = ws2.openFeatureStore("test",false); |
|
598 |
assertEquals("ws2-update sizes", 3, store2.size64()); |
|
599 |
features = store2.getFeatures((Expression) null, "id", true); |
|
600 |
|
|
601 |
utils().test_check(features, 0, 1, "AAA"); |
|
602 |
utils().test_check(features, 1, 2, "BBB"); |
|
603 |
utils().test_check(features, 2, 3, "CC1"); |
|
604 |
|
|
605 |
//Comprobar que en la tabla de cambios locales no hay nada |
|
606 |
FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME); |
|
607 |
assertEquals("ws2-changes size", 0, changes.size64()); |
|
608 |
DisposeUtils.disposeQuietly(changes); |
|
609 |
} finally { |
|
610 |
server.stop(); |
|
611 |
} |
|
612 |
|
|
613 |
} |
|
614 |
|
|
615 |
public void testOneCommitAndMergeOverDeleted() throws Exception { |
|
616 |
try { |
|
617 |
|
|
618 |
VCSGisWorkspace[] wss = initTest(); |
|
619 |
VCSGisWorkspace ws1 = wss[0]; |
|
620 |
VCSGisWorkspace ws2 = wss[1]; |
|
621 |
List<Feature> features; |
|
622 |
|
|
623 |
int r; |
|
624 |
Feature f; |
|
625 |
EditableFeature ef; |
|
626 |
FeatureStore store1; |
|
627 |
FeatureStore store2; |
|
628 |
|
|
629 |
// Modificamos en workspace1 una feature con una id concreta y la commitamos |
|
630 |
store1 = ws1.openFeatureStore("test",false); |
|
631 |
store1.edit(); |
|
632 |
utils().test_update(store1, 3, "CC1"); |
|
633 |
|
|
634 |
store1.finishEditing(); |
|
635 |
DisposeUtils.disposeQuietly(store1); |
|
636 |
|
|
637 |
r = ws1.commit(); |
|
638 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r); |
|
639 |
|
|
640 |
// Borramos en el workspace2 la feature con la misma id |
|
641 |
store2 = ws2.openFeatureStore("test",false); |
|
642 |
store2.edit(); |
|
643 |
utils().test_delete(store2, 3, "CCC"); |
|
644 |
|
|
645 |
store2.finishEditing(); |
|
646 |
DisposeUtils.disposeQuietly(store2); |
|
647 |
|
|
648 |
// ------------------------------------------------------------ |
|
649 |
// Preparamos la actualización de (updatePrepare) la tabla "test" en el workspace2 |
|
650 |
// comprobamos que funciona y que tiene lo que toca. |
|
651 |
r = ws2.updatePrepare("test"); |
|
652 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
653 |
|
|
654 |
// assertTrue(false); |
|
655 |
// Actualizamos (update) la tabla "test" en el workspace2 |
|
656 |
// comprobamos que falla |
|
657 |
// r = ws2.update("test"); |
|
658 |
// assertEquals("ws2.update-1 status", ERR_UPDATE_NEED_MERGE, r); |
|
659 |
// Actualizamos (merge) la tabla "test" en el workspace2 |
|
660 |
// comprobamos que no falla |
|
661 |
r = ws2.merge("test"); |
|
662 |
assertEquals("ws2.update-1 status", ERR_NO_ERROR, r); |
|
663 |
|
|
664 |
//Comprobamos que en workspace2 hay lo que toca |
|
665 |
store2 = ws2.openFeatureStore("test",false); |
|
666 |
assertEquals("ws2-update sizes", 2, store2.size64()); |
|
667 |
features = store2.getFeatures((Expression) null, "id", true); |
|
668 |
|
|
669 |
utils().test_check(features, 0, 1, "AAA"); |
|
670 |
utils().test_check(features, 1, 2, "BBB"); |
|
671 |
// check(features, 2, 3, "CC1"); |
|
672 |
|
|
673 |
//Comprobar que en la tabla de cambios locales permanece el cambio |
|
674 |
FeatureStore changes = ws2.getFeatureStore(WorkspaceChangesTable.TABLE_NAME); |
|
675 |
assertEquals("ws2-changes size", 1, changes.size64()); |
|
676 |
DisposeUtils.disposeQuietly(changes); |
|
677 |
} finally { |
|
678 |
server.stop(); |
|
679 |
} |
|
680 |
|
|
681 |
} |
|
682 |
|
|
683 |
} |
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.90/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.server/src/test/java/org/gvsig/vcsgis/app/server/TestSrv02Entities.java | ||
---|---|---|
1 |
package org.gvsig.vcsgis.app.server; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Locale; |
|
7 |
import junit.framework.TestCase; |
|
8 |
import static junit.framework.TestCase.assertEquals; |
|
9 |
import org.apache.commons.io.FileUtils; |
|
10 |
import org.eclipse.jetty.server.Server; |
|
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
12 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
13 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
14 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
15 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.createServer; |
|
16 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.utils; |
|
17 |
import static org.gvsig.vcsgis.app.server.VCSGisJettyServerUtils.SERVER_PORT; |
|
18 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
|
19 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
|
20 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
|
21 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
|
22 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
|
23 |
import org.slf4j.Logger; |
|
24 |
import org.slf4j.LoggerFactory; |
|
25 |
|
|
26 |
public class TestSrv02Entities extends TestCase { |
|
27 |
|
|
28 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestSrv02Entities.class); |
|
29 |
|
|
30 |
static{ |
|
31 |
Locale.setDefault(Locale.forLanguageTag("es-ES")); |
|
32 |
} |
|
33 |
|
|
34 |
public TestSrv02Entities(String testName) { |
|
35 |
super(testName); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
protected void setUp() throws Exception { |
|
40 |
super.setUp(); |
|
41 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected void tearDown() throws Exception { |
|
46 |
super.tearDown(); |
|
47 |
} |
|
48 |
|
|
49 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
50 |
// public void testHello() {} |
|
51 |
public void testEntities() throws Exception { |
|
52 |
final String testid = "ServerAddCommit"; |
|
53 |
final URL serverUrl = new URL("http://localhost:" + SERVER_PORT + "/"); |
|
54 |
|
|
55 |
VCSGisManager vcsgismanager = VCSGisLocator.getVCSGisManager(); |
|
56 |
JDBCServerExplorerParameters explorerParams = utils().getRepositoryServerExplorerParameters("srv-" + testid); |
|
57 |
File wsfile = utils().getFile(FileUtils.getFile("test-dbs", "ws-" + testid)); |
|
58 |
|
|
59 |
// --------------------------------------------------------- |
|
60 |
// Creamos el server y obtenemos el repositorio del server |
|
61 |
int r = vcsgismanager.initRepository(explorerParams, null); |
|
62 |
assertEquals("srv-init status", 0, r); |
|
63 |
|
|
64 |
Server server = createServer(utils(),explorerParams); |
|
65 |
try { |
|
66 |
server.start(); |
|
67 |
|
|
68 |
VCSGisRepository repositoryRemote = vcsgismanager.openRepository(serverUrl); |
|
69 |
|
|
70 |
// --------------------------------------------------------- |
|
71 |
// Creamos un workspace y preparamos los datos en el para hacer un commit |
|
72 |
r = vcsgismanager.initWorkspace(wsfile, repositoryRemote, "Test add and commit", null); |
|
73 |
assertEquals("ws-init status", 0, r); |
|
74 |
|
|
75 |
VCSGisWorkspace ws = vcsgismanager.openWorkspace(wsfile); |
|
76 |
utils().info_workspace(ws); |
|
77 |
|
|
78 |
FeatureStore sourceStore = utils().openSourceStore1(); |
|
79 |
long expectedRows = sourceStore.getFeatureCount(); |
|
80 |
|
|
81 |
r = ws.add("sourceStore1", sourceStore, "ID"); |
|
82 |
assertEquals("ws-add status", 0, r); |
|
83 |
|
|
84 |
DisposeUtils.disposeQuietly(sourceStore); |
|
85 |
|
|
86 |
r = ws.commit(); |
|
87 |
assertEquals("ws-commit status", 0, r); |
|
88 |
|
|
89 |
// --------------------------------------------------------- |
|
90 |
// Comprobamos que en el server esta la tabla que acabamos de adicionar |
|
91 |
ws.updateEntitiesFromRepository(null); |
|
92 |
List<VCSGisEntity> rentities = ws.getRepositoryEntities(); |
|
93 |
assertEquals("Num entities in server", 1, rentities.size()); |
|
94 |
assertEquals("Name of the entity in server", "sourceStore1", rentities.get(0).getEntityName()); |
|
95 |
} finally { |
|
96 |
server.stop(); |
|
97 |
} |
|
98 |
} |
|
99 |
} |
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.90/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.server/src/test/java/org/gvsig/vcsgis/app/server/TestSrv05Update.java | ||
---|---|---|
1 |
package org.gvsig.vcsgis.app.server; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.URL; |
|
5 |
import java.sql.Timestamp; |
|
6 |
import java.util.List; |
|
7 |
import java.util.Locale; |
|
8 |
import junit.framework.TestCase; |
|
9 |
import static junit.framework.TestCase.assertEquals; |
|
10 |
import static junit.framework.TestCase.assertNotNull; |
|
11 |
import org.apache.commons.io.FileUtils; |
|
12 |
import org.eclipse.jetty.server.Server; |
|
13 |
import org.gvsig.expressionevaluator.Expression; |
|
14 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
15 |
import org.gvsig.fmap.dal.feature.Feature; |
|
16 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
17 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
18 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
19 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
20 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.createServer; |
|
21 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.utils; |
|
22 |
import static org.gvsig.vcsgis.app.server.VCSGisJettyServerUtils.SERVER_PORT; |
|
23 |
import org.gvsig.vcsgis.lib.SequentialCodeGenerator; |
|
24 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
|
25 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
|
26 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
|
27 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR; |
|
28 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
|
29 |
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldbImpl; |
|
30 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
|
31 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
|
32 |
import org.slf4j.Logger; |
|
33 |
import org.slf4j.LoggerFactory; |
|
34 |
|
|
35 |
public class TestSrv05Update extends TestCase { |
|
36 |
|
|
37 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestSrv05Update.class); |
|
38 |
|
|
39 |
static{ |
|
40 |
Locale.setDefault(Locale.forLanguageTag("es-ES")); |
|
41 |
} |
|
42 |
|
|
43 |
public TestSrv05Update(String testName) { |
|
44 |
super(testName); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected void setUp() throws Exception { |
|
49 |
super.setUp(); |
|
50 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
protected void tearDown() throws Exception { |
|
55 |
super.tearDown(); |
|
56 |
} |
|
57 |
|
|
58 |
@SuppressWarnings("UnusedAssignment") |
|
59 |
public void testUpdate() throws Exception { |
|
60 |
final String testid = "ServerUpdate"; |
|
61 |
final URL serverUrl = new URL("http://localhost:" + SERVER_PORT + "/"); |
|
62 |
|
|
63 |
SequentialCodeGenerator.reset(); |
|
64 |
|
|
65 |
VCSGisManager vcsgismanager = VCSGisLocator.getVCSGisManager(); |
|
66 |
vcsgismanager.setCodeGenerator(new SequentialCodeGenerator()); |
|
67 |
JDBCServerExplorerParameters explorerParams = utils().getRepositoryServerExplorerParameters("srv-" + testid); |
|
68 |
File ws1file = utils().getFile(FileUtils.getFile("test-dbs", "ws1-" + testid)); |
|
69 |
File ws2file = utils().getFile(FileUtils.getFile("test-dbs", "ws2-" + testid)); |
|
70 |
|
|
71 |
int r; |
|
72 |
Feature f; |
|
73 |
EditableFeature ef; |
|
74 |
List<Feature> features; |
|
75 |
FeatureStore store1; |
|
76 |
FeatureStore store2; |
|
77 |
|
|
78 |
// --------------------------------------------------------- |
|
79 |
// Creamos el server y obtenemos el repositorio del server |
|
80 |
r = vcsgismanager.initRepository(explorerParams, null); |
|
81 |
assertEquals("srv-init status", 0, r); |
|
82 |
|
|
83 |
Server server = createServer(utils(),explorerParams); |
|
84 |
VCSGisWorkspaceEntity lentity = null; |
|
85 |
|
|
86 |
try { |
|
87 |
server.start(); |
|
88 |
|
|
89 |
VCSGisRepository repositoryRemote = vcsgismanager.openRepository(serverUrl); |
|
90 |
|
|
91 |
// ------------------------------------------------------------ |
|
92 |
// Creamos workspace1 y lo abrimos. |
|
93 |
r = vcsgismanager.initWorkspace(ws1file, repositoryRemote, "Test update1", null); |
|
94 |
assertEquals("init_ws1 status", ERR_NO_ERROR, r); |
|
95 |
|
|
96 |
VCSGisWorkspace ws1 = vcsgismanager.openWorkspace(ws1file); |
|
97 |
utils().info_workspace(ws1); |
|
98 |
|
|
99 |
// ------------------------------------------------------------ |
|
100 |
// Adicionamos al workspace1 la tabla "test" y la commitamos. |
|
101 |
FeatureStore sourceTest = utils().openSourceStore2(); |
|
102 |
r = ws1.add("test", sourceTest, "text"); |
|
103 |
assertEquals("ws1.add status", ERR_NO_ERROR, r); |
|
104 |
|
|
105 |
store1 = ws1.openFeatureStore("test",false); |
|
106 |
store1.edit(); |
|
107 |
utils().test_insert(store1, 4, "DDD"); |
|
108 |
utils().test_insert(store1, 5, "EEE"); |
|
109 |
utils().test_insert(store1, 6, "FFF"); |
|
110 |
store1.finishEditing(); |
|
111 |
|
|
112 |
r = ws1.commit(); |
|
113 |
assertEquals("ws1.commit-1 status", ERR_NO_ERROR, r); |
|
114 |
DisposeUtils.disposeQuietly(sourceTest); |
|
115 |
|
|
116 |
// ------------------------------------------------------------ |
|
117 |
// Inicializamos el workspace2 asociandolo al mismo repositorio que |
|
118 |
// workspace1 y lo abrimos. |
|
119 |
r = vcsgismanager.initWorkspace(ws2file, repositoryRemote, "Test update2", null); |
|
120 |
assertEquals("init_ws2 status", ERR_NO_ERROR, r); |
|
121 |
VCSGisWorkspace ws2 = vcsgismanager.openWorkspace(ws2file); |
|
122 |
utils().info_workspace(ws2); |
|
123 |
|
|
124 |
// ------------------------------------------------------------ |
|
125 |
// Hacemos un checkout en workspace2 de la tabla "test" |
|
126 |
// y comprobamos que tiene lo que toca. |
|
127 |
r = ws2.checkout("test"); |
|
128 |
assertEquals("ws2-checkout status", ERR_NO_ERROR, r); |
|
129 |
|
|
130 |
VCSGisEntity entity = ws2.getWorkspaceEntityByName("test"); |
|
131 |
assertNotNull("ws2.update-1 entity", entity); |
|
132 |
assertEquals("ws2.update-1 label", "text", entity.getFieldForLabel()); |
|
133 |
|
|
134 |
store2 = ws2.openFeatureStore("test",false); |
|
135 |
assertEquals("ws2-checkout sizes", 6, store2.size64()); |
|
136 |
features = store2.getFeatures((Expression) null, "id", true); |
|
137 |
|
|
138 |
utils().test_check(features, 0, 1, "AAA"); |
|
139 |
utils().test_check(features, 1, 2, "BBB"); |
|
140 |
utils().test_check(features, 2, 3, "CCC"); |
|
141 |
utils().test_check(features, 3, 4, "DDD"); |
|
142 |
utils().test_check(features, 4, 5, "EEE"); |
|
143 |
utils().test_check(features, 5, 6, "FFF"); |
|
144 |
|
|
145 |
DisposeUtils.disposeQuietly(features); |
|
146 |
DisposeUtils.disposeQuietly(store2); |
|
147 |
|
|
148 |
// ------------------------------------------------------------ |
|
149 |
// Modificamos la tabla "test" en el workspace1 y la commitamos. |
|
150 |
store1 = ws1.openFeatureStore("test",false); |
|
151 |
store1.edit(); |
|
152 |
utils().test_insert(store1, 7, "GGG"); |
|
153 |
utils().test_update(store1, 2, "BB2"); |
|
154 |
utils().test_delete(store1, 3, "CCC"); |
|
155 |
store1.finishEditing(); |
|
156 |
|
|
157 |
DisposeUtils.disposeQuietly(store1); |
|
158 |
r = ws1.commit(Timestamp.valueOf("2020-02-17 10:11:12.123"), "Insertado DDD y modificado BBB a BB2", null); |
|
159 |
assertEquals("ws1.commit-2 status", ERR_NO_ERROR, r); |
|
160 |
|
|
161 |
String localRevisionCode = ws2.getWorkspaceEntity("test").getRepositoryRevisionCode(); |
|
162 |
assertEquals("ws2 localRevisionCode", "00000000000021abcdef0123456789", localRevisionCode); |
|
163 |
|
|
164 |
r = ws2.updatePrepare("test"); |
|
165 |
assertEquals("ws2-updatePrepare status", ERR_NO_ERROR, r); |
|
166 |
|
|
167 |
r = ws2.update("test"); |
|
168 |
assertEquals("ws2-update status", ERR_NO_ERROR, r); |
|
169 |
|
|
170 |
store2 = ws2.openFeatureStore("test",false); |
|
171 |
assertEquals("ws2-checkout sizes", 6, store2.size64()); |
|
172 |
features = store2.getFeatures((Expression) null, "id", true); |
|
173 |
|
|
174 |
utils().test_check(features, 0, 1, "AAA"); |
|
175 |
utils().test_check(features, 1, 2, "BB2"); |
|
176 |
utils().test_check(features, 2, 4, "DDD"); |
|
177 |
utils().test_check(features, 3, 5, "EEE"); |
|
178 |
utils().test_check(features, 4, 6, "FFF"); |
|
179 |
utils().test_check(features, 5, 7, "GGG"); |
|
180 |
|
|
181 |
DisposeUtils.disposeQuietly(features); |
|
182 |
DisposeUtils.disposeQuietly(store2); |
|
183 |
|
|
184 |
lentity = ws2.getWorkspaceEntity("test"); |
|
185 |
|
|
186 |
ws1.dispose(); |
|
187 |
ws2.dispose(); |
|
188 |
ws1 = null; |
|
189 |
ws2 = null; |
|
190 |
|
|
191 |
// --------------------------------------------------------- |
|
192 |
// Comprobamos que la tabla adicionada al espacio ed trabajo contiene |
|
193 |
// los mismos registros que la original. |
|
194 |
} finally { |
|
195 |
server.stop(); |
|
196 |
} |
|
197 |
|
|
198 |
VCSGisRepositoryLocaldbImpl repositoryLocal = (VCSGisRepositoryLocaldbImpl) vcsgismanager.openRepository(explorerParams); |
|
199 |
VCSGisEntity rentity = repositoryLocal.getEntityByName("test"); |
|
200 |
|
|
201 |
assertEquals("Check local revision code", lentity.getLocalRevisionCode(), rentity.getRepositoryRevisionCode()); |
|
202 |
assertEquals("Check repository revision code", lentity.getRepositoryRevisionCode(), rentity.getRepositoryRevisionCode()); |
|
203 |
|
|
204 |
repositoryLocal.dispose(); |
|
205 |
|
|
206 |
} |
|
207 |
} |
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.90/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.server/src/test/java/org/gvsig/vcsgis/app/server/TestSrv03Checkout.java | ||
---|---|---|
1 |
package org.gvsig.vcsgis.app.server; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.URL; |
|
5 |
import java.sql.Timestamp; |
|
6 |
import java.util.Locale; |
|
7 |
import junit.framework.TestCase; |
|
8 |
import static junit.framework.TestCase.assertEquals; |
|
9 |
import org.apache.commons.io.FileUtils; |
|
10 |
import org.eclipse.jetty.server.Server; |
|
11 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
12 |
import org.gvsig.fmap.dal.feature.Feature; |
|
13 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
14 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
|
15 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
16 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
17 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
18 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
19 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.createServer; |
|
20 |
import static org.gvsig.vcsgis.app.server.TestServerUtils.utils; |
|
21 |
import static org.gvsig.vcsgis.app.server.VCSGisJettyServerUtils.SERVER_PORT; |
|
22 |
import org.gvsig.vcsgis.lib.VCSGisEntity; |
|
23 |
import org.gvsig.vcsgis.lib.VCSGisLocator; |
|
24 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
|
25 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_OK; |
|
26 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
|
27 |
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldbImpl; |
|
28 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.DataRepoTable; |
|
29 |
import org.gvsig.vcsgis.lib.repository.localdb.tables.EntitiesRepoTable; |
|
30 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
|
31 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceEntity; |
|
32 |
import org.slf4j.Logger; |
|
33 |
import org.slf4j.LoggerFactory; |
|
34 |
|
|
35 |
public class TestSrv03Checkout extends TestCase { |
|
36 |
|
|
37 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestSrv03Checkout.class); |
|
38 |
|
|
39 |
static{ |
|
40 |
Locale.setDefault(Locale.forLanguageTag("es-ES")); |
|
41 |
} |
|
42 |
|
|
43 |
public TestSrv03Checkout(String testName) { |
|
44 |
super(testName); |
|
45 |
} |
|
46 |
|
|
47 |
@Override |
|
48 |
protected void setUp() throws Exception { |
|
49 |
super.setUp(); |
|
50 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
protected void tearDown() throws Exception { |
|
55 |
super.tearDown(); |
|
56 |
} |
|
57 |
|
|
58 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
59 |
// public void testHello() {} |
|
60 |
public void testCheckout() throws Exception { |
|
61 |
final String testid = "ServerCheckout"; |
|
62 |
final URL serverUrl = new URL("http://localhost:" + SERVER_PORT + "/"); |
|
63 |
|
|
64 |
VCSGisManager vcsgismanager = VCSGisLocator.getVCSGisManager(); |
|
65 |
|
|
66 |
JDBCServerExplorer serverdb = utils().openRepositoryServerExplorer("srv-" + testid); |
|
67 |
|
|
68 |
JDBCServerExplorerParameters explorerParams = serverdb.getParameters(); |
|
69 |
|
|
70 |
// JDBCServerExplorerParameters explorerParams = TestUtils.getServerExplorerParameters("srv-"+testid); |
|
71 |
File ws1file = utils().getFile(FileUtils.getFile("test-dbs", "ws1-" + testid)); |
|
72 |
File ws2file = utils().getFile(FileUtils.getFile("test-dbs", "ws2-" + testid)); |
|
73 |
|
|
74 |
// --------------------------------------------------------- |
|
75 |
// Creamos el server y obtenemos el repositorio del server |
|
76 |
int r = vcsgismanager.initRepository(explorerParams, null); |
|
77 |
assertEquals("srv-init status", 0, r); |
|
78 |
|
|
79 |
Server server = createServer(utils(),explorerParams); |
|
80 |
VCSGisWorkspaceEntity lentity = null; |
|
81 |
long expectedRows = -1; |
|
82 |
try { |
|
83 |
server.start(); |
|
84 |
|
|
85 |
VCSGisRepository repositoryRemote = vcsgismanager.openRepository(serverUrl); |
|
86 |
|
|
87 |
// --------------------------------------------------------- |
|
88 |
// Creamos un workspace y preparamos los datos en el para hacer un commit |
|
89 |
r = vcsgismanager.initWorkspace(ws1file, repositoryRemote, "Test checkout ws1", null); |
|
90 |
assertEquals("ws1-init status", 0, r); |
|
91 |
|
|
92 |
VCSGisWorkspace ws1 = vcsgismanager.openWorkspace(ws1file); |
|
93 |
utils().info_workspace(ws1); |
|
94 |
|
|
95 |
FeatureStore sourceStore = utils().openSourceStore2(); |
|
96 |
expectedRows = sourceStore.getFeatureCount(); |
|
97 |
|
|
98 |
r = ws1.add("test", sourceStore, "text"); |
|
99 |
assertEquals("ws1-add status", 0, r); |
|
100 |
|
|
101 |
r = ws1.commit(Timestamp.valueOf("2020-02-17 10:11:12.123"), testid, null); |
|
102 |
assertEquals("ws1.commit status", ERR_OK, r); |
|
103 |
|
|
104 |
entities_setResources(serverdb, "test", "test_res"); |
|
105 |
|
|
106 |
DisposeUtils.disposeQuietly(sourceStore); |
|
107 |
|
|
108 |
r = vcsgismanager.initWorkspace(ws2file, repositoryRemote, "Test checkout ws2", null); |
|
109 |
assertEquals("ws2-init status", 0, r); |
|
110 |
|
|
111 |
VCSGisWorkspace ws2 = vcsgismanager.openWorkspace(ws2file); |
|
112 |
utils().info_workspace(ws2); |
|
113 |
|
|
114 |
r = ws2.checkout("test"); |
|
115 |
assertEquals("ws1.commit status", ERR_OK, r); |
|
116 |
|
|
117 |
lentity = ws2.getWorkspaceEntity("test"); |
|
118 |
// --------------------------------------------------------- |
|
119 |
// Comprobamos que la tabla adicionada al espacio de trabajo contiene |
|
120 |
// los mismos registros que la original. |
|
121 |
} finally { |
|
122 |
server.stop(); |
|
123 |
} |
|
124 |
|
|
125 |
VCSGisRepositoryLocaldbImpl repositoryLocal = (VCSGisRepositoryLocaldbImpl) vcsgismanager.openRepository(explorerParams); |
|
126 |
VCSGisEntity rentity = repositoryLocal.getEntityByName("test"); |
|
127 |
|
|
128 |
assertEquals("Check revision codes 1", lentity.getLocalRevisionCode(), rentity.getRepositoryRevisionCode()); |
|
129 |
assertEquals("Check revision codes 2", lentity.getRepositoryRevisionCode(), rentity.getRepositoryRevisionCode()); |
|
130 |
assertEquals("Check resources", "test_res", lentity.getResources()); |
|
131 |
|
|
132 |
FeatureStore dataStore = repositoryLocal.getFeatureStore(DataRepoTable.TABLE_NAME, true); |
|
133 |
assertEquals("DataStore", expectedRows, dataStore.size64()); |
|
134 |
|
|
135 |
DisposeUtils.disposeQuietly(dataStore); |
|
136 |
|
|
137 |
repositoryLocal.dispose(); |
|
138 |
} |
|
139 |
|
|
140 |
public static void entities_setResources(JDBCServerExplorer server, String tableName, String resource) throws Exception { |
|
141 |
JDBCStoreParameters entitiesOpenParameters = server.get(EntitiesRepoTable.TABLE_NAME); |
|
142 |
FeatureStore store = (FeatureStore) server.open(entitiesOpenParameters); |
|
143 |
store.edit(); |
|
144 |
Feature f = store.findFirst("\"" + EntitiesRepoTable.ENTITY_NAME + "\" = '" + tableName + "'"); |
|
145 |
EditableFeature ef = f.getEditable(); |
|
146 |
ef.set(EntitiesRepoTable.RESOURCES, resource); |
|
147 |
store.update(ef); |
|
148 |
store.finishEditing(); |
|
149 |
} |
|
150 |
|
|
151 |
} |
org.gvsig.vcsgis/tags/org.gvsig.vcsgis-1.0.90/org.gvsig.vcsgis.app/org.gvsig.vcsgis.app.server/src/test/java/org/gvsig/vcsgis/app/server/TestSrv04Row.java | ||
---|---|---|
1 |
package org.gvsig.vcsgis.app.server; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.net.URL; |
|
5 |
import java.util.Locale; |
|
6 |
import junit.framework.TestCase; |
|
7 |
import org.apache.commons.io.FileUtils; |
|
8 |
import org.eclipse.jetty.server.Server; |
|
9 |
import org.gvsig.fmap.dal.feature.Feature; |
|
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
11 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters; |
Also available in: Unified diff