From 2bf87bd7f35d02d1d161d79a3a496fed74f4ba7a Mon Sep 17 00:00:00 2001 From: Manuel Soulier Date: Mon, 4 Dec 2023 12:20:32 +0100 Subject: [PATCH] feat: wsimport data sample externalization --- .../importServlet/ImportStep1KoTest.java | 98 +--------------- .../importServlet/ImportStep1OkTest.java | 100 +--------------- .../dao/InitializeTestDataNoScalability.java | 109 ++++++++++++++++++ 3 files changed, 117 insertions(+), 190 deletions(-) create mode 100644 arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/InitializeTestDataNoScalability.java diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportStep1KoTest.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportStep1KoTest.java index 11637554a..94bc45a86 100644 --- a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportStep1KoTest.java +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportStep1KoTest.java @@ -17,6 +17,7 @@ import fr.insee.arc.utils.query.InitializeQueryTest; import fr.insee.arc.ws.services.importServlet.actions.SendResponse; import fr.insee.arc.ws.services.importServlet.bo.ExportTrackingType; +import fr.insee.arc.ws.services.importServlet.dao.InitializeTestDataNoScalability; public class ImportStep1KoTest extends ServletArc { @@ -26,16 +27,13 @@ public class ImportStep1KoTest extends ServletArc { @BeforeClass public static void setup() throws SQLException, ArcException { - - InitializeQueryTest.buildPropertiesWithoutScalability(null); - - destroyTestData(); - initializeTestData(); + InitializeTestDataNoScalability.destroyTestData(); + InitializeTestDataNoScalability.initializeTestData(false); } @AfterClass public static void tearDown() throws SQLException, ArcException { - destroyTestData(); + InitializeTestDataNoScalability.destroyTestData(); } private String executeImportStep1(JSONObject clientJsonInput) throws ArcException @@ -88,93 +86,5 @@ private void testRegisterWsKo(String arcResponse) throws ArcException { UtilitaireDao.get(0).hasResults(InitializeQueryTest.c, query); } - - /** - * initialize data for the tests - * @throws SQLException - * @throws ArcException - */ - private static void initializeTestData() throws SQLException, ArcException { - - ArcPreparedStatementBuilder query; - - query = new ArcPreparedStatementBuilder(); - - 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); - - // table variable_metier doesn't exists, it will crash - - // 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"); - query.append(", null::text[] as client, null::timestamp[] as date_client"); - query.append(" UNION ALL "); - // file that mustn't be retrieved when reprise is false and family is DSN - query.append("SELECT 'file_not_to_retrieve_when_reprise_false.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"); - 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(InitializeQueryTest.c, query); - } - - - - /** - * destroy data for the tests - * @throws SQLException - * @throws ArcException - */ - private static void destroyTestData() throws SQLException, ArcException { - - ArcPreparedStatementBuilder query; - - query = new ArcPreparedStatementBuilder(); - - query.append("DROP SCHEMA IF EXISTS arc CASCADE;"); - query.append("DROP SCHEMA IF EXISTS arc_bas1 CASCADE;"); - UtilitaireDao.get(0).executeImmediate(InitializeQueryTest.c, query); - } - - - } diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportStep1OkTest.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportStep1OkTest.java index 470d672b2..0b9f0eed5 100644 --- a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportStep1OkTest.java +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportStep1OkTest.java @@ -16,6 +16,7 @@ import fr.insee.arc.utils.exception.ArcException; import fr.insee.arc.utils.query.InitializeQueryTest; import fr.insee.arc.ws.services.importServlet.actions.SendResponse; +import fr.insee.arc.ws.services.importServlet.dao.InitializeTestDataNoScalability; public class ImportStep1OkTest extends ServletArc { @@ -24,16 +25,14 @@ public class ImportStep1OkTest extends ServletArc { @BeforeClass public static void setup() throws SQLException, ArcException { - - InitializeQueryTest.buildPropertiesWithoutScalability(null); - destroyTestData(); - initializeTestData(); + InitializeTestDataNoScalability.destroyTestData(); + InitializeTestDataNoScalability.initializeTestData(true); } @AfterClass public static void tearDown() throws SQLException, ArcException { - destroyTestData(); + InitializeTestDataNoScalability.destroyTestData(); } private String executeImportStep1(JSONObject clientJsonInput) throws ArcException @@ -114,96 +113,5 @@ private void testCreateTableTablePeriodicite() throws ArcException { // table image created should be like arc_bas1.ARTEMIS_timestamp_ assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_ext_mod_periodicite")); } - - - /** - * initialize data for the tests - * @throws SQLException - * @throws ArcException - */ - private static void initializeTestData() throws SQLException, ArcException { - - ArcPreparedStatementBuilder query; - query = new ArcPreparedStatementBuilder(); - - 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"); - query.append(SQL.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"); - query.append(SQL.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"); - query.append(", null::text[] as client, null::timestamp[] as date_client"); - query.append(SQL.UNION_ALL); - // file that mustn't be retrieved when reprise is false and family is DSN - query.append("SELECT 'file_not_to_retrieve_when_reprise_false.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"); - 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(InitializeQueryTest.c, query); - } - - - - /** - * destroy data for the tests - * @throws SQLException - * @throws ArcException - */ - private static void destroyTestData() throws SQLException, ArcException { - - ArcPreparedStatementBuilder query; - - query = new ArcPreparedStatementBuilder(); - - query.append("DROP SCHEMA IF EXISTS arc CASCADE;"); - query.append("DROP SCHEMA IF EXISTS arc_bas1 CASCADE;"); - UtilitaireDao.get(0).executeImmediate(InitializeQueryTest.c, query); - } - - - } diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/InitializeTestDataNoScalability.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/InitializeTestDataNoScalability.java new file mode 100644 index 000000000..113d0ced6 --- /dev/null +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/InitializeTestDataNoScalability.java @@ -0,0 +1,109 @@ +package fr.insee.arc.ws.services.importServlet.dao; + +import java.sql.SQLException; + +import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; +import fr.insee.arc.utils.dao.SQL; +import fr.insee.arc.utils.dao.UtilitaireDao; +import fr.insee.arc.utils.exception.ArcException; +import fr.insee.arc.utils.query.InitializeQueryTest; + +public class InitializeTestDataNoScalability { + + /** + * initialize the data sample for wsimport test + * @param ok : true mean that data will be valid, false that a table will be lacking + * @throws SQLException + * @throws ArcException + */ + public static void initializeTestData(boolean ok) throws SQLException, ArcException { + + InitializeQueryTest.buildPropertiesWithoutScalability(null); + + ArcPreparedStatementBuilder query; + query = new ArcPreparedStatementBuilder(); + 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"); + query.append(SQL.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"); + query.append(SQL.UNION_ALL); + query.append("SELECT 'PASRAU' as id_famille,'mapping_pasrau_test_ok' as nom_table_metier"); + query.append(SQL.END_QUERY); + + + if (!ok) + { + 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"); + query.append(", null::text[] as client, null::timestamp[] as date_client"); + query.append(SQL.UNION_ALL); + // file that mustn't be retrieved when reprise is false and family is DSN + query.append("SELECT 'file_not_to_retrieve_when_reprise_false.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"); + 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(InitializeQueryTest.c, query); + } + + + + /** + * destroy data for the tests + * @throws SQLException + * @throws ArcException + */ + public static void destroyTestData() throws SQLException, ArcException { + + ArcPreparedStatementBuilder query; + + query = new ArcPreparedStatementBuilder(); + + query.append("DROP SCHEMA IF EXISTS arc CASCADE;"); + query.append("DROP SCHEMA IF EXISTS arc_bas1 CASCADE;"); + UtilitaireDao.get(0).executeImmediate(InitializeQueryTest.c, query); + } + + + + +}