Skip to content

Commit

Permalink
feat: test wsimport step 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Dec 4, 2023
1 parent 0de2540 commit eaa78af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -53,17 +64,37 @@ 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();
testCreateTableVarMetier();
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit eaa78af

Please sign in to comment.