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 @ 45775
History | View | Annotate | Download (3.68 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 openStore(String name) throws Exception { |
56 |
DataManager dataManager = DALLocator.getDataManager(); |
57 |
StoresRepository repository = dataManager.getStoresRepository(); |
58 |
FeatureStore store = (FeatureStore) repository.getStore(name); |
59 |
return store;
|
60 |
} |
61 |
|
62 |
public static FeatureStore openSourceCountries() throws Exception { |
63 |
return openStore("countries"); |
64 |
} |
65 |
|
66 |
public static FeatureStore openSourceContinents() throws Exception { |
67 |
return openStore("continents"); |
68 |
} |
69 |
|
70 |
public static void initialiceRepository() throws Exception { |
71 |
DataManager dataManager = DALLocator.getDataManager(); |
72 |
StoresRepository repository = dataManager.getStoresRepository(); |
73 |
repository.add( |
74 |
"continents",
|
75 |
dataManager.createStoreParameters( |
76 |
DataStore.CSV_PROVIDER_NAME, |
77 |
"file=",getResource("/org/gvsig/fmap/dal/store/csv/continents.csv"), |
78 |
"automaticTypesDetection=", false, |
79 |
"delimiter=",",", |
80 |
"locale=","en" |
81 |
) |
82 |
); |
83 |
repository.add( |
84 |
"continents2",
|
85 |
dataManager.createStoreParameters( |
86 |
DataStore.CSV_PROVIDER_NAME, |
87 |
"file=",getResource("/org/gvsig/fmap/dal/store/csv/continents2.csv"), |
88 |
"automaticTypesDetection=", true, |
89 |
"delimiter=",";", |
90 |
"locale=","en" |
91 |
) |
92 |
); |
93 |
repository.add( |
94 |
"countries",
|
95 |
dataManager.createStoreParameters( |
96 |
DataStore.CSV_PROVIDER_NAME, |
97 |
"file=",getResource("/org/gvsig/fmap/dal/store/csv/countries.csv"), |
98 |
"automaticTypesDetection=", false, |
99 |
"delimiter=",",", |
100 |
"locale=","en" |
101 |
) |
102 |
); |
103 |
} |
104 |
} |