Skip to content

Commit

Permalink
feat: client dao tests on metadata tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Dec 1, 2023
1 parent f8f8898 commit be7587d
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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_<tablename_to_retrieve>
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_<tablename_to_retrieve>
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_<tablename_to_retrieve>
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_<tablename_to_retrieve>
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_<tablename_to_retrieve>
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<String> dataTableImages) throws ArcException {
TableToRetrieve registeredTable = clientDaoDsnStep1.getAClientTableByType(ExportTrackingType.DATA);

Expand Down Expand Up @@ -98,7 +161,7 @@ private List<String> testCreateImages(List<String> selectedDataTables) throws Ar

// only table with 1 id_source must had been retrieved
assertEquals(1, content.size());

return dataTableImages;

}
Expand All @@ -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());

}

/**
Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
Expand Down

0 comments on commit be7587d

Please sign in to comment.