From eaa78af3799b4a5eea285f5c4afc590a3acdc9a9 Mon Sep 17 00:00:00 2001 From: Manuel Soulier Date: Mon, 4 Dec 2023 12:54:06 +0100 Subject: [PATCH] feat: test wsimport step 2 --- .../services/importServlet/ImportOKTest.java | 35 +++++++++++++++++-- .../dao/InitializeTestDataNoScalability.java | 6 ++-- 2 files changed, 36 insertions(+), 5 deletions(-) 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/ImportOKTest.java index 5d1ac9862..f293712e4 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/ImportOKTest.java @@ -1,5 +1,6 @@ package fr.insee.arc.ws.services.importServlet; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; @@ -41,6 +42,16 @@ private String executeImportStep1(JSONObject clientJsonInput) throws ArcExceptio return sentResponse.getWr().toString(); } + private String executeImportStep2(JSONObject clientJsonInput) throws ArcException + { + JSONObject clientJsonInputValidated= validateRequest(clientJsonInput); + ImportStep2GetTableNameService imp = new ImportStep2GetTableNameService(clientJsonInputValidated); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + SendResponse sentResponse = new SendResponse(bos); + imp.execute(sentResponse); + return sentResponse.getWr().toString(); + } + @Test(expected = ArcException.class) public void testExecuteFamilyNotValid() throws ArcException { @@ -53,10 +64,12 @@ public void testExecuteFamilyNotValid() throws ArcException { @Test public void testExecute() throws ArcException { - JSONObject clientJsonInput = new JSONObject( + // 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\"}"); - executeImportStep1(clientJsonInput); + // response token will be used by client to invoke step2 + String arcResponseStep1 = executeImportStep1(clientJsonInputStep1); testCreateAndDropWsPending(); testCreateTableNmcl(); @@ -64,6 +77,24 @@ public void testExecute() throws ArcException { testCreateTableTableMetier(); testCreateTableTableFamille(); testCreateTableTablePeriodicite(); + + // 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\"}"); + + String arcResponseStep2 = executeImportStep2(clientJsonInputStep2); + + // ws info must be the first table to be retrieved + // token must return name of the table and the ddl of the table + assertEquals(arcResponseStep1+"_ws_info client text, timestamp text", arcResponseStep2); + + +// JSONObject clientJsonInputStep1 = new JSONObject( +// "{\"familleNorme\":\"DSN\",\"periodicite\":\"M\",\"service\":\"arcClient\",\"validiteSup\":\"2032-03-01\",\"format\":\"csv_gzip\",\"reprise\":false,\"client\":\"ARTEMIS\",\"environnement\":\"arc_bas1\"}"); +// + + } private void testCreateAndDropWsPending() throws ArcException { 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 c6548614f..be1637e3e 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 @@ -12,11 +12,11 @@ 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 + * @param dataSampleOk : true mean that data sample will be valid, false that a table will be lacking * @throws SQLException * @throws ArcException */ - public static void initializeTestData(boolean ok) throws SQLException, ArcException { + public static void initializeTestData(boolean dataSampleOk) throws SQLException, ArcException { ArcPreparedStatementBuilder query; query = new ArcPreparedStatementBuilder(); @@ -41,7 +41,7 @@ public static void initializeTestData(boolean ok) throws SQLException, ArcExcept query.append(SQL.END_QUERY); - if (ok) + if (dataSampleOk) { 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);