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 @ 47606
History | View | Annotate | Download (3.06 KB)
1 | 47539 | jjdelcerro | 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 | 47606 | fdiaz | try {
|
80 | 47539 | jjdelcerro | FeatureStore sourceStore = TestUtils.openSourceStore1(); |
81 | JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
||
82 | |||
83 | assertFalse(explorer.exists()); |
||
84 | |||
85 | File f = ((HasAFile)explorer.getParameters()).getFile();
|
||
86 | FileUtils.touch(f); |
||
87 | |||
88 | assertFalse(explorer.exists()); |
||
89 | |||
90 | createFrom(explorer, sourceStore); |
||
91 | |||
92 | assertTrue(explorer.exists()); |
||
93 | 47606 | fdiaz | } catch(Throwable th){ |
94 | LOGGER.warn("testExistDatabase:", th);
|
||
95 | throw th;
|
||
96 | } |
||
97 | 47539 | jjdelcerro | } |
98 | |||
99 | } |