Statistics
| Revision:

root / trunk / org.gvsig.postgresql / org.gvsig.postgresql.provider / src / test / java / org / gvsig / postgresql / dal / TestUtilsPostgreSQL.java @ 932

History | View | Annotate | Download (2.82 KB)

1
package org.gvsig.postgresql.dal;
2

    
3
import java.net.URL;
4
import java.util.Properties;
5
import org.gvsig.fmap.dal.DALLocator;
6
import org.gvsig.fmap.dal.DataManager;
7
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils;
8
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
9
import org.gvsig.fmap.dal.store.jdbc2.spi.FakeConnectionProvider;
10

    
11
/**
12
 *
13
 * @author jjdelcerro
14
 */
15
@SuppressWarnings("UseSpecificCatch")
16
public class TestUtilsPostgreSQL extends AbstractTestUtils {
17

    
18
    @Override
19
    public String getProviderName() {
20
        return PostgreSQLLibrary.NAME;
21
    }
22

    
23
    @Override
24
    public String getExpectedsPath() {
25
        return "/org/gvsig/postgresql/dal";
26
    }
27
    
28
    @Override
29
    protected Properties getProperties() {
30
        if (this.properties == null) {
31
            try {
32
                URL url = this.getClass().getResource("postgresql.properties");
33
                Properties props = new Properties();
34
                props.load(url.openStream());
35
                String[] keys = new String[]{
36
                    "PostgreSQLEnabled",
37
                    "PostgreSQLHost",
38
                    "PostgreSQLPort",
39
                    "PostgreSQLDbname",
40
                    "PostgreSQLSchema",
41
                    "PostgreSQLUser",
42
                    "PostgreSQLPassword"
43
                };
44
                for (String key : keys) {
45
                    if (System.getenv().containsKey(key)) {
46
                        props.setProperty(key, System.getenv(key));
47
                    }
48
                }
49
                this.properties = props;
50
            } catch (Exception ex) {
51
                throw new RuntimeException(ex);
52
            } 
53
        }
54
        return this.properties;
55
    }
56

    
57
    @Override
58
    public boolean isTheDatabaseAvailable() {
59
        return this.getPropertyBoolean("PostgreSQLEnabled");
60
    }
61

    
62
    @Override
63
    public JDBCHelper createJDBCHelper() throws Exception {
64
        PostgreSQLServerExplorerParameters params = this.getServerExplorerParameters("fake");
65
        PostgreSQLHelper helper = new PostgreSQLHelper(params, new FakeConnectionProvider());
66
      return helper;
67
    }
68

    
69
    @Override
70
    public PostgreSQLServerExplorerParameters getServerExplorerParameters(String dbname) throws Exception {
71
        DataManager dataManager = DALLocator.getDataManager();
72
        PostgreSQLServerExplorerParameters conn = (PostgreSQLServerExplorerParameters) dataManager.createServerExplorerParameters(this.getProviderName());
73
        conn.setHost(getProperty("PostgreSQLHost"));
74
        conn.setPort(getPropertyInt("PostgreSQLPort", 5432));
75
        conn.setDBName(getProperty("PostgreSQLDbname"));
76
        conn.setSchema(getProperty("PostgreSQLSchema"));
77
        conn.setUser(getProperty("PostgreSQLUser"));
78
        conn.setPassword(getProperty("PostgreSQLPassword"));
79
        conn.setShowInformationDBTables(false);
80
        return conn;
81
    }
82
    
83
}