From 53e347cbecaff84858089a938a90bef4dee65c28 Mon Sep 17 00:00:00 2001 From: Manuel Soulier Date: Wed, 6 Dec 2023 08:09:51 +0100 Subject: [PATCH] feat: better test mechanics for wsimport --- .../importServlet/ExpectedResults.java | 22 +++ .../ImportOKNoScalabilityTest.java | 52 ++++++ .../ImportOKScalabilityTest.java | 158 ++---------------- .../{ImportOKTest.java => RunImport.java} | 84 ++++------ .../importServlet/bo/RetrievedTable.java | 40 +++++ .../dao/InitializeTestDataNoScalability.java | 17 +- .../dao/InitializeTestDataScalability.java | 30 +++- 7 files changed, 196 insertions(+), 207 deletions(-) create mode 100644 arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ExpectedResults.java create mode 100644 arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKNoScalabilityTest.java rename arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/{ImportOKTest.java => RunImport.java} (73%) create mode 100644 arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/bo/RetrievedTable.java diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ExpectedResults.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ExpectedResults.java new file mode 100644 index 000000000..5dae150ce --- /dev/null +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ExpectedResults.java @@ -0,0 +1,22 @@ +package fr.insee.arc.ws.services.importServlet; + +import java.util.Arrays; +import java.util.List; + +import fr.insee.arc.ws.services.importServlet.bo.RetrievedTable; + +public class ExpectedResults { + + + public static final List EXPECTED_RETRIEVED_TABLES = Arrays.asList( + new RetrievedTable("ws_info", 1, "ARTEMIS") + ,new RetrievedTable("mapping_dsn_test1_ok", 2, "file1_to_retrieve.xml") + ,new RetrievedTable("mod_table_metier", 1, "DSN") + ,new RetrievedTable("mod_variable_metier", 1, "DSN") + ,new RetrievedTable("nmcl_table1", 1, "data1") + ,new RetrievedTable("nmcl_table2", 1, "data2") + ,new RetrievedTable("ext_mod_famille", 1, "DSN") + ,new RetrievedTable("ext_mod_periodicite", 1, "1") + ); + +} diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKNoScalabilityTest.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKNoScalabilityTest.java new file mode 100644 index 000000000..3f43045c3 --- /dev/null +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKNoScalabilityTest.java @@ -0,0 +1,52 @@ +package fr.insee.arc.ws.services.importServlet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; +import java.sql.SQLException; +import java.util.zip.GZIPInputStream; + +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; +import fr.insee.arc.utils.dao.UtilitaireDao; +import fr.insee.arc.utils.exception.ArcException; +import fr.insee.arc.utils.query.InitializeQueryTest; +import fr.insee.arc.utils.utils.ManipString; +import fr.insee.arc.ws.services.importServlet.bo.ExecuteStep; +import fr.insee.arc.ws.services.importServlet.dao.InitializeTestDataNoScalability; + +public class ImportOKNoScalabilityTest { + + @BeforeClass + public static void setup() throws SQLException, ArcException { + InitializeTestDataNoScalability.destroyTestData(); + InitializeTestDataNoScalability.initializeTestData(true); + } + + @AfterClass + public static void tearDown() throws SQLException, ArcException { + InitializeTestDataNoScalability.destroyTestData(); + } + + @Test(expected = ArcException.class) + public void testExecuteFamilyNotValid() throws ArcException, UnsupportedEncodingException { + RunImport.testExecuteFamilyNotValid(); + } + + @Test + public void testExecute() throws ArcException, IOException { + RunImport.testExecute(); + } + +} diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKScalabilityTest.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKScalabilityTest.java index 2a698f0a9..48ce2b204 100644 --- a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKScalabilityTest.java +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKScalabilityTest.java @@ -10,6 +10,8 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; import java.util.zip.GZIPInputStream; import org.apache.commons.io.IOUtils; @@ -22,8 +24,10 @@ import fr.insee.arc.utils.dao.UtilitaireDao; import fr.insee.arc.utils.exception.ArcException; import fr.insee.arc.utils.query.InitializeQueryTest; +import fr.insee.arc.utils.structure.GenericBean; import fr.insee.arc.utils.utils.ManipString; import fr.insee.arc.ws.services.importServlet.bo.ExecuteStep; +import fr.insee.arc.ws.services.importServlet.bo.RetrievedTable; import fr.insee.arc.ws.services.importServlet.dao.InitializeTestDataScalability; public class ImportOKScalabilityTest { @@ -39,155 +43,15 @@ public static void tearDown() throws SQLException, ArcException { InitializeTestDataScalability.destroyTestData(); } - @Test - public void testExecute() throws ArcException, IOException { - - // parameters sent by client for step 1 - JSONObject clientJsonInputStep1 = new JSONObject( - "{\"familleNorme\":\"DSN\",\"periodicite\":\"M\",\"service\":\"arcClient\",\"validiteSup\":\"2032-03-01\",\"format\":\"csv_gzip\",\"reprise\":false,\"client\":\"ARTEMIS\",\"environnement\":\"arc_bas1\"}"); - - // response token will be used by client to invoke step2 - String arcResponseStep1 = ExecuteStep.executeImportStep1(clientJsonInputStep1); - - testCreateAndDropWsPending(); - testCreateTableNmcl(); - testCreateTableVarMetier(); - testCreateTableTableMetier(); - testCreateTableTableFamille(); - testCreateTableTablePeriodicite(); - - // test ws Iteration - testWsIteration(arcResponseStep1); - - // test that client had been marked in pilotage - testClientMarkedInPilotage(); - + @Test(expected = ArcException.class) + public void testExecuteFamilyNotValid() throws ArcException, UnsupportedEncodingException { + RunImport.testExecuteFamilyNotValid(); } - private void testClientMarkedInPilotage() throws ArcException { - ArcPreparedStatementBuilder query = new ArcPreparedStatementBuilder(); - - query.append("SELECT client[1] as client from arc_bas1.pilotage_fichier where id_source = 'file_to_retrieve.xml';"); - - String clientMarkedInPilotage = UtilitaireDao.get(0).getString(null, query); - - assertEquals("ARTEMIS", clientMarkedInPilotage); - - // "ws_info", "mapping_dsn_test1_ok", "mod_table_metier", "mod_variable_metier", "nmcl_table1", "nmcl_table2", "ext_mod_famille", "ext_mod_periodicite" - - } - - /** - * iterate through webservice call until the end - * test the first table to be retrieved - * @param arcResponseStep1 - * @throws IOException - * @throws ArcException - */ - private void testWsIteration(String arcResponseStep1) throws IOException, ArcException { - boolean sortie = false; - boolean first = true; - - do { - String arcResponseStep2 = invokeStep2(arcResponseStep1); - // arcResponse2 return table,ame and DDL of the table - // tablename is the first token from the arcResponse2 - String tableBucket = ManipString.substringBeforeFirst(arcResponseStep2, " "); - - sortie = tableBucket.equals(""); - - if (sortie) - { - break; - } - - ByteArrayOutputStream arcResponseStep3 = invokeStep3(tableBucket); - String outputStep3 = ""; - - try (InputStream is = new ByteArrayInputStream(arcResponseStep3.toByteArray()); - GZIPInputStream zis = new GZIPInputStream(is);) { - outputStep3 = IOUtils.toString(zis, StandardCharsets.UTF_8); - } - - if (first) { - // ws info must be the first table to be retrieved - assertEquals(arcResponseStep1 + "_ws_info client text, timestamp text", arcResponseStep2); - // first info in the csv table of ws_info is client name - assertEquals("ARTEMIS", ManipString.substringBeforeFirst(outputStep3, ";")); - } - - first=false; - - } while (!sortie); - - } - - private ByteArrayOutputStream invokeStep3(String tableResponseStep2) - throws UnsupportedEncodingException, ArcException { - JSONObject clientJsonInputStep3 = new JSONObject( - "{\"familleNorme\":\"DSN\",\"periodicite\":\"M\",\"service\":\"tableName\",\"validiteSup\":\"2032-03-01\",\"format\":\"csv_gzip\",\"reprise\":false,\"client\":\"" - + tableResponseStep2 - + "\",\"environnement\":\"arc_bas1\",\"type\":\"jsonwsp/request\"}"); - return ExecuteStep.executeImportStep3(clientJsonInputStep3); - } - - private String invokeStep2(String arcResponseStep1) throws UnsupportedEncodingException, ArcException { - // parameters sent by client for step 2 - // it use response token provided as response of step1 - JSONObject clientJsonInputStep2 = new JSONObject( - "{\"familleNorme\":\"DSN\",\"periodicite\":\"M\",\"service\":\"tableName\",\"validiteSup\":\"2032-03-01\",\"format\":\"csv_gzip\",\"reprise\":false,\"client\":\"" - + arcResponseStep1 + "\",\"environnement\":\"arc_bas1\",\"type\":\"jsonwsp/request\"}"); - - return ExecuteStep.executeImportStep2(clientJsonInputStep2); - } - - private void testCreateAndDropWsPending() throws ArcException { - - // check that the parallel thread that create tables drop the table ws_pending - - // it should be done in less than 50 iteration, test data is very little - int maxIteration = 50; - int i = 0; - - while (i < maxIteration - && UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_ws_pending")) { - i++; - UtilitaireDao.get(0).executeImmediate(InitializeQueryTest.c, "SELECT pg_sleep(1);"); - } - - assertTrue(i > 0); - assertTrue(i < maxIteration); - } - - private void testCreateTableNmcl() throws ArcException { - // table image created should be like - // arc_bas1.ARTEMIS_timestamp_ - assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_nmcl_table1")); - assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_nmcl_table2")); - } - - private void testCreateTableVarMetier() throws ArcException { - // table image created should be like - // arc_bas1.ARTEMIS_timestamp_ - assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_mod_variable_metier")); - } - - private void testCreateTableTableMetier() throws ArcException { - // table image created should be like - // arc_bas1.ARTEMIS_timestamp_ - assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_mod_table_metier")); - } - - private void testCreateTableTableFamille() throws ArcException { - // table image created should be like - // arc_bas1.ARTEMIS_timestamp_ - assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_ext_mod_famille")); - } - - 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")); + @Test + public void testExecute() throws ArcException, IOException { + RunImport.testExecute(); } + } diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKTest.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/RunImport.java similarity index 73% rename from arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKTest.java rename to arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/RunImport.java index 3555cd0a6..1a0c74954 100644 --- a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/ImportOKTest.java +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/RunImport.java @@ -9,14 +9,10 @@ import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; -import java.sql.SQLException; import java.util.zip.GZIPInputStream; import org.apache.commons.io.IOUtils; import org.json.JSONObject; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; import fr.insee.arc.utils.dao.UtilitaireDao; @@ -24,30 +20,17 @@ import fr.insee.arc.utils.query.InitializeQueryTest; import fr.insee.arc.utils.utils.ManipString; import fr.insee.arc.ws.services.importServlet.bo.ExecuteStep; -import fr.insee.arc.ws.services.importServlet.dao.InitializeTestDataNoScalability; -public class ImportOKTest { +public class RunImport { - @BeforeClass - public static void setup() throws SQLException, ArcException { - InitializeTestDataNoScalability.destroyTestData(); - InitializeTestDataNoScalability.initializeTestData(true); - } - - @AfterClass - public static void tearDown() throws SQLException, ArcException { - InitializeTestDataNoScalability.destroyTestData(); - } - - @Test(expected = ArcException.class) - public void testExecuteFamilyNotValid() throws ArcException, UnsupportedEncodingException { + public static void testExecuteFamilyNotValid() throws UnsupportedEncodingException, ArcException { JSONObject clientJsonInput = new JSONObject( "{\"familleNorme\":\"RESIL\",\"periodicite\":\"M\",\"service\":\"arcClient\",\"validiteSup\":\"2032-03-01\",\"format\":\"csv_gzip\",\"reprise\":false,\"client\":\"ARTEMIS\",\"environnement\":\"arc_bas1\"}"); ExecuteStep.executeImportStep1(clientJsonInput); } - - @Test - public void testExecute() throws ArcException, IOException { + + + public static void testExecute() throws ArcException, IOException { // parameters sent by client for step 1 JSONObject clientJsonInputStep1 = new JSONObject( @@ -65,33 +48,32 @@ public void testExecute() throws ArcException, IOException { // test ws Iteration testWsIteration(arcResponseStep1); - + // test that client had been marked in pilotage testClientMarkedInPilotage(); } - private void testClientMarkedInPilotage() throws ArcException { + private static void testClientMarkedInPilotage() throws ArcException { ArcPreparedStatementBuilder query = new ArcPreparedStatementBuilder(); - - query.append("SELECT client[1] as client from arc_bas1.pilotage_fichier where id_source = 'file_to_retrieve.xml';"); - + + query.append( + "SELECT distinct client[1] as client from arc_bas1.pilotage_fichier where id_source in ('file1_to_retrieve.xml','file2_to_retrieve.xml');"); + String clientMarkedInPilotage = UtilitaireDao.get(0).getString(null, query); - + assertEquals("ARTEMIS", clientMarkedInPilotage); - - // "ws_info", "mapping_dsn_test1_ok", "mod_table_metier", "mod_variable_metier", "nmcl_table1", "nmcl_table2", "ext_mod_famille", "ext_mod_periodicite" - } /** - * iterate through webservice call until the end - * test the first table to be retrieved + * iterate through webservice call until the end test the first table to be + * retrieved + * * @param arcResponseStep1 * @throws IOException * @throws ArcException */ - private void testWsIteration(String arcResponseStep1) throws IOException, ArcException { + private static void testWsIteration(String arcResponseStep1) throws IOException, ArcException { boolean sortie = false; boolean first = true; @@ -100,11 +82,10 @@ private void testWsIteration(String arcResponseStep1) throws IOException, ArcExc // arcResponse2 return table,ame and DDL of the table // tablename is the first token from the arcResponse2 String tableBucket = ManipString.substringBeforeFirst(arcResponseStep2, " "); - + sortie = tableBucket.equals(""); - - if (sortie) - { + + if (sortie) { break; } @@ -123,22 +104,21 @@ private void testWsIteration(String arcResponseStep1) throws IOException, ArcExc assertEquals("ARTEMIS", ManipString.substringBeforeFirst(outputStep3, ";")); } - first=false; - + first = false; + } while (!sortie); - + } - private ByteArrayOutputStream invokeStep3(String tableResponseStep2) + private static ByteArrayOutputStream invokeStep3(String tableResponseStep2) throws UnsupportedEncodingException, ArcException { JSONObject clientJsonInputStep3 = new JSONObject( "{\"familleNorme\":\"DSN\",\"periodicite\":\"M\",\"service\":\"tableName\",\"validiteSup\":\"2032-03-01\",\"format\":\"csv_gzip\",\"reprise\":false,\"client\":\"" - + tableResponseStep2 - + "\",\"environnement\":\"arc_bas1\",\"type\":\"jsonwsp/request\"}"); + + tableResponseStep2 + "\",\"environnement\":\"arc_bas1\",\"type\":\"jsonwsp/request\"}"); return ExecuteStep.executeImportStep3(clientJsonInputStep3); } - private String invokeStep2(String arcResponseStep1) throws UnsupportedEncodingException, ArcException { + private static String invokeStep2(String arcResponseStep1) throws UnsupportedEncodingException, ArcException { // parameters sent by client for step 2 // it use response token provided as response of step1 JSONObject clientJsonInputStep2 = new JSONObject( @@ -148,7 +128,7 @@ private String invokeStep2(String arcResponseStep1) throws UnsupportedEncodingEx return ExecuteStep.executeImportStep2(clientJsonInputStep2); } - private void testCreateAndDropWsPending() throws ArcException { + private static void testCreateAndDropWsPending() throws ArcException { // check that the parallel thread that create tables drop the table ws_pending @@ -166,35 +146,37 @@ private void testCreateAndDropWsPending() throws ArcException { assertTrue(i < maxIteration); } - private void testCreateTableNmcl() throws ArcException { + private static void testCreateTableNmcl() throws ArcException { // table image created should be like // arc_bas1.ARTEMIS_timestamp_ assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_nmcl_table1")); assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_nmcl_table2")); } - private void testCreateTableVarMetier() throws ArcException { + private static void testCreateTableVarMetier() throws ArcException { // table image created should be like // arc_bas1.ARTEMIS_timestamp_ assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_mod_variable_metier")); } - private void testCreateTableTableMetier() throws ArcException { + private static void testCreateTableTableMetier() throws ArcException { // table image created should be like // arc_bas1.ARTEMIS_timestamp_ assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_mod_table_metier")); } - private void testCreateTableTableFamille() throws ArcException { + private static void testCreateTableTableFamille() throws ArcException { // table image created should be like // arc_bas1.ARTEMIS_timestamp_ assertTrue(UtilitaireDao.get(0).isTableExiste(InitializeQueryTest.c, "arc_bas1.ARTEMIS_%_ext_mod_famille")); } - private void testCreateTableTablePeriodicite() throws ArcException { + private static 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")); } + + } diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/bo/RetrievedTable.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/bo/RetrievedTable.java new file mode 100644 index 000000000..5d78d56f3 --- /dev/null +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/bo/RetrievedTable.java @@ -0,0 +1,40 @@ +package fr.insee.arc.ws.services.importServlet.bo; + +public class RetrievedTable { + + private String tableName; + private int numberOfRecord; + private String firstValue; + + public RetrievedTable(String tableName, int numberOfRecord, String firstValue) { + super(); + this.tableName = tableName; + this.numberOfRecord = numberOfRecord; + this.firstValue = firstValue; + } + + public String getTableName() { + return tableName; + } + + public int getNumberOfRecord() { + return numberOfRecord; + } + + public String getFirstValue() { + return firstValue; + } + + @Override + public boolean equals(Object obj) { + + RetrievedTable obj2= (RetrievedTable) obj; + + return this.tableName.equals(obj2.getTableName()) + && this.numberOfRecord == obj2.getNumberOfRecord() + && this.firstValue.equals(obj2.getFirstValue()); + } + + + +} 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 index be1637e3e..bf500fe8f 100644 --- 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 @@ -49,7 +49,11 @@ public static void initializeTestData(boolean dataSampleOk) throws SQLException, // 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("SELECT 'file1_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); + query.append("SELECT 'file2_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); @@ -68,15 +72,20 @@ public static void initializeTestData(boolean dataSampleOk) throws SQLException, // 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 'file1_to_retrieve.xml' as id_source, 'data1_of_file_to_retrieve' as data"); + query.append(SQL.UNION_ALL); + query.append("SELECT 'file2_to_retrieve.xml' as id_source, 'data2_of_file_to_retrieve' as data"); + query.append(SQL.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("CREATE TABLE arc_bas1.nmcl_table1 AS SELECT 'data1' as data"); query.append(SQL.END_QUERY); - query.append("CREATE TABLE arc_bas1.nmcl_table2 AS SELECT 1 as data"); + + query.append("CREATE TABLE arc_bas1.nmcl_table2 AS SELECT 'data2' 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); diff --git a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/InitializeTestDataScalability.java b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/InitializeTestDataScalability.java index 1ec900c16..b33268d57 100644 --- a/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/InitializeTestDataScalability.java +++ b/arc-ws/src/test/java/fr/insee/arc/ws/services/importServlet/dao/InitializeTestDataScalability.java @@ -1,6 +1,8 @@ package fr.insee.arc.ws.services.importServlet.dao; import java.sql.SQLException; +import java.util.Arrays; +import java.util.List; import fr.insee.arc.core.dataobjects.ArcPreparedStatementBuilder; import fr.insee.arc.utils.dao.SQL; @@ -10,6 +12,7 @@ public class InitializeTestDataScalability { + /** * initialize the data sample for wsimport test * @param dataSampleOk : true mean that data sample will be valid, false that a table will be lacking @@ -48,17 +51,32 @@ public static void initializeTestData(boolean dataSampleOk) throws SQLException, } // 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"); + + // files on nod 1 + query.append("SELECT 'file1_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("SELECT 'file1_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(", '{ARTEMIS}'::text[] as client, '{2023-11-30 10:29:47.000}'::timestamp[] as date_client"); + + query.append(SQL.UNION_ALL); + // files on nod 2 + query.append("SELECT 'file2_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 'file2_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 "); @@ -66,10 +84,12 @@ public static void initializeTestData(boolean dataSampleOk) throws SQLException, query.append(SQL.END_QUERY); // nomenclature tables - query.append("CREATE TABLE arc_bas1.nmcl_table1 AS SELECT 1 as data"); + query.append("CREATE TABLE arc_bas1.nmcl_table1 AS SELECT 'data1' as data"); query.append(SQL.END_QUERY); - query.append("CREATE TABLE arc_bas1.nmcl_table2 AS SELECT 1 as data"); + + query.append("CREATE TABLE arc_bas1.nmcl_table2 AS SELECT 'data2' 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);