svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.csv / src / test / java / org / gvsig / fmap / dal / store / csv / TestUtils.java @ 44738
History | View | Annotate | Download (3.39 KB)
1 |
package org.gvsig.fmap.dal.store.csv; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.net.URL; |
5 |
import org.apache.commons.io.FileUtils; |
6 |
import org.apache.commons.io.FilenameUtils; |
7 |
import org.gvsig.fmap.dal.DALLocator; |
8 |
import org.gvsig.fmap.dal.DataManager; |
9 |
import org.gvsig.fmap.dal.DataStore; |
10 |
import org.gvsig.fmap.dal.StoresRepository; |
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
12 |
import org.slf4j.Logger; |
13 |
import org.slf4j.LoggerFactory; |
14 |
|
15 |
public class TestUtils { |
16 |
|
17 |
public static final Logger LOGGER = LoggerFactory.getLogger(TestUtils.class); |
18 |
|
19 |
public static File getTargetFolder() throws Exception { |
20 |
URL url = TestUtils.class.getResource("/"); |
21 |
File x = new File(url.toURI()); |
22 |
File target = x.getParentFile();
|
23 |
return target;
|
24 |
} |
25 |
|
26 |
public static File getResource(String name) throws Exception { |
27 |
File x = FileUtils.getFile(getTargetFolder(), "test-classes", name); |
28 |
return x;
|
29 |
} |
30 |
|
31 |
public static File getResourceAsFile(String pathname) throws Exception { |
32 |
URL url = TestUtils.class.getResource(pathname);
|
33 |
File x = new File(url.toURI()); |
34 |
return x;
|
35 |
} |
36 |
|
37 |
public static void removeDALResource(String fname) throws Exception { |
38 |
File f = getResource(fname);
|
39 |
f = new File(FilenameUtils.removeExtension(f.getAbsolutePath())+".dal"); |
40 |
FileUtils.deleteQuietly(f); |
41 |
} |
42 |
|
43 |
public static FeatureStore openSourceStore1() throws Exception { |
44 |
DataManager dataManager = DALLocator.getDataManager(); |
45 |
File f = getResource("/org/gvsig/fmap/dal/store/csv/testCreateSource1.csv"); |
46 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
47 |
DataStore.CSV_PROVIDER_NAME, |
48 |
"file=",f,
|
49 |
"automaticTypesDetection=", false, |
50 |
"locale=","en" |
51 |
); |
52 |
return store;
|
53 |
} |
54 |
|
55 |
public static FeatureStore openSourceCountries() throws Exception { |
56 |
DataManager dataManager = DALLocator.getDataManager(); |
57 |
StoresRepository repository = dataManager.getStoresRepository(); |
58 |
FeatureStore store = (FeatureStore) repository.getStore("countries");
|
59 |
return store;
|
60 |
} |
61 |
|
62 |
public static FeatureStore openSourceContinents() throws Exception { |
63 |
DataManager dataManager = DALLocator.getDataManager(); |
64 |
StoresRepository repository = dataManager.getStoresRepository(); |
65 |
FeatureStore store = (FeatureStore) repository.getStore("continents");
|
66 |
return store;
|
67 |
} |
68 |
|
69 |
public static void initialiceRepository() throws Exception { |
70 |
DataManager dataManager = DALLocator.getDataManager(); |
71 |
StoresRepository repository = dataManager.getStoresRepository(); |
72 |
repository.add( |
73 |
"continents",
|
74 |
dataManager.createStoreParameters( |
75 |
DataStore.CSV_PROVIDER_NAME, |
76 |
"file=",getResource("/org/gvsig/fmap/dal/store/csv/continents.csv"), |
77 |
"automaticTypesDetection=", false, |
78 |
"delimiter=",",", |
79 |
"locale=","en" |
80 |
) |
81 |
); |
82 |
repository.add( |
83 |
"countries",
|
84 |
dataManager.createStoreParameters( |
85 |
DataStore.CSV_PROVIDER_NAME, |
86 |
"file=",getResource("/org/gvsig/fmap/dal/store/csv/countries.csv"), |
87 |
"automaticTypesDetection=", false, |
88 |
"delimiter=",",", |
89 |
"locale=","en" |
90 |
) |
91 |
); |
92 |
} |
93 |
} |