Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.sqlite / org.gvsig.sqlite.provider / src / test / java / org / gvsig / sqlite / dal / ExistsDBTest.java @ 47539

History | View | Annotate | Download (2.93 KB)

1
package org.gvsig.sqlite.dal;
2

    
3
import java.io.File;
4
import junit.framework.TestCase;
5
import org.apache.commons.io.FileUtils;
6
import org.gvsig.fmap.dal.DALLocator;
7
import org.gvsig.fmap.dal.DataManager;
8
import org.gvsig.fmap.dal.DataStore;
9
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
10
import org.gvsig.fmap.dal.feature.EditableFeatureType;
11
import org.gvsig.fmap.dal.feature.FeatureStore;
12
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
13
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
14
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer;
15
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
16
import org.gvsig.tools.util.HasAFile;
17
import org.slf4j.Logger;
18
import org.slf4j.LoggerFactory;
19

    
20
/**
21
 *
22
 * @author jjdelcerro
23
 */
24
public class ExistsDBTest extends TestCase {
25
    private static final Logger LOGGER = LoggerFactory.getLogger(TestCreate.class);
26

    
27
    public static final String DBNAME = "test_workspace";
28
   
29
    public ExistsDBTest(String testName) {
30
        super(testName);
31
    }
32

    
33
    @Override
34
    protected void setUp() throws Exception {
35
        super.setUp();
36
        new DefaultLibrariesInitializer().fullInitialize();
37
    }
38

    
39
    @Override
40
    protected void tearDown() throws Exception {
41
        super.tearDown();
42
    }
43

    
44
    protected String getProviderName() {
45
        return DataStore.H2SPATIAL_PROVIDER_NAME;
46
    }
47
    
48
    protected String getTargetName() {
49
        return "testCreateTarget1";
50
    }
51
    
52
    protected FeatureStore openTargetStore1(JDBCServerExplorer explorer) throws Exception {
53
        JDBCStoreParameters params = explorer.get(getTargetName());
54
        
55
        DataManager dataManager = DALLocator.getDataManager();
56
        FeatureStore store;
57
        try {
58
            store = (FeatureStore) dataManager.openStore(
59
                    getProviderName(), 
60
                    params
61
            );
62
        } catch(ValidateDataParametersException ex) {
63
            LOGGER.warn(ex.getLocalizedMessageStack());
64
            throw ex;
65
        }
66
        return store;
67
    }
68

    
69
    protected void createFrom(JDBCServerExplorer explorer, FeatureStore sourceStore) throws Exception {
70
        NewFeatureStoreParameters params = (NewFeatureStoreParameters) explorer.getAddParameters(
71
                getTargetName()
72
        );
73
        EditableFeatureType ft = params.getDefaultFeatureType();
74
        ft.addAll(sourceStore.getDefaultFeatureType());
75
        explorer.add(getProviderName(), params, true);
76
    }
77

    
78
    public void testExistDatabase() throws Exception {
79
        FeatureStore sourceStore = TestUtils.openSourceStore1();
80
        JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME);
81
        
82
        assertFalse(explorer.exists());
83
        
84
        File f = ((HasAFile)explorer.getParameters()).getFile();
85
        FileUtils.touch(f);
86
        
87
        assertFalse(explorer.exists());
88

    
89
        createFrom(explorer, sourceStore);        
90
        
91
        assertTrue(explorer.exists());
92
    }
93

    
94
}