Revision 1029

View differences:

tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.app/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4

  
5
  <modelVersion>4.0.0</modelVersion>
6
  <artifactId>org.gvsig.postgresql.app</artifactId>
7
  <packaging>pom</packaging>
8
  <name>${project.artifactId}</name>
9
  <parent>
10
      <groupId>org.gvsig</groupId>
11
      <artifactId>org.gvsig.postgresql</artifactId>
12
      <version>2.0.199</version>
13
  </parent>
14

  
15
  <modules>
16
    <module>org.gvsig.postgresql.app.mainplugin</module>
17
    <!--
18
    <module>org.gvsig.postgresql.app.export</module>
19
    -->
20
  </modules>
21

  
22
</project>
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4

  
5
  <modelVersion>4.0.0</modelVersion>
6
  <artifactId>org.gvsig.postgresql.app.mainplugin</artifactId>
7
  <packaging>jar</packaging>
8
  <name>${project.artifactId}</name>
9
  <description>PostgreSQL file format support</description>
10

  
11
  <parent>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.postgresql.app</artifactId>
14
      <version>2.0.199</version>
15
  </parent>
16

  
17
  <dependencies>
18
    <dependency>
19
        <groupId>org.gvsig</groupId>
20
        <artifactId>org.gvsig.tools.lib</artifactId>
21
        <scope>compile</scope>
22
    </dependency>
23
    <dependency>
24
        <groupId>org.gvsig</groupId>
25
        <artifactId>org.gvsig.andami</artifactId>
26
        <scope>compile</scope>
27
    </dependency>
28
    <dependency>
29
        <groupId>org.gvsig</groupId>
30
        <artifactId>org.gvsig.postgresql.provider</artifactId>
31
        <scope>compile</scope>
32
    </dependency>
33
    
34
    <dependency>
35
      <groupId>org.postgresql</groupId>
36
      <artifactId>postgresql</artifactId>
37
      <scope>runtime</scope>
38
    </dependency>
39
    <dependency>
40
      <groupId>org.apache.commons</groupId>
41
      <artifactId>commons-dbcp2</artifactId>
42
      <scope>runtime</scope>
43
    </dependency>    
44
    <dependency>
45
      <groupId>org.apache.commons</groupId>
46
      <artifactId>commons-pool2</artifactId>
47
      <scope>runtime</scope>
48
    </dependency>
49

  
50
  </dependencies>
51
  
52
    <properties>
53
        <!-- Package info property values -->
54
        <!-- Default values in org.gvsig.desktop -->
55
        <gvsig.package.info.name>Formats: PostgreSQL support</gvsig.package.info.name>
56
        <gvsig.package.info.state>testing</gvsig.package.info.state>
57
        <gvsig.package.info.official>true</gvsig.package.info.official>
58
        <gvsig.package.info.dependencies>required: org.gvsig.app.mainplugin -ge 2.0.1</gvsig.package.info.dependencies>
59
        <gvsig.package.info.categories>Formats,Vector,Database</gvsig.package.info.categories>
60
        <gvsig.package.info.poolURL>https://devel.gvsig.org/download/projects/gvsig-postgresql/pool/</gvsig.package.info.poolURL>
61
    </properties>
62
  
63

  
64
</project>
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/buildNumber.properties
1
#Thu Feb 24 22:51:00 CET 2022
2
buildNumber=2257
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
  <libraries library-dir="lib/"/>
4
  <depends plugin-name="org.gvsig.app.mainplugin"/>
5
  <resourceBundle name="text"/>
6
  <extensions>
7
     <extension class-name="org.gvsig.andami.LibraryExtension" active="false"/>
8
  </extensions>    
9
</plugin-config>
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/i18n/text.properties
1
_PostgreSQL_loading_parameters=Par\u00e1metros de carga de PostgreSQL
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/resources-plugin/i18n/text_en.properties
1
_PostgreSQL_loading_parameters=PostgreSQL loading parameters
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.app/org.gvsig.postgresql.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
    <file>
17
      <source>src/main/resources-plugin/config.xml</source>
18
    </file>
19
  </files>
20

  
21
  <dependencySets>
22
  
23
    <dependencySet>
24
      <useProjectArtifact>false</useProjectArtifact>
25
      <useTransitiveDependencies>false</useTransitiveDependencies>
26
      <outputDirectory>lib</outputDirectory>
27
      <includes>
28
        <include>org.gvsig:org.gvsig.postgresql.provider</include>
29
      </includes>
30
    </dependencySet>
31
    
32
    <dependencySet>
33
      <useProjectArtifact>false</useProjectArtifact>
34
      <useTransitiveDependencies>false</useTransitiveDependencies>
35
      <outputDirectory>lib</outputDirectory>
36
      <includes>
37
		<include>org.postgresql:postgresql</include>
38
		<include>org.apache.commons:commons-dbcp2</include>
39
		<include>org.apache.commons:commons-pool2</include>
40
      </includes>
41
    </dependencySet>
42
    
43
  </dependencySets>
44

  
45
</assembly>
46

  
47

  
48

  
49

  
0 50

  
tags/org.gvsig.postgresql-2.0.199/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4

  
5
  <modelVersion>4.0.0</modelVersion>
6
  <artifactId>org.gvsig.postgresql</artifactId>
7
  <version>2.0.199</version>
8
  <packaging>pom</packaging>
9
  <name>${project.artifactId}</name>
10
  <description>PostgreSQL support fort DAL and gvSIG</description>
11
  <parent>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.desktop</artifactId>
14
      <version>2.0.362</version>
15
  </parent>
16

  
17
  <url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql</url>
18
  <scm>
19
      <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.199</connection>
20
      <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-postgresql/tags/org.gvsig.postgresql-2.0.199</developerConnection>
21
      <url>https://devel.gvsig.org/redmine/projects/gvsig-postgresql/repository/show/tags/org.gvsig.postgresql-2.0.199</url>
22
  </scm>
23

  
24
    <repositories>
25
        <repository>
26
            <id>gvsig-public-http-repository</id>
27
            <name>gvSIG maven public HTTP repository</name>
28
            <url>http://devel.gvsig.org/m2repo/j2se</url>
29
            <releases>
30
                <enabled>true</enabled>
31
                <updatePolicy>daily</updatePolicy>
32
                <checksumPolicy>warn</checksumPolicy>
33
            </releases>
34
            <snapshots>
35
                <enabled>true</enabled>
36
                <updatePolicy>daily</updatePolicy>
37
                <checksumPolicy>warn</checksumPolicy>
38
            </snapshots>
39
        </repository>
40
    </repositories>
41
  
42
  
43
	<build>
44
		<plugins>
45
			<plugin>
46
				<groupId>org.apache.maven.plugins</groupId>
47
				<artifactId>maven-release-plugin</artifactId>
48
				<configuration>
49
					<tagBase>https://devel.gvsig.org/svn/gvsig-postgresql/tags/</tagBase>
50
					<goals>deploy</goals>
51
				</configuration>
52
			</plugin>
53
		</plugins>
54
	</build>
55

  
56

  
57
  <dependencyManagement>
58
      <dependencies>
59
          <dependency>
60
            <groupId>org.gvsig</groupId>
61
            <artifactId>org.gvsig.postgresql.provider</artifactId>
62
            <version>2.0.199</version>
63
          </dependency>
64
          <dependency>
65
            <groupId>org.gvsig</groupId>
66
            <artifactId>org.gvsig.postgresql.app.mainplugin</artifactId>
67
            <version>2.0.199</version>
68
          </dependency>
69
        <dependency>
70
            <groupId>org.postgresql</groupId>
71
            <artifactId>postgresql</artifactId>
72
            <version>42.3.1</version>
73
        </dependency>
74
        <dependency>
75
          <groupId>org.apache.commons</groupId>
76
          <artifactId>commons-dbcp2</artifactId>
77
          <version>2.7.0</version>
78
        </dependency>   
79
        <dependency>
80
            <groupId>org.apache.commons</groupId>
81
            <artifactId>commons-pool2</artifactId>
82
            <version>2.7.0</version>
83
        </dependency>
84
      </dependencies>
85
  </dependencyManagement>
86
 
87
  <modules>
88
    <module>org.gvsig.postgresql.app</module>
89
    <module>org.gvsig.postgresql.provider</module>
90
  </modules>
91

  
92
</project>
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestWhereWithComputedField.java
1
package org.gvsig.postgresql.dal;
2

  
3
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils;
4
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestWhereWithComputedField;
5

  
6
public class TestWhereWithComputedField extends AbstractTestWhereWithComputedField {
7
    
8
    public TestWhereWithComputedField(String testName) {
9
        super(testName);
10
    }
11

  
12
    @Override
13
    protected AbstractTestUtils createUtils() {
14
        return new TestUtilsPostgreSQL();
15
    }
16

  
17
    @Override
18
    public void testWhereWithComputedField() throws Exception {
19
        super.testWhereWithComputedField(); 
20
    }
21

  
22
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestUtils.java
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
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCount.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.List;
4
import junit.framework.TestCase;
5
import org.gvsig.fmap.dal.feature.FeatureStore;
6
import org.gvsig.fmap.dal.feature.FeatureType;
7
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
8
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
9
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
11
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CountOperation;
12
import org.gvsig.postgresql.dal.TestUtils;
13
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

  
17
public class TestCount extends TestCase {
18

  
19
  private static final Logger LOGGER = LoggerFactory.getLogger(TestCount.class);
20

  
21
  public TestCount(String testName) {
22
    super(testName);
23
  }
24

  
25
  @Override
26
  protected void setUp() throws Exception {
27
    super.setUp();
28
    new DefaultLibrariesInitializer().fullInitialize();
29
  }
30

  
31
  @Override
32
  protected void tearDown() throws Exception {
33
    super.tearDown();
34
  }
35

  
36
  // TODO add test methods here. The name must begin with 'test'. For example:
37
  // public void testHello() {}
38
  
39
  public void testCount() throws Exception {
40
    JDBCHelper helper = TestUtils.getJDBCHelper();
41
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
42
    OperationsFactory operations = helper.getOperations();
43

  
44
    List<String> expectedSQLs = TestUtils.getSQLs("count.sql");
45
    
46
    FeatureStore sourceStore = TestUtils.openSourceStore1();
47

  
48
    TableReference table = operations.createTableReference(
49
            "dbtest", 
50
            sqlbuilder.default_schema(), 
51
            "test", 
52
            null
53
    );
54
    FeatureType featureType = sourceStore.getDefaultFeatureType();
55
    CountOperation count = operations.createCount(
56
            featureType,
57
            table, 
58
            null, null
59
    );
60
    
61
    String sql = count.getSQL();
62
    assertEquals("Count SQL", expectedSQLs.get(0), sql);
63
  }
64

  
65
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestResultSetForSetProvider.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.List;
4
import junit.framework.TestCase;
5
import org.gvsig.fmap.dal.feature.FeatureStore;
6
import org.gvsig.fmap.dal.feature.FeatureType;
7
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
8
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
9
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
11
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation;
12
import org.gvsig.postgresql.dal.TestUtils;
13
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

  
17
public class TestResultSetForSetProvider extends TestCase {
18

  
19
  private static final Logger LOGGER = LoggerFactory.getLogger(TestResultSetForSetProvider.class);
20

  
21
  public TestResultSetForSetProvider(String testName) {
22
    super(testName);
23
  }
24

  
25
  @Override
26
  protected void setUp() throws Exception {
27
    super.setUp();
28
    new DefaultLibrariesInitializer().fullInitialize();
29
  }
30

  
31
  @Override
32
  protected void tearDown() throws Exception {
33
    super.tearDown();
34
  }
35

  
36
  // TODO add test methods here. The name must begin with 'test'. For example:
37
  // public void testHello() {}
38
  
39
  public void testResultSetForSetProvider() throws Exception {
40
    JDBCHelper helper = TestUtils.getJDBCHelper();
41
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
42
    OperationsFactory operations = helper.getOperations();
43

  
44
    List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql");
45
    
46
    FeatureStore sourceStore = TestUtils.openSourceStore1();
47

  
48
    TableReference table = operations.createTableReference(
49
            "dbtest", 
50
            sqlbuilder.default_schema(), 
51
            "test", 
52
            null
53
    );
54
    FeatureType featureType = sourceStore.getDefaultFeatureType();
55
    ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider(
56
            table,
57
            null,
58
            null,
59
            null,
60
            featureType,
61
            featureType,
62
            0,
63
            0, 
64
            0
65
    );
66
    String sql = resultSetForSetProvider.getSQL();
67
    assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(0), sql);
68
  }
69

  
70
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestFetchFeatureProviderByReference.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.List;
4
import junit.framework.TestCase;
5
import org.gvsig.fmap.dal.feature.Feature;
6
import org.gvsig.fmap.dal.feature.FeatureReference;
7
import org.gvsig.fmap.dal.feature.FeatureStore;
8
import org.gvsig.fmap.dal.feature.FeatureType;
9
import org.gvsig.fmap.dal.feature.impl.featurereference.FeatureReferenceFactory;
10
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
11
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
12
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
13
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
14
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
15
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureProviderByReferenceOperation;
16
import org.gvsig.postgresql.dal.TestUtils;
17
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

  
21
public class TestFetchFeatureProviderByReference extends TestCase {
22

  
23
  private static final Logger LOGGER = LoggerFactory.getLogger(TestFetchFeatureProviderByReference.class);
24

  
25
  public TestFetchFeatureProviderByReference(String testName) {
26
    super(testName);
27
  }
28

  
29
  @Override
30
  protected void setUp() throws Exception {
31
    super.setUp();
32
    new DefaultLibrariesInitializer().fullInitialize();
33
  }
34

  
35
  @Override
36
  protected void tearDown() throws Exception {
37
    super.tearDown();
38
  }
39

  
40
  // TODO add test methods here. The name must begin with 'test'. For example:
41
  // public void testHello() {}
42
  
43
  public void testFetchFeatureProviderByReference() throws Exception {
44
    JDBCHelper helper = TestUtils.getJDBCHelper();
45
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
46
    OperationsFactory operations = helper.getOperations();
47

  
48
    List<String> expectedSQLs = TestUtils.getSQLs("fetchFeatureProviderByReference.sql");
49
    
50
    FeatureStore sourceStore = TestUtils.openSourceStore1();
51
    TableReference table = operations.createTableReference(
52
            "dbtest", 
53
            sqlbuilder.default_schema(), 
54
            "test", 
55
            null
56
    );
57
    FeatureType featureType = sourceStore.getDefaultFeatureType();
58
    Feature feature = sourceStore.getFeatures().get(1);    
59
    FeatureReference reference = FeatureReferenceFactory.createReferencePKFromFeature(feature);
60
    
61
    FetchFeatureProviderByReferenceOperation fetchFeatureProviderByReference = operations.createFetchFeatureProviderByReference(
62
            (FeatureReferenceProviderServices) reference,
63
            featureType, 
64
            table
65
    );
66
    
67
    String sql = fetchFeatureProviderByReference.getSQL();
68
    assertEquals("FetchFeatureProviderByReference SQL", expectedSQLs.get(0), sql);
69
  }
70

  
71
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCalculateEnvelope.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.List;
4
import junit.framework.TestCase;
5
import org.gvsig.fmap.dal.feature.FeatureStore;
6
import org.gvsig.fmap.dal.feature.FeatureType;
7
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
8
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
9
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
11
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CalculateEnvelopeOfColumnOperation;
12
import org.gvsig.postgresql.dal.TestUtils;
13
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

  
17
public class TestCalculateEnvelope extends TestCase {
18

  
19
  private static final Logger LOGGER = LoggerFactory.getLogger(TestCalculateEnvelope.class);
20

  
21
  public TestCalculateEnvelope(String testName) {
22
    super(testName);
23
  }
24

  
25
  @Override
26
  protected void setUp() throws Exception {
27
    super.setUp();
28
    new DefaultLibrariesInitializer().fullInitialize();
29
  }
30

  
31
  @Override
32
  protected void tearDown() throws Exception {
33
    super.tearDown();
34
  }
35

  
36
  // TODO add test methods here. The name must begin with 'test'. For example:
37
  // public void testHello() {}
38
  
39
  public void testCalculateEnvelope() throws Exception {
40
    JDBCHelper helper = TestUtils.getJDBCHelper();
41
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
42
    OperationsFactory operations = helper.getOperations();
43

  
44
    List<String> expectedSQLs = TestUtils.getSQLs("calculateEnvelope.sql");
45
    
46
    FeatureStore sourceStore = TestUtils.openSourceStore1();
47

  
48
    TableReference table = operations.createTableReference(
49
            "dbtest", 
50
            sqlbuilder.default_schema(), 
51
            "test", 
52
            null
53
    );
54
    FeatureType featureType = sourceStore.getDefaultFeatureType();
55
    CalculateEnvelopeOfColumnOperation calculateEnvelope = operations.createCalculateEnvelopeOfColumn(
56
            featureType,
57
            table, 
58
            "Geometry",
59
            null,
60
            null, 
61
            featureType.getDefaultSRS()
62
    );
63
    
64
    String sql = calculateEnvelope.getSQL();
65
    assertEquals("CalculateEnvelope SQL", expectedSQLs.get(0), sql);
66
  }
67

  
68
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestCreateTable.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.List;
4
import junit.framework.TestCase;
5
import org.gvsig.fmap.dal.feature.FeatureStore;
6
import org.gvsig.fmap.dal.feature.FeatureType;
7
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
8
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
9
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
11
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CreateTableOperation;
12
import org.gvsig.postgresql.dal.TestUtils;
13
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

  
17
public class TestCreateTable extends TestCase {
18

  
19
  private static final Logger LOGGER = LoggerFactory.getLogger(TestCreateTable.class);
20

  
21
  public TestCreateTable(String testName) {
22
    super(testName);
23
  }
24

  
25
  @Override
26
  protected void setUp() throws Exception {
27
    super.setUp();
28
    new DefaultLibrariesInitializer().fullInitialize();
29
  }
30

  
31
  @Override
32
  protected void tearDown() throws Exception {
33
    super.tearDown();
34
  }
35

  
36
  // TODO add test methods here. The name must begin with 'test'. For example:
37
  // public void testHello() {}
38
  
39
  public void testCreateTable() throws Exception {
40
    JDBCHelper helper = TestUtils.getJDBCHelper();
41
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
42
    OperationsFactory operations = helper.getOperations();
43

  
44
    List<String> expectedSQLs = TestUtils.getSQLs("createTable.sql");
45
    
46
    FeatureStore sourceStore = TestUtils.openSourceStore1();
47

  
48
    TableReference table = operations.createTableReference(
49
            "dbtest", 
50
            sqlbuilder.default_schema(), 
51
            "test", 
52
            null
53
    );
54
    FeatureType featureType = sourceStore.getDefaultFeatureType();
55
    CreateTableOperation createTable = operations.createTable(
56
            table,
57
            featureType,
58
            null,
59
            null
60
    );
61
    List<String> SQLs = createTable.getSQLs();
62
    assertEquals("CreateTable num. SQLs", expectedSQLs.size(), SQLs.size());
63
    for (int i = 0; i < expectedSQLs.size(); i++) {
64
      assertEquals("CreateTable SQL "+i, expectedSQLs.get(i), SQLs.get(i));
65
    }
66

  
67
  }
68

  
69
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestDropTable.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.List;
4
import junit.framework.TestCase;
5
import org.gvsig.fmap.dal.feature.FeatureStore;
6
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
7
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
8
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
9
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
10
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.DropTableOperation;
11
import org.gvsig.postgresql.dal.TestUtils;
12
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
13
import org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
15

  
16
public class TestDropTable extends TestCase {
17

  
18
  private static final Logger LOGGER = LoggerFactory.getLogger(TestDropTable.class);
19

  
20
  public TestDropTable(String testName) {
21
    super(testName);
22
  }
23

  
24
  @Override
25
  protected void setUp() throws Exception {
26
    super.setUp();
27
    new DefaultLibrariesInitializer().fullInitialize();
28
  }
29

  
30
  @Override
31
  protected void tearDown() throws Exception {
32
    super.tearDown();
33
  }
34

  
35
  // TODO add test methods here. The name must begin with 'test'. For example:
36
  // public void testHello() {}
37
  
38
  public void testDropTable() throws Exception {
39
    JDBCHelper helper = TestUtils.getJDBCHelper();
40
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
41
    OperationsFactory operations = helper.getOperations();
42

  
43
    List<String> expectedSQLs = TestUtils.getSQLs("dropTable.sql");
44
    
45
    FeatureStore sourceStore = TestUtils.openSourceStore1();
46

  
47
    TableReference table = operations.createTableReference(
48
            "dbtest", 
49
            sqlbuilder.default_schema(), 
50
            "test", 
51
            null
52
    );
53
    DropTableOperation dropTable = operations.createDropTable(
54
            table
55
    );
56
    List<String> SQLs = dropTable.getSQLs();
57
    assertEquals("DropTable num. SQLs", expectedSQLs.size(), SQLs.size());
58
    for (int i = 0; i < expectedSQLs.size(); i++) {
59
      assertEquals("DropTable SQL "+i, expectedSQLs.get(i), SQLs.get(i));
60
    }
61
  }
62

  
63
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestTableIsEmpty.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.List;
4
import junit.framework.TestCase;
5
import org.gvsig.fmap.dal.feature.FeatureStore;
6
import org.gvsig.fmap.dal.feature.FeatureType;
7
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
8
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
9
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
11
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.TableIsEmptyOperation;
12
import org.gvsig.postgresql.dal.TestUtils;
13
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

  
17
public class TestTableIsEmpty extends TestCase {
18

  
19
  private static final Logger LOGGER = LoggerFactory.getLogger(TestTableIsEmpty.class);
20

  
21
  public TestTableIsEmpty(String testName) {
22
    super(testName);
23
  }
24

  
25
  @Override
26
  protected void setUp() throws Exception {
27
    super.setUp();
28
    new DefaultLibrariesInitializer().fullInitialize();
29
  }
30

  
31
  @Override
32
  protected void tearDown() throws Exception {
33
    super.tearDown();
34
  }
35

  
36
  // TODO add test methods here. The name must begin with 'test'. For example:
37
  // public void testHello() {}
38
  
39
  public void testTableIsEmpty() throws Exception {
40
    JDBCHelper helper = TestUtils.getJDBCHelper();
41
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
42
    OperationsFactory operations = helper.getOperations();
43

  
44
    List<String> expectedSQLs = TestUtils.getSQLs("tableIsEmpty.sql");
45
    
46
    FeatureStore sourceStore = TestUtils.openSourceStore1();
47

  
48
    TableReference table = operations.createTableReference(
49
            "dbtest", 
50
            sqlbuilder.default_schema(), 
51
            "test", 
52
            null
53
    );
54
    FeatureType featureType = sourceStore.getDefaultFeatureType();
55
    TableIsEmptyOperation tableIsEmpty = operations.createTableIsEmpty(
56
            featureType,
57
            table,
58
            null, 
59
            null
60
    );
61
    
62
    String sql = tableIsEmpty.getSQL();
63
    assertEquals("TableIsEmpty SQL", expectedSQLs.get(0), sql);
64
  }
65

  
66
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestPerformChanges.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.Collections;
4
import java.util.List;
5
import junit.framework.TestCase;
6
import org.gvsig.fmap.dal.DALLocator;
7
import org.gvsig.fmap.dal.DataTypes;
8
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
9
import org.gvsig.fmap.dal.feature.EditableFeatureType;
10
import org.gvsig.fmap.dal.feature.FeatureStore;
11
import org.gvsig.fmap.dal.feature.FeatureType;
12
import org.gvsig.fmap.dal.feature.FeatureType.FeatureTypeChanged;
13
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
14
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
15
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
16
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
17
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.PerformChangesOperation;
18
import org.gvsig.postgresql.dal.TestUtils;
19
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
20
import org.slf4j.Logger;
21
import org.slf4j.LoggerFactory;
22

  
23
public class TestPerformChanges extends TestCase {
24

  
25
  private static final Logger LOGGER = LoggerFactory.getLogger(TestPerformChanges.class);
26

  
27
  public TestPerformChanges(String testName) {
28
    super(testName);
29
  }
30

  
31
  @Override
32
  protected void setUp() throws Exception {
33
    super.setUp();
34
    new DefaultLibrariesInitializer().fullInitialize();
35
  }
36

  
37
  @Override
38
  protected void tearDown() throws Exception {
39
    super.tearDown();
40
  }
41

  
42
  // TODO add test methods here. The name must begin with 'test'. For example:
43
  // public void testHello() {}
44
  
45
  public void testPerformChanges() throws Exception {
46
    JDBCHelper helper = TestUtils.getJDBCHelper();
47
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
48
    OperationsFactory operations = helper.getOperations();
49

  
50
    List<String> expectedSQLs = TestUtils.getSQLs("performChanges.sql");
51
    
52
    FeatureStore sourceStore = TestUtils.openSourceStore1();
53

  
54
    TableReference table = operations.createTableReference(
55
            "dbtest", 
56
            sqlbuilder.default_schema(), 
57
            "test", 
58
            null
59
    );
60
    FeatureType featureType = sourceStore.getDefaultFeatureType();
61
    
62
    
63
    FeatureTypeChanged featureTypeChanged = new FeatureTypeChanged() {
64
      @Override
65
      public FeatureType getSource() {
66
        EditableFeatureType ft = DALLocator.getDataManager().createFeatureType();
67
        EditableFeatureAttributeDescriptor id = ft.add("ID", DataTypes.INT);
68
        id.copyFrom(featureType.getAttributeDescriptor("ID"));
69
        return ft;
70
      }
71

  
72
      @Override
73
      public FeatureType getTarget() {
74
        return featureType;
75
      }
76
    };
77
    List<FeatureTypeChanged> featureTypesChangeds = Collections.singletonList(featureTypeChanged);
78
    
79
    PerformChangesOperation performChanges = operations.createPerformChanges(
80
            table, 
81
            sourceStore.getDefaultFeatureType(),
82
            null, 
83
            null, 
84
            null, 
85
            featureTypesChangeds.iterator()
86
    );
87
    String insertSQL = performChanges.getInsertSQL();
88
    String deleteSQL = performChanges.getDeleteSQL();
89
    String updateSQL = performChanges.getUpdateSQL();
90
    List<String> updateTableSQLs = performChanges.getUpdateTableSQLs();
91

  
92
    assertEquals("Insert SQL", expectedSQLs.get(0), insertSQL);
93
    assertEquals("Delete SQL", expectedSQLs.get(1), deleteSQL);
94
    assertEquals("Update SQL", expectedSQLs.get(2), updateSQL);
95
    assertEquals("UpdateTable num. SQLs", expectedSQLs.size()-3, updateTableSQLs.size());
96
    for (int i = 0; i < updateTableSQLs.size(); i++) {
97
      assertEquals("UpdateTable SQL "+i, expectedSQLs.get(i+3), updateTableSQLs.get(i));
98
    }
99
    
100
    // FIXME: El ALTER TABLE de una columna geometria no funciona
101
  }
102

  
103
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestUpdateTableStatistics.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.List;
4
import junit.framework.TestCase;
5
import org.gvsig.fmap.dal.feature.FeatureStore;
6
import org.gvsig.fmap.dal.feature.FeatureType;
7
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
8
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
9
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
11
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.UpdateTableStatisticsOperation;
12
import org.gvsig.postgresql.dal.TestUtils;
13
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

  
17
public class TestUpdateTableStatistics extends TestCase {
18

  
19
  private static final Logger LOGGER = LoggerFactory.getLogger(TestUpdateTableStatistics.class);
20

  
21
  public TestUpdateTableStatistics(String testName) {
22
    super(testName);
23
  }
24

  
25
  @Override
26
  protected void setUp() throws Exception {
27
    super.setUp();
28
    new DefaultLibrariesInitializer().fullInitialize();
29
  }
30

  
31
  @Override
32
  protected void tearDown() throws Exception {
33
    super.tearDown();
34
  }
35

  
36
  // TODO add test methods here. The name must begin with 'test'. For example:
37
  // public void testHello() {}
38
  
39
  public void testUpdateTableStatistics() throws Exception {
40
    JDBCHelper helper = TestUtils.getJDBCHelper();
41
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
42
    OperationsFactory operations = helper.getOperations();
43

  
44
    List<String> expectedSQLs = TestUtils.getSQLs("updateTableStatistics.sql");
45
    
46
    FeatureStore sourceStore = TestUtils.openSourceStore1();
47

  
48
    TableReference table = operations.createTableReference(
49
            "dbtest", 
50
            sqlbuilder.default_schema(), 
51
            "test", 
52
            null
53
    );
54
    FeatureType featureType = sourceStore.getDefaultFeatureType();
55
    UpdateTableStatisticsOperation updateTableStatistics = operations.createUpdateTableStatistics(
56
            table
57
    );
58
    
59
    List<String> SQLs = updateTableStatistics.getSQLs();
60
    assertEquals("UpdateTableStatistics num. SQLs", expectedSQLs.size(), SQLs.size());
61
    for (int i = 0; i < expectedSQLs.size(); i++) {
62
      assertEquals("UpdateTableStatistics SQL "+i, expectedSQLs.get(i), SQLs.get(i));
63
    }
64
  }
65

  
66
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestJsonValue.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestJsonValue;
4
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils;
5
import org.gvsig.postgresql.dal.TestUtilsPostgreSQL;
6
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

  
10
public class TestJsonValue extends AbstractTestJsonValue {
11

  
12
    private static final Logger LOGGER = LoggerFactory.getLogger(TestJsonValue.class);
13

  
14
    public TestJsonValue(String testName) {
15
        super(testName);
16
    }
17

  
18
    @Override
19
    protected void setUp() throws Exception {
20
        super.setUp();
21
        new DefaultLibrariesInitializer().fullInitialize();
22
    }
23

  
24
    @Override
25
    protected void tearDown() throws Exception {
26
        super.tearDown();
27
    }
28

  
29
    @Override
30
    protected AbstractTestUtils createUtils() {
31
        return new TestUtilsPostgreSQL();
32
    }
33
    
34
    public void testJsonValue() throws Exception {
35
        super.testJsonValue();
36
    }
37
    
38

  
39
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestAppend.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import junit.framework.TestCase;
6
import org.gvsig.fmap.dal.DataTypes;
7
import org.gvsig.fmap.dal.feature.Feature;
8
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
9
import org.gvsig.fmap.dal.feature.FeatureStore;
10
import org.gvsig.fmap.dal.feature.FeatureType;
11
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
12
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
13
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
14
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
15
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.AppendOperation;
16
import org.gvsig.postgresql.dal.TestUtils;
17
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

  
21
public class TestAppend extends TestCase {
22

  
23
  private static final Logger LOGGER = LoggerFactory.getLogger(TestAppend.class);
24

  
25
  public TestAppend(String testName) {
26
    super(testName);
27
  }
28

  
29
  @Override
30
  protected void setUp() throws Exception {
31
    super.setUp();
32
    new DefaultLibrariesInitializer().fullInitialize();
33
  }
34

  
35
  @Override
36
  protected void tearDown() throws Exception {
37
    super.tearDown();
38
  }
39

  
40
  // TODO add test methods here. The name must begin with 'test'. For example:
41
  // public void testHello() {}
42
  
43
  public void testAppend() throws Exception {
44
    JDBCHelper helper = TestUtils.getJDBCHelper();
45
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
46
    OperationsFactory operations = helper.getOperations();
47

  
48
    List<String> expectedSQLs = TestUtils.getSQLs("append.sql");
49
    
50
    FeatureStore sourceStore = TestUtils.openSourceStore1();
51

  
52
    TableReference table = operations.createTableReference(
53
            "dbtest", 
54
            sqlbuilder.default_schema(), 
55
            "test", 
56
            null
57
    );
58
    FeatureType featureType = sourceStore.getDefaultFeatureType();
59
    AppendOperation append = operations.createAppend(
60
            table,
61
            featureType
62
    );
63
    append.begin();
64
    List<String> SQLs = new ArrayList<>();
65
    SQLs.addAll(append.getPreviousSQLs());
66
    SQLs.add( append.getSQL());
67
    SQLs.addAll(append.getPostSQLs());
68
    assertEquals("Append num SQLs", expectedSQLs.size(), SQLs.size());
69
    for (int i = 0; i < expectedSQLs.size(); i++) {
70
      assertEquals("Append SQL "+i, expectedSQLs.get(i), SQLs.get(i));
71
    }
72
    
73
    for (Feature sourceFeature : sourceStore.getFeatureSet()) {
74
      List<Object> parametersSQL = append.getSQLParameters(TestUtils.getFeatureProvider(sourceFeature));
75
      List<Object> expectedParameters = this.getExpectedparameters(sourceFeature);
76
      assertEquals("Append num. parameters", parametersSQL.size(), expectedParameters.size());
77
      for (int i = 0; i < expectedParameters.size(); i++) {
78
        assertEquals("Append parameter "+i, expectedParameters.get(i), parametersSQL.get(i));
79
      }
80
    }
81
    append.end();
82
  }
83

  
84
  private List<Object> getExpectedparameters(Feature sourceFeature) {
85
    FeatureType ft = sourceFeature.getType();
86
    List<Object> values = new ArrayList<>();
87
    for (FeatureAttributeDescriptor attr : ft) {
88
      Object v = sourceFeature.get(attr.getIndex());
89
      values.add(v);
90
      if( attr.getType()==DataTypes.GEOMETRY ) {
91
        String srs = attr.getSRS().getAbrev();
92
        values.add(Integer.parseInt(srs.split(":")[1]));
93
      }
94
    }
95
    return values;
96
  }
97

  
98
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/sql/TestFetchFeatureType.java
1
package org.gvsig.postgresql.dal.operations.sql;
2

  
3
import java.util.Collections;
4
import java.util.List;
5
import junit.framework.TestCase;
6
import org.gvsig.fmap.dal.feature.FeatureStore;
7
import org.gvsig.fmap.dal.feature.FeatureType;
8
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
9
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
10
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
11
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
12
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.FetchFeatureTypeOperation;
13
import org.gvsig.postgresql.dal.TestUtils;
14
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

  
18
public class TestFetchFeatureType extends TestCase {
19

  
20
  private static final Logger LOGGER = LoggerFactory.getLogger(TestFetchFeatureType.class);
21

  
22
  public TestFetchFeatureType(String testName) {
23
    super(testName);
24
  }
25

  
26
  @Override
27
  protected void setUp() throws Exception {
28
    super.setUp();
29
    new DefaultLibrariesInitializer().fullInitialize();
30
  }
31

  
32
  @Override
33
  protected void tearDown() throws Exception {
34
    super.tearDown();
35
  }
36

  
37
  // TODO add test methods here. The name must begin with 'test'. For example:
38
  // public void testHello() {}
39
  
40
  public void testFetchFeatureType() throws Exception {
41
    JDBCHelper helper = TestUtils.getJDBCHelper();
42
    JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder();
43
    OperationsFactory operations = helper.getOperations();
44

  
45
    List<String> expectedSQLs = TestUtils.getSQLs("fetchFeatureType.sql");
46
    
47
    FeatureStore sourceStore = TestUtils.openSourceStore1();
48

  
49
    TableReference table = operations.createTableReference(
50
            "dbtest", 
51
            sqlbuilder.default_schema(), 
52
            "test", 
53
            null
54
    );
55
    FeatureType featureType = sourceStore.getDefaultFeatureType();
56
    FetchFeatureTypeOperation fetchFeatureType = operations.createFetchFeatureType(
57
            featureType.getEditable(),
58
            table,
59
            Collections.EMPTY_LIST,
60
            null, // "Geometry" 
61
            featureType.getDefaultSRS()
62
    );
63
    
64
    
65
    String retrieveFirstRowOfTableSQL = fetchFeatureType.getSQLToRetrieveMetadataOfTable();
66
    String retrievePrimaryKeysFromInformationSchemaSQL = fetchFeatureType.getSQLToRetrievePrimaryKeysFromInformationSchema();
67

  
68
    assertEquals("FetchFeatureType first row SQL", expectedSQLs.get(0), retrieveFirstRowOfTableSQL);
69
    assertEquals("FetchFeatureType get primery keys SQL", expectedSQLs.get(1), retrievePrimaryKeysFromInformationSchemaSQL);
70
  }
71

  
72
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/operations/usecases/arena2/TestMultipleExpansionOfCalculatedField.java
1
package org.gvsig.postgresql.dal.operations.usecases.arena2;
2

  
3
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils;
4
import org.gvsig.fmap.dal.store.jdbc2.operations.usecases.arena2.AbstractTestMultipleExpansionOfCalculatedField;
5
import org.gvsig.postgresql.dal.TestUtilsPostgreSQL;
6

  
7
@SuppressWarnings("UseSpecificCatch")
8
public class TestMultipleExpansionOfCalculatedField extends AbstractTestMultipleExpansionOfCalculatedField {
9

  
10
    public TestMultipleExpansionOfCalculatedField(String testName) {
11
        super(testName);
12
    }
13

  
14
    @Override
15
    protected AbstractTestUtils createUtils() {
16
        return new TestUtilsPostgreSQL();
17
    }
18
    
19
    @Override
20
    public void testMultipleExpansionOfCalculatedField() throws Exception {
21
       super.testMultipleExpansionOfCalculatedField();
22
    }
23

  
24
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestUtilsPostgreSQL.java
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
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/TestComputedAttributes.java
1
package org.gvsig.postgresql.dal;
2

  
3
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestComputedAttributes;
4
import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils;
5

  
6
public class TestComputedAttributes extends AbstractTestComputedAttributes {
7
    
8
    public TestComputedAttributes(String testName) {
9
        super(testName);
10
    }
11

  
12
    @Override
13
    protected AbstractTestUtils createUtils() {
14
        return new TestUtilsPostgreSQL();
15
    }
16

  
17
    @Override
18
    public void testComputed1() throws Exception {
19
        super.testComputed1(); 
20
    }
21

  
22
    @Override
23
    public void testComputed2() throws Exception {
24
        super.testComputed2(); 
25
    }
26
    
27
}
tags/org.gvsig.postgresql-2.0.199/org.gvsig.postgresql.provider/src/test/java/org/gvsig/postgresql/dal/PostgreSQLBuilderTest.java
1
package org.gvsig.postgresql.dal;
2

  
3
import junit.framework.TestCase;
4
import org.apache.commons.lang3.ArrayUtils;
5
import org.cresques.cts.IProjection;
6
import org.gvsig.expressionevaluator.ExpressionBuilder;
7
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
8
import org.gvsig.fmap.crs.CRSFactory;
9
import org.gvsig.fmap.dal.SQLBuilder;
10
import org.gvsig.fmap.dal.SQLBuilder.Privilege;
11
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase;
12
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
13
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase;
14
import org.gvsig.fmap.geom.DataTypes;
15
import org.gvsig.fmap.geom.Geometry;
16
import org.gvsig.fmap.geom.GeometryLocator;
17
import org.gvsig.fmap.geom.GeometryManager;
18
import org.gvsig.fmap.geom.primitive.Polygon;
19
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
20

  
21
public class PostgreSQLBuilderTest extends TestCase {
22
    
23
    public PostgreSQLBuilderTest(String testName) {
24
        super(testName);
25
    }
26

  
27
    @Override
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff