root / trunk / org.gvsig.postgresql / org.gvsig.postgresql.provider / src / test / java / org / gvsig / postgresql / dal / TestUtils.java @ 576
History | View | Annotate | Download (2.76 KB)
1 |
package org.gvsig.postgresql.dal; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.net.URL; |
5 |
import java.util.ArrayList; |
6 |
import java.util.List; |
7 |
import org.apache.commons.io.FileUtils; |
8 |
import org.apache.commons.lang3.StringUtils; |
9 |
import org.gvsig.fmap.dal.DALLocator; |
10 |
import org.gvsig.fmap.dal.DataManager; |
11 |
import org.gvsig.fmap.dal.DataStore; |
12 |
import org.gvsig.fmap.dal.feature.Feature; |
13 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
14 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
15 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
16 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
17 |
import org.slf4j.Logger; |
18 |
import org.slf4j.LoggerFactory; |
19 |
|
20 |
public class TestUtils { |
21 |
|
22 |
public static final Logger LOGGER = LoggerFactory.getLogger(TestUtils.class); |
23 |
|
24 |
public static final String PROVIDER_NAME = PostgreSQLLibrary.NAME; |
25 |
|
26 |
public static File getTargetFolder() throws Exception { |
27 |
URL url = TestUtils.class.getResource("/"); |
28 |
File x = new File(url.toURI()); |
29 |
File target = x.getParentFile();
|
30 |
return target;
|
31 |
} |
32 |
|
33 |
public static File getResource(String name) throws Exception { |
34 |
File x = new File(getTargetFolder(), name); |
35 |
return x;
|
36 |
} |
37 |
|
38 |
public static File getResourceAsFile(String pathname) throws Exception { |
39 |
URL url = TestUtils.class.getResource(pathname);
|
40 |
File x = new File(url.toURI()); |
41 |
return x;
|
42 |
} |
43 |
|
44 |
public static FeatureStore openSourceStore1() throws Exception { |
45 |
DataManager dataManager = DALLocator.getDataManager(); |
46 |
File f = getResourceAsFile("/org/gvsig/postgresql/dal/testCreateSource1.csv"); |
47 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
48 |
DataStore.CSV_PROVIDER_NAME, |
49 |
"file=",f,
|
50 |
"automaticTypesDetection=", false, |
51 |
"locale=","en" |
52 |
); |
53 |
return store;
|
54 |
} |
55 |
|
56 |
|
57 |
public static List<String> getSQLs(String name) throws Exception { |
58 |
File f = getResourceAsFile("/org/gvsig/postgresql/dal/"+name); |
59 |
List<String> SQLs = new ArrayList<>(); |
60 |
List<String> lines = FileUtils.readLines(f); |
61 |
StringBuilder sb = new StringBuilder(); |
62 |
for (String line : lines) { |
63 |
line = StringUtils.stripStart(line, null);
|
64 |
if( line.startsWith("--") ) { |
65 |
continue;
|
66 |
} |
67 |
if( line.endsWith(";") ) { |
68 |
sb.append(line.substring(0, line.length()-1)); |
69 |
SQLs.add(sb.toString()); |
70 |
sb.setLength(0);
|
71 |
} else {
|
72 |
sb.append(line); |
73 |
} |
74 |
} |
75 |
return SQLs;
|
76 |
} |
77 |
|
78 |
public static JDBCHelper getJDBCHelper() { |
79 |
PostgreSQLHelper helper = new PostgreSQLHelper();
|
80 |
return helper;
|
81 |
} |
82 |
|
83 |
public static FeatureProvider getFeatureProvider(Feature feature) { |
84 |
return ((DefaultFeature)feature).getData();
|
85 |
} |
86 |
} |