-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PostgisRasterExport] add step tests
- Loading branch information
1 parent
8c1252e
commit ce04dc2
Showing
10 changed files
with
135 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
gretl/src/test/java/ch/so/agi/gretl/steps/PostgisRasterExportStepTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package ch.so.agi.gretl.steps; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
import org.testcontainers.containers.PostgisContainerProvider; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
|
||
import ch.so.agi.gretl.api.Connector; | ||
import ch.so.agi.gretl.logging.GretlLogger; | ||
import ch.so.agi.gretl.logging.LogEnvironment; | ||
import ch.so.agi.gretl.testutil.TestUtil; | ||
import net.sf.saxon.s9api.SaxonApiException; | ||
|
||
public class PostgisRasterExportStepTest { | ||
private GretlLogger log; | ||
|
||
static String WAIT_PATTERN = ".*database system is ready to accept connections.*\\s"; | ||
|
||
@ClassRule | ||
public static PostgreSQLContainer postgres = | ||
(PostgreSQLContainer) new PostgisContainerProvider() | ||
.newInstance().withDatabaseName("gretl") | ||
.withUsername(TestUtil.PG_DDLUSR_USR) | ||
.withInitScript("init_postgresql.sql") | ||
.waitingFor(Wait.forLogMessage(WAIT_PATTERN, 2)); | ||
|
||
public PostgisRasterExportStepTest() { | ||
LogEnvironment.initStandalone(); | ||
this.log = LogEnvironment.getLogger(this.getClass()); | ||
} | ||
|
||
@Rule | ||
public TemporaryFolder folder = new TemporaryFolder(); | ||
|
||
@Test | ||
public void export_geotiff_Ok() throws Exception { | ||
// Prepare | ||
Connector sourceDb = new Connector(postgres.getJdbcUrl(), TestUtil.PG_READERUSR_USR, TestUtil.PG_READERUSR_PWD); | ||
File sqlFile = new File("src/test/resources/data/postgisrasterprocessor/prepare_raster_geotiff.sql"); | ||
String outFileName = "outfile.tif"; | ||
File targetFile = new File("src/test/resources/data/postgisrasterprocessor/target.tif"); | ||
|
||
File outDirectory = folder.newFolder("build"); | ||
//File outDirectory = Paths.get("/Users/stefan/tmp/").toFile(); | ||
File outFile = Paths.get(outDirectory.getAbsolutePath(), outFileName).toFile(); | ||
|
||
// Run: Calculate and export raster file from PostGIS | ||
PostgisRasterExportStep postgisRasterExportStep = new PostgisRasterExportStep(); | ||
postgisRasterExportStep.execute(sourceDb, sqlFile, outFile); | ||
|
||
// Check result | ||
long targetFileSize = targetFile.length(); | ||
long outFileSize = outFile.length(); | ||
assertEquals(targetFileSize, outFileSize); | ||
} | ||
|
||
@Test | ||
public void export_aaigrid_Ok() throws Exception { | ||
// Prepare | ||
Connector sourceDb = new Connector(postgres.getJdbcUrl(), TestUtil.PG_READERUSR_USR, TestUtil.PG_READERUSR_PWD); | ||
File sqlFile = new File("src/test/resources/data/postgisrasterprocessor/prepare_raster_aaigrid.sql"); | ||
String outFileName = "outfile.asc"; | ||
File targetFile = new File("src/test/resources/data/postgisrasterprocessor/target.asc"); | ||
|
||
File outDirectory = folder.newFolder("build"); | ||
//File outDirectory = Paths.get("/Users/stefan/tmp/").toFile(); | ||
File outFile = Paths.get(outDirectory.getAbsolutePath(), outFileName).toFile(); | ||
|
||
// Run: Calculate and export raster file from PostGIS | ||
PostgisRasterExportStep postgisRasterExportStep = new PostgisRasterExportStep(); | ||
postgisRasterExportStep.execute(sourceDb, sqlFile, outFile); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
gretl/src/test/resources/data/postgisrasterprocessor/prepare_raster_aaigrid.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT | ||
1::int AS foo, ST_AsGDALRaster((ST_AsRaster(ST_Buffer(ST_Point(2607880,1228287),10),150, 150)), 'AAIGrid', ARRAY[''], 2056) AS raster | ||
; |
3 changes: 3 additions & 0 deletions
3
gretl/src/test/resources/data/postgisrasterprocessor/prepare_raster_geotiff.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT | ||
1::int AS foo, ST_AsGDALRaster((ST_AsRaster(ST_Buffer(ST_Point(2607880,1228287),10),150, 150)), 'GTiff', ARRAY[''], 2056) AS raster | ||
; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters