Statistics
| Revision:

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 / Test06AddCommit.java @ 2701

History | View | Annotate | Download (3.49 KB)

1
package org.gvsig.vcsgis.lib.impl;
2

    
3
import java.io.File;
4
import junit.framework.TestCase;
5
import static junit.framework.TestCase.assertEquals;
6
import org.apache.commons.io.FileUtils;
7
import org.gvsig.fmap.dal.feature.FeatureStore;
8
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
9
import org.gvsig.tools.dispose.DisposeUtils;
10
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
11
import org.gvsig.vcsgis.lib.workspace.tables.WorkspaceChangesTable;
12
import org.gvsig.vcsgis.lib.workspace.VCSGisWorkspace;
13
import org.gvsig.vcsgis.lib.vcsgis;
14
import org.gvsig.vcsgis.lib.repository.VCSGisRepository;
15
import org.gvsig.vcsgis.lib.vcsgisadmin;
16
import org.gvsig.vcsgis.lib.repository.localdb.VCSGisRepositoryLocaldb;
17
import org.gvsig.vcsgis.lib.repository.localdb.tables.DataRepoTable;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

    
21
public class Test06AddCommit extends TestCase {
22

    
23
    private static final Logger LOGGER = LoggerFactory.getLogger(Test06AddCommit.class);
24

    
25
    public Test06AddCommit(String testName) {
26
        super(testName);
27
    }
28

    
29
    @Override
30
    protected void setUp() throws Exception {
31
        super.setUp();
32
        new DefaultLibrariesInitializer().fullInitialize();
33
    }
34

    
35
    @Override
36
    protected void tearDown() throws Exception {
37
        super.tearDown();
38
    }
39

    
40
    // TODO add test methods here. The name must begin with 'test'. For example:
41
    // public void testHello() {}
42
    
43
    public void testAddCommit() throws Exception {
44
        JDBCServerExplorer server = TestUtils.openServerExplorer("srv-addco");
45
        File wsfile = TestUtils.getFile(FileUtils.getFile("test-dbs","ws-addco")); 
46

    
47
        // ---------------------------------------------------------
48
        // Creamos el respositorio y lo abrimos.
49
        int r = vcsgisadmin.init_repository(server);
50
        assertEquals("srv-init status", 0, r);
51

    
52
        VCSGisRepository repo = vcsgisadmin.open_repository(server);
53
        TestUtils.h2sql_repository(repo);
54
        
55
        
56
        // ---------------------------------------------------------
57
        // Creamos un workspace y lo abrimos.
58
        r = vcsgis.init_workspace(wsfile, repo, "Test add and commit");
59
        assertEquals("ws-init status", 0, r);
60
        
61
        VCSGisWorkspace ws = vcsgis.open_workspace(wsfile);
62
        TestUtils.h2sql_workspace(ws);
63
        
64
        // ---------------------------------------------------------
65
        // A?adimos al workspace la tabla de pruebas y lo commitamos
66
        FeatureStore sourceStore = TestUtils.openSourceStore1();
67
        r = ws.add("sourceStore1", sourceStore, "ID");
68
        assertEquals("ws-add status", 0, r);
69
        
70
        r = ws.commit();
71
        assertEquals("ws-commit status", 0, r);
72

    
73
        // ---------------------------------------------------------
74
        // Comprobamos que tras el commit la tabla de cambios esta vacia.
75
        FeatureStore changesStore = ws.getFeatureStore(WorkspaceChangesTable.TABLE_NAME);
76
        assertEquals("Changes", 0, changesStore.size64());
77
        
78
        DisposeUtils.disposeQuietly(changesStore);
79
        
80
        // ---------------------------------------------------------
81
        // Comprobamos que la tabla a?adida al espacio ed trabajo contiene
82
        // los mismos registros que la original.
83
        FeatureStore dataStore = ((VCSGisRepositoryLocaldb)repo).getFeatureStore(DataRepoTable.TABLE_NAME);
84
        assertEquals("DataStore", sourceStore.size64(), dataStore.size64());
85
        
86
        sourceStore.dispose();
87
        DisposeUtils.disposeQuietly(dataStore);
88
    }
89
}