From 7ba78f38f68708dce7d090e38b85228572eb8c6c Mon Sep 17 00:00:00 2001 From: Manuel Soulier Date: Fri, 27 Oct 2023 15:04:37 +0200 Subject: [PATCH] fix: zonky fix attempt --- .../GenericPreparedStatementBuilderTest.java | 18 +++++++++--------- .../fr/insee/arc/utils/query/TestDatabase.java | 13 +++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/arc-utils/src/test/java/fr/insee/arc/utils/dao/GenericPreparedStatementBuilderTest.java b/arc-utils/src/test/java/fr/insee/arc/utils/dao/GenericPreparedStatementBuilderTest.java index 52a27309c..cb1097484 100644 --- a/arc-utils/src/test/java/fr/insee/arc/utils/dao/GenericPreparedStatementBuilderTest.java +++ b/arc-utils/src/test/java/fr/insee/arc/utils/dao/GenericPreparedStatementBuilderTest.java @@ -1,5 +1,7 @@ package fr.insee.arc.utils.dao; +import java.sql.SQLException; + import org.junit.Test; import fr.insee.arc.utils.exception.ArcException; @@ -11,25 +13,23 @@ public class GenericPreparedStatementBuilderTest extends InitializeQueryTest { @Test public void copyFromGenericBean() throws ArcException { - UtilitaireDao.get(0).executeImmediate(c, "DROP SCHEMA IF EXISTS arc_bas9 CASCADE;"); - UtilitaireDao.get(0).executeImmediate(c, "CREATE TABLE zzz(a text);"); - - UtilitaireDao.get(0).executeImmediate(c, "CREATE SCHEMA arc_bas9;"); + UtilitaireDao.get(0).executeImmediate(c, "DROP SCHEMA IF EXISTS test CASCADE;"); + UtilitaireDao.get(0).executeImmediate(c, "CREATE SCHEMA test;"); // create a test table with 26 lines - UtilitaireDao.get(0).executeImmediate(c, "CREATE TABLE arc_bas9.table_test as select i as id, chr(i+64) as val, array[i,i+1] as arr, current_date as dd from generate_series(1,26) i;"); + UtilitaireDao.get(0).executeImmediate(c, "CREATE TABLE test.table_test as select i as id, chr(i+64) as val, array[i,i+1] as arr, current_date as dd from generate_series(1,26) i;"); // the content will grab the first 10 lines of test table - GenericBean gb= new GenericBean(UtilitaireDao.get(0).executeRequest(c, new GenericPreparedStatementBuilder("SELECT * FROM arc_bas9.table_test where id<=10"))); + GenericBean gb= new GenericBean(UtilitaireDao.get(0).executeRequest(c, new GenericPreparedStatementBuilder("SELECT * FROM test.table_test where id<=10"))); // copy the content into a target table using copyFromGenericBean GenericPreparedStatementBuilder query = new GenericPreparedStatementBuilder(); - query.copyFromGenericBean("arc_bas9.table_test_copy", gb); + query.copyFromGenericBean("test.table_test_copy", gb); UtilitaireDao.get(0).executeRequest(c, query); // test result - testMetadataAndNumberOfRecords("arc_bas9.table_test_copy", 10, new String[] {"id", "val", "arr", "dd"}); - UtilitaireDao.get(0).executeImmediate(c, "DROP SCHEMA IF EXISTS arc_bas9 CASCADE;"); + testMetadataAndNumberOfRecords("test.table_test_copy", 10, new String[] {"id", "val", "arr", "dd"}); + UtilitaireDao.get(0).executeImmediate(c, "DROP SCHEMA IF EXISTS test CASCADE;"); } diff --git a/arc-utils/src/test/java/fr/insee/arc/utils/query/TestDatabase.java b/arc-utils/src/test/java/fr/insee/arc/utils/query/TestDatabase.java index 4fba6d7e2..d8121d0c2 100644 --- a/arc-utils/src/test/java/fr/insee/arc/utils/query/TestDatabase.java +++ b/arc-utils/src/test/java/fr/insee/arc/utils/query/TestDatabase.java @@ -4,6 +4,8 @@ import java.sql.Connection; import java.sql.SQLException; +import fr.insee.arc.utils.dao.UtilitaireDao; +import fr.insee.arc.utils.exception.ArcException; import io.zonky.test.db.postgres.embedded.EmbeddedPostgres; public class TestDatabase { @@ -17,9 +19,20 @@ private static Connection instanciateTestDatabase() try { pg = EmbeddedPostgres.start(); connection = pg.getPostgresDatabase().getConnection(); + + String user = connection.getMetaData().getUserName(); + System.out.println("§§§§§§§"); + System.out.println(user); + + UtilitaireDao.get(0).executeImmediate(connection, "GRANT CREATE ON DATABASE test TO "+user+";"); + + + } catch (IOException | SQLException e) { connection = null; + } catch (ArcException e) { + connection = null; } return connection; }