use of com.baremaps.postgres.jdbi.PostgisPlugin in project baremaps by baremaps.
the class ImportResourceIntegrationTest method configure.
@Override
protected ResourceConfig configure() {
enable(TestProperties.LOG_TRAFFIC);
enable(TestProperties.DUMP_ENTITY);
// Create a datasource to a throwaway postgis database
DataSource dataSource = PostgresUtils.datasource(DATABASE_URL);
// Initialize the database
jdbi = Jdbi.create(dataSource).installPlugin(new Jackson2Plugin()).installPlugin(new PostgisPlugin());
jdbi.useHandle(handle -> handle.execute("create extension if not exists hstore;" + "create table collections (id uuid primary key, collection jsonb)"));
// Configure the service
return new ResourceConfig().registerClasses(MultiPartFeature.class, ImportResource.class).register(new AbstractBinder() {
@Override
protected void configure() {
bind(jdbi).to(Jdbi.class);
}
});
}
use of com.baremaps.postgres.jdbi.PostgisPlugin in project baremaps by baremaps.
the class PostgisPluginTest method test.
@Test
@Tag("integration")
void test() {
Jdbi jdbi = Jdbi.create("jdbc:tc:postgis:13-3.1:///test").installPlugin(new PostgisPlugin());
PostgisRecord record = new PostgisRecord();
record.setId(1);
record.setPoint(new GeometryFactory().createPoint(new Coordinate(1, 1)));
record.setLineString(new GeometryFactory().createLineString(new Coordinate[] { new Coordinate(1, 1), new Coordinate(1, 2), new Coordinate(2, 2), new Coordinate(2, 1) }));
record.setPolygon(new GeometryFactory().createPolygon(new Coordinate[] { new Coordinate(1, 1), new Coordinate(1, 2), new Coordinate(2, 2), new Coordinate(2, 1), new Coordinate(1, 1) }));
List<PostgisRecord> result = jdbi.withHandle(handle -> {
handle.execute("DROP TABLE IF EXISTS record");
handle.execute("CREATE TABLE record (id INTEGER PRIMARY KEY, point geometry(point), linestring geometry(linestring), polygon geometry(polygon))");
handle.createUpdate("INSERT INTO record (id, point, linestring, polygon) VALUES (:id, :point, :lineString, :polygon)").bindBean(record).execute();
return handle.createQuery("SELECT * FROM record ORDER BY id").mapToBean(PostgisRecord.class).list();
});
assertEquals(record.getPoint(), result.get(0).getPoint());
assertEquals(record.getLineString(), result.get(0).getLineString());
assertEquals(record.getPolygon(), result.get(0).getPolygon());
}
Aggregations