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