From be7587d0217728216df958f241678bb5dd7d7eba Mon Sep 17 00:00:00 2001 From: Manuel Soulier Date: Fri, 1 Dec 2023 18:50:25 +0100 Subject: [PATCH] feat: client dao tests on metadata tables --- .../ImportStep3GetTableDataService.java | 1 - .../services/importServlet/dao/ClientDao.java | 44 +++++----- .../importServlet/dao/ClientDaoTest.java | 86 ++++++++++++++++++- 3 files changed, 107 insertions(+), 24 deletions(-) diff --git a/arc-ws/src/main/java/fr/insee/arc/ws/services/importServlet/ImportStep3GetTableDataService.java b/arc-ws/src/main/java/fr/insee/arc/ws/services/importServlet/ImportStep3GetTableDataService.java index f848750b0..546bc1133 100644 --- a/arc-ws/src/main/java/fr/insee/arc/ws/services/importServlet/ImportStep3GetTableDataService.java +++ b/arc-ws/src/main/java/fr/insee/arc/ws/services/importServlet/ImportStep3GetTableDataService.java @@ -4,7 +4,6 @@ import org.apache.logging.log4j.Logger; import org.json.JSONObject; -import fr.insee.arc.core.dataobjects.ViewEnum; import fr.insee.arc.utils.exception.ArcException; import fr.insee.arc.utils.utils.Sleep; import fr.insee.arc.ws.services.importServlet.actions.SendResponse; diff --git a/arc-ws/src/main/java/fr/insee/arc/ws/services/importServlet/dao/ClientDao.java b/arc-ws/src/main/java/fr/insee/arc/ws/services/importServlet/dao/ClientDao.java index 96e8966f8..d4a044d85 100644 --- a/arc-ws/src/main/java/fr/insee/arc/ws/services/importServlet/dao/ClientDao.java +++ b/arc-ws/src/main/java/fr/insee/arc/ws/services/importServlet/dao/ClientDao.java @@ -326,6 +326,28 @@ public void createTableVarMetier() throws ArcException { } + /* + * (non-Javadoc) + * + * @see fr.insee.arc_essnet.ws.dao.ClientDarcleMetier(java.lang.String, + * fr.insee.arc_essnet.ws.actions.Senarc + */ + public void createTableMetier() throws ArcException { + LoggerHelper.debugAsComment(LOGGER, "ClientDaoImpl.sendTableMetier()"); + + String nomTableImage = TableNaming.buildTableNameWithTokens(environnement, ViewEnum.MOD_TABLE_METIER, client, + timestamp); + + ArcPreparedStatementBuilder requete = new ArcPreparedStatementBuilder( + "\n CREATE TABLE " + nomTableImage + FormatSQL.WITH_NO_VACUUM + " AS"); + requete.append("\n SELECT * FROM " + ViewEnum.MOD_TABLE_METIER.getFullName(environnement) + " "); + requete.append("\n WHERE id_famille = " + requete.quoteText(famille)); + requete.append(";"); + UtilitaireDao.get(0).executeRequest(connection, requete); + + registerTableToBeRetrieved(ExportTrackingType.DATA, ArcDatabase.COORDINATOR, nomTableImage); + } + /* * (non-Javadoc) * @@ -368,28 +390,6 @@ public void createTablePeriodicite() throws ArcException { } - /* - * (non-Javadoc) - * - * @see fr.insee.arc_essnet.ws.dao.ClientDarcleMetier(java.lang.String, - * fr.insee.arc_essnet.ws.actions.Senarc - */ - public void createTableMetier() throws ArcException { - LoggerHelper.debugAsComment(LOGGER, "ClientDaoImpl.sendTableMetier()"); - - String nomTableImage = TableNaming.buildTableNameWithTokens(environnement, ViewEnum.MOD_TABLE_METIER, client, - timestamp); - - ArcPreparedStatementBuilder requete = new ArcPreparedStatementBuilder( - "\n CREATE TABLE " + nomTableImage + FormatSQL.WITH_NO_VACUUM + " AS"); - requete.append("\n SELECT * FROM " + ViewEnum.MOD_TABLE_METIER.getFullName(environnement) + " "); - requete.append("\n WHERE id_famille = " + requete.quoteText(famille)); - requete.append(";"); - UtilitaireDao.get(0).executeRequest(connection, requete); - - registerTableToBeRetrieved(ExportTrackingType.DATA, ArcDatabase.COORDINATOR, nomTableImage); - } - /** * Get the table object of the table to retrieve by its type * diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/ClientDaoTest.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/ClientDaoTest.java index a28a37f41..c991ab6be 100644 --- a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/ClientDaoTest.java +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/ClientDaoTest.java @@ -2,6 +2,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.sql.SQLException; @@ -12,6 +13,7 @@ import fr.insee.arc.core.dataobjects.ArcDatabase; import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; +import fr.insee.arc.core.dataobjects.ViewEnum; import fr.insee.arc.utils.dao.SQL; import fr.insee.arc.utils.dao.UtilitaireDao; import fr.insee.arc.utils.exception.ArcException; @@ -41,6 +43,9 @@ public void clientDaoTest() throws ArcException, SQLException { // test tracking table creation and registration testCreateTableTrackRetrievedTables(); + //test return of client table when nothing found + testGetAClientTableByNameNotFound(); + // test family check testVerificationFamilleOK(); testVerificationFamilleKO(); @@ -62,9 +67,67 @@ public void clientDaoTest() throws ArcException, SQLException { // the dataTable in dataTableImages must be found the the track data table by its name testGetAClientTableByName(dataTableImages); + // test tables creation for metadata tables + testCreateTableNmcl(); + testCreateTableVarMetier(); + testCreateTableTableMetier(); + testCreateTableTableFamille(); + testCreateTableTablePeriodicite(); + + testDropPendingClientTables(); + + destroyTestData(); } + private void testDropPendingClientTables() throws ArcException { + clientDaoDsnStep1.dropPendingClientTables(ArcDatabase.COORDINATOR.getIndex()); + // all client tables should had been deleted + assertFalse(UtilitaireDao.get(0).isTableExiste(c, "arc_bas1.ARTEMIS%")); + } + + private void testCreateTableNmcl() throws ArcException { + // TODO Auto-generated method stub + clientDaoDsnStep1.createTableNmcl(); + // table image created should be like arc_bas1.ARTEMIS_timestamp_ + assertTrue(UtilitaireDao.get(0).isTableExiste(c, "arc_bas1.ARTEMIS_%_nmcl_table1")); + assertTrue(UtilitaireDao.get(0).isTableExiste(c, "arc_bas1.ARTEMIS_%_nmcl_table2")); + } + + private void testCreateTableVarMetier() throws ArcException { + // TODO Auto-generated method stub + clientDaoDsnStep1.createTableVarMetier(); + // table image created should be like arc_bas1.ARTEMIS_timestamp_ + assertTrue(UtilitaireDao.get(0).isTableExiste(c, "arc_bas1.ARTEMIS_%_mod_variable_metier")); + } + + private void testCreateTableTableMetier() throws ArcException { + // TODO Auto-generated method stub + clientDaoDsnStep1.createTableMetier(); + // table image created should be like arc_bas1.ARTEMIS_timestamp_ + assertTrue(UtilitaireDao.get(0).isTableExiste(c, "arc_bas1.ARTEMIS_%_mod_table_metier")); + } + + private void testCreateTableTableFamille() throws ArcException { + // TODO Auto-generated method stub + clientDaoDsnStep1.createTableFamille(); + // table image created should be like arc_bas1.ARTEMIS_timestamp_ + assertTrue(UtilitaireDao.get(0).isTableExiste(c, "arc_bas1.ARTEMIS_%_ext_mod_famille")); + } + + private void testCreateTableTablePeriodicite() throws ArcException { + // TODO Auto-generated method stub + clientDaoDsnStep1.createTablePeriodicite(); + // table image created should be like arc_bas1.ARTEMIS_timestamp_ + assertTrue(UtilitaireDao.get(0).isTableExiste(c, "arc_bas1.ARTEMIS_%_ext_mod_periodicite")); + } + + private void testGetAClientTableByNameNotFound() throws ArcException { + TableToRetrieve registeredTable = clientDaoDsnStep1.getAClientTableByName("not_existing_table"); + assertNull(registeredTable.getTableName()); + assertNull(registeredTable.getNod()); + } + private void testGetAClientTableByType(List dataTableImages) throws ArcException { TableToRetrieve registeredTable = clientDaoDsnStep1.getAClientTableByType(ExportTrackingType.DATA); @@ -98,7 +161,7 @@ private List testCreateImages(List selectedDataTables) throws Ar // only table with 1 id_source must had been retrieved assertEquals(1, content.size()); - + return dataTableImages; } @@ -120,6 +183,7 @@ private void testCreateTableOfIdSourceRepriseFalse() throws ArcException { // only 1 file must be selected as reprise = false // file_not_to_retrieve_when_reprise_false has already been marked as retrieved by 'ARTEMIS' client assertEquals(1, content.size()); + } /** @@ -201,16 +265,25 @@ private void initializeTestData() throws SQLException, ArcException { query.append("CREATE SCHEMA arc;"); query.append("CREATE SCHEMA arc_bas1;"); + + // family and client tables query.append("CREATE TABLE arc.ihm_client AS "); query.append("SELECT 'DSN' as id_famille,'ARTEMIS' as id_application UNION ALL "); query.append("SELECT 'DSN' as id_famille,'DSNFLASH' as id_application"); query.append(SQL.END_QUERY); + query.append("CREATE TABLE arc.ihm_famille AS SELECT 'DSN' as id_famille"); + query.append(SQL.END_QUERY); + query.append("CREATE TABLE arc_bas1.mod_table_metier AS "); query.append("SELECT 'DSN' as id_famille,'mapping_dsn_test1_ok' as nom_table_metier UNION ALL "); query.append("SELECT 'PASRAU' as id_famille,'mapping_pasrau_test_ok' as nom_table_metier"); query.append(SQL.END_QUERY); + query.append("CREATE TABLE arc_bas1.mod_variable_metier AS SELECT 'DSN' as id_famille, 'mapping_dsn_test1_ok' as nom_table_metier, 'id_source' as nom_variable_metier"); + query.append(SQL.END_QUERY); + + // pilotage tables query.append("CREATE TABLE arc_bas1.pilotage_fichier AS "); query.append("SELECT 'file_to_retrieve.xml' as id_source, 'PHASE3V1' as id_norme, '2023-10-01' as validite,'M' as periodicite"); query.append(", 'MAPPING' as phase_traitement, '{OK}'::text[] as etat_traitement, '2023-11-30 10:29:47.000'::timestamp as date_traitement"); @@ -222,15 +295,26 @@ private void initializeTestData() throws SQLException, ArcException { query.append(", '{ARTEMIS}'::text[] as client, '{2023-11-30 10:29:47.000}'::timestamp[] as date_client");; query.append(SQL.END_QUERY); + // norme table used to retrieve family of data query.append("CREATE TABLE arc_bas1.norme AS "); query.append("SELECT 'PHASE3V1' as id_norme, 'DSN' as id_famille UNION ALL "); query.append("SELECT 'PASRAU' as id_norme, 'PASRAU' as id_famille"); query.append(SQL.END_QUERY); + // data tables containing two files + // one had already been retrieved by client 'ARTEMIS', the other hadn't been retrieved yet query.append("CREATE TABLE arc_bas1.mapping_dsn_test1_ok AS "); query.append("SELECT 'file_to_retrieve.xml' as id_source, 'data_of_file_to_retrieve' as data UNION ALL "); query.append("SELECT 'file_not_to_retrieve_when_reprise_false.xml' as id_source, 'data_of_file_not_to_retrieve_when_reprise_false' as data"); query.append(SQL.END_QUERY); + + // nomenclature tables + query.append("CREATE TABLE arc_bas1.nmcl_table1 AS SELECT 1 as data"); + query.append(SQL.END_QUERY); + query.append("CREATE TABLE arc_bas1.nmcl_table2 AS SELECT 1 as data"); + query.append(SQL.END_QUERY); + query.append("CREATE TABLE arc.ext_mod_periodicite AS SELECT 1 as id, 'A' as VAL"); + query.append(SQL.END_QUERY); UtilitaireDao.get(0).executeImmediate(c, query); }