Skip to content

Commit

Permalink
fix: zonky fix attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Oct 27, 2023
1 parent 4ee301d commit 7ba78f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;");

}

Expand Down
13 changes: 13 additions & 0 deletions arc-utils/src/test/java/fr/insee/arc/utils/query/TestDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand Down

0 comments on commit 7ba78f3

Please sign in to comment.