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 / server / TestS02Commit.java @ 2710
History | View | Annotate | Download (4.28 KB)
1 |
package org.gvsig.vcsgis.lib.impl.server; |
---|---|
2 |
|
3 |
import java.io.ByteArrayInputStream; |
4 |
import java.io.ByteArrayOutputStream; |
5 |
import java.io.File; |
6 |
import java.io.InputStream; |
7 |
import java.net.URL; |
8 |
import java.util.Map; |
9 |
import junit.framework.TestCase; |
10 |
import static junit.framework.TestCase.assertEquals; |
11 |
import org.apache.commons.io.FileUtils; |
12 |
import org.apache.commons.io.FilenameUtils; |
13 |
import org.apache.commons.io.IOUtils; |
14 |
import org.apache.commons.lang3.StringUtils; |
15 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
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 org.gvsig.vcsgis.lib.VCSGisLocator; |
20 |
import org.gvsig.vcsgis.lib.VCSGisManager; |
21 |
import static org.gvsig.vcsgis.lib.VCSGisManager.ERR_NO_ERROR; |
22 |
import org.gvsig.vcsgis.lib.impl.TestUtils; |
23 |
import org.gvsig.vcsgis.lib.repository.VCSGisRepository; |
24 |
import org.gvsig.vcsgis.lib.repository.remoteclient.requests.CommitRequestClient; |
25 |
import org.gvsig.vcsgis.lib.server.handlers.CommitHandler; |
26 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace; |
27 |
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspaceImpl; |
28 |
import org.slf4j.Logger; |
29 |
import org.slf4j.LoggerFactory; |
30 |
import static org.gvsig.vcsgis.lib.impl.TestUtils.match; |
31 |
|
32 |
|
33 |
public class TestS02Commit extends TestCase { |
34 |
|
35 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestS02Commit.class); |
36 |
|
37 |
public TestS02Commit(String testName) { |
38 |
super(testName);
|
39 |
} |
40 |
|
41 |
@Override
|
42 |
protected void setUp() throws Exception { |
43 |
super.setUp();
|
44 |
new DefaultLibrariesInitializer().fullInitialize();
|
45 |
} |
46 |
|
47 |
@Override
|
48 |
protected void tearDown() throws Exception { |
49 |
super.tearDown();
|
50 |
} |
51 |
|
52 |
// TODO add test methods here. The name must begin with 'test'. For example:
|
53 |
// public void testHello() {}
|
54 |
|
55 |
public void testCommit() throws Exception { |
56 |
final String testid = "ServerCommit"; |
57 |
final URL serverUrl = new URL("http://localhost:9810/"); |
58 |
|
59 |
VCSGisManager manager = VCSGisLocator.getVCSGisManager(); |
60 |
JDBCServerExplorer server = TestUtils.openServerExplorer("srv-"+testid);
|
61 |
File ws1file = TestUtils.getFile(FileUtils.getFile("test-dbs","ws-"+testid)); |
62 |
|
63 |
int r = manager.initRepository(server, null); |
64 |
assertEquals("initRepository status", ERR_NO_ERROR, r);
|
65 |
|
66 |
VCSGisRepository repo = manager.openRepository(server); |
67 |
TestUtils.h2sql_repository(repo); |
68 |
|
69 |
// -------------------------
|
70 |
// Prepare the data in workspace
|
71 |
r = manager.initWorkspace(ws1file, repo, "Test "+testid, null); |
72 |
assertEquals("initWorkspace status", ERR_NO_ERROR, r);
|
73 |
|
74 |
VCSGisWorkspace ws1 = manager.openWorkspace(ws1file); |
75 |
assertNotNull("openWorkspace status", ws1);
|
76 |
TestUtils.h2sql_workspace(ws1); |
77 |
|
78 |
FeatureStore store2 = TestUtils.openSourceStore2(); |
79 |
ws1.add("test", store2, "text"); |
80 |
assertEquals("ws1.add status", ERR_NO_ERROR, r);
|
81 |
|
82 |
DisposeUtils.disposeQuietly(store2); |
83 |
|
84 |
Map<String, String> expected = TestUtils.getExpecteds("S02Commit.txt"); |
85 |
|
86 |
VCSGisRepository client = manager.openRepository(serverUrl); |
87 |
CommitRequestClient request = (CommitRequestClient) client.createCommitRequest(); |
88 |
((VCSGisWorkspaceImpl)ws1).prepareCommitRequest(request, null, null, null); |
89 |
|
90 |
ByteArrayOutputStream request_stream = new ByteArrayOutputStream(1024); |
91 |
LOGGER.debug("===: "+testid+"/produce request"); |
92 |
request.requestDataProducer(request_stream); |
93 |
LOGGER.debug("===: "+testid+"/request built"); |
94 |
String request_s = request_stream.toString().trim();
|
95 |
assertTrue("request data", match(expected.get("request"), request_s)); |
96 |
|
97 |
ByteArrayInputStream is = new ByteArrayInputStream(request_stream.toByteArray()); |
98 |
LOGGER.debug("===: "+testid+"/handle request"); |
99 |
CommitHandler handler = new CommitHandler(repo);
|
100 |
InputStream response_stream = handler.handle(is);
|
101 |
|
102 |
LOGGER.debug("===: "+testid+"/Transform response to string"); |
103 |
String response_s = StringUtils.join(IOUtils.readLines(response_stream),'\n').trim(); |
104 |
assertTrue("response data", match(expected.get("response"), response_s)); |
105 |
|
106 |
|
107 |
} |
108 |
} |