Skip to content

Commit

Permalink
feat: update siera functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
lmanelphe committed Oct 13, 2023
1 parent 0a15c82 commit 548c6e6
Showing 1 changed file with 109 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package fr.insee.arc.core.businesstest;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.junit.Rule;
import org.junit.Test;
Expand All @@ -22,191 +27,175 @@
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;

public class TestsFonctionnels extends InitializeQueryTest
{
public class TestsFonctionnels extends InitializeQueryTest {

@Rule
public TemporaryFolder testFolder= new TemporaryFolder();
public TemporaryFolder testFolder = new TemporaryFolder();

@Test
public void executeFunctionnalTests() throws IOException, SQLException, ArcException {
BddPatcherTest.createDatabase();


File root=testFolder.newFolder("root");
File root = testFolder.newFolder("root");
String repertoire = root.getAbsolutePath();

buildPropertiesWithoutScalability(repertoire);

executeTestSirene("arc_bas1", repertoire);

executeTestSiera("arc_bas2", repertoire);

executeTestAnimal("arc_bas8", repertoire);


}





/**
* COVERAGE
* complex xml load test
* COVERAGE complex xml load test
*
* @param sandbox
* @param repertoire
* @throws IOException
* @throws ArcException
* @throws SQLException
*/
private void executeTestSirene(String sandbox, String repertoire) throws IOException, ArcException, SQLException
{
private void executeTestSirene(String sandbox, String repertoire) throws IOException, ArcException, SQLException {
BddPatcherTest.insertTestDataSirene();


ApiServiceFactory.getService(TraitementPhase.INITIALISATION, sandbox, repertoire,
10000000, null
).invokeApi();

String repertoireDeDepot = DirectoryPath.directoryReceptionEntrepot(repertoire, sandbox, DataWarehouse.DEFAULT.getName());

Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/Cas_test_V2008.11.zip"), new File(repertoireDeDepot, "Cas_test_V2008.11.zip").toPath());
Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/Cas_test_V2016.02.zip"), new File(repertoireDeDepot, "Cas_test_V2016.02.zip").toPath());

ApiServiceFactory.getService(TraitementPhase.RECEPTION, sandbox, repertoire,
10000000, null
).invokeApi();


ApiServiceFactory.getService(TraitementPhase.INITIALISATION, sandbox, repertoire, 10000000, null).invokeApi();

String repertoireDeDepot = DirectoryPath.directoryReceptionEntrepot(repertoire, sandbox,
DataWarehouse.DEFAULT.getName());

Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/Cas_test_V2008.11.zip"),
new File(repertoireDeDepot, "Cas_test_V2008.11.zip").toPath());
Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/Cas_test_V2016.02.zip"),
new File(repertoireDeDepot, "Cas_test_V2016.02.zip").toPath());

ApiServiceFactory.getService(TraitementPhase.RECEPTION, sandbox, repertoire, 10000000, null).invokeApi();

assertEquals(114, nbFileInPhase(sandbox, TraitementPhase.RECEPTION, TraitementEtat.OK));

ApiServiceFactory.getService(TraitementPhase.CHARGEMENT, sandbox, repertoire,
10000000, null
).invokeApi();

ApiServiceFactory.getService(TraitementPhase.CHARGEMENT, sandbox, repertoire, 10000000, null).invokeApi();
assertEquals(114, nbFileInPhase(sandbox, TraitementPhase.CHARGEMENT, TraitementEtat.OK));

ApiServiceFactory.getService(TraitementPhase.NORMAGE, sandbox, repertoire,
10000000, null
).invokeApi();
ApiServiceFactory.getService(TraitementPhase.NORMAGE, sandbox, repertoire, 10000000, null).invokeApi();
assertEquals(114, nbFileInPhase(sandbox, TraitementPhase.NORMAGE, TraitementEtat.OK));

ApiServiceFactory.getService(TraitementPhase.CONTROLE, sandbox, repertoire,
10000000, null
).invokeApi();

ApiServiceFactory.getService(TraitementPhase.CONTROLE, sandbox, repertoire, 10000000, null).invokeApi();
assertEquals(47, nbFileInPhase(sandbox, TraitementPhase.CONTROLE, TraitementEtat.OK));

}

/**
* COVERAGE
* xml load test
* normage complexe rule test
* filtering controle rule test
* complex mapping rules test
* COVERAGE xml load test normage complexe rule test filtering controle rule
* test complex mapping rules test
*
* @param sandbox
* @param repertoire
* @throws IOException
* @throws ArcException
* @throws SQLException
*/
private void executeTestSiera(String sandbox, String repertoire) throws IOException, ArcException, SQLException
{
private void executeTestSiera(String sandbox, String repertoire) throws IOException, ArcException, SQLException {
BddPatcherTest.insertTestDataSiera();

ApiServiceFactory.getService(TraitementPhase.INITIALISATION, sandbox, repertoire,
10000000, null
).invokeApi();

String repertoireDeDepot = DirectoryPath.directoryReceptionEntrepot(repertoire, sandbox, DataWarehouse.DEFAULT.getName());

Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/siera_ano.xml"), new File(repertoireDeDepot, "siera_ano.xml").toPath());

ApiServiceFactory.getService(TraitementPhase.RECEPTION, sandbox, repertoire,
10000000, null
).invokeApi();


ApiServiceFactory.getService(TraitementPhase.INITIALISATION, sandbox, repertoire, 10000000, null).invokeApi();

String repertoireDeDepot = DirectoryPath.directoryReceptionEntrepot(repertoire, sandbox,
DataWarehouse.DEFAULT.getName());

Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/siera_ano.xml"),
new File(repertoireDeDepot, "siera_ano.xml").toPath());

ApiServiceFactory.getService(TraitementPhase.RECEPTION, sandbox, repertoire, 10000000, null).invokeApi();

assertEquals(1, nbFileInPhase(sandbox, TraitementPhase.RECEPTION, TraitementEtat.OK));

ApiServiceFactory.getService(TraitementPhase.CHARGEMENT, sandbox, repertoire,
10000000, null
).invokeApi();

ApiServiceFactory.getService(TraitementPhase.CHARGEMENT, sandbox, repertoire, 10000000, null).invokeApi();
assertEquals(1, nbFileInPhase(sandbox, TraitementPhase.CHARGEMENT, TraitementEtat.OK));

ApiServiceFactory.getService(TraitementPhase.NORMAGE, sandbox, repertoire,
10000000, null
).invokeApi();
ApiServiceFactory.getService(TraitementPhase.NORMAGE, sandbox, repertoire, 10000000, null).invokeApi();
assertEquals(1, nbFileInPhase(sandbox, TraitementPhase.NORMAGE, TraitementEtat.OK));

ApiServiceFactory.getService(TraitementPhase.CONTROLE, sandbox, repertoire,
10000000, null
).invokeApi();

ApiServiceFactory.getService(TraitementPhase.CONTROLE, sandbox, repertoire, 10000000, null).invokeApi();
assertEquals(1, nbFileInPhase(sandbox, TraitementPhase.CONTROLE, TraitementEtat.OK));

ApiServiceFactory.getService(TraitementPhase.MAPPING, sandbox, repertoire,
10000000, null
).invokeApi();
ApiServiceFactory.getService(TraitementPhase.MAPPING, sandbox, repertoire, 10000000, null).invokeApi();
assertEquals(1, nbFileInPhase(sandbox, TraitementPhase.MAPPING, TraitementEtat.OK));


// test on data
ArcPreparedStatementBuilder query = new ArcPreparedStatementBuilder();
query.build(SQL.SELECT, "typrem", SQL.FROM, sandbox, ".mapping_dsn_remuneration_ok");
Map<String, List<String>> dsnRemunerationRecords = new GenericBean(
UtilitaireDao.get(0).executeRequest(c, query)).mapContent();
List<String> expectedRecords = new ArrayList<String>();
expectedRecords.add("{REM001,REM002,REM003,REM022,PRI027,PRI028,VFV,VPE,BAS02,BAS03,BAS03,BAS48}");
expectedRecords.add("{REM001,REM003,REM010,PRI027,PRI028,VFV,VPE,BAS02,BAS03,BAS03,BAS48}");
expectedRecords.add("{REM010,REM012,REM013,REM014,ARV04,ARV06,VFV,VPE,BAS02,BAS03,BAS04,BAS14}");
expectedRecords.add("{REM001,REM002,ARV04,ARV06,VFV,VPE,BAS02,BAS03,BAS04,BAS14}");
expectedRecords.add("{REM001,REM002,ARV04,ARV06,VFV,VPE,BAS12,BAS13}");
expectedRecords.add("{REM002,REM003,REM010,REM012,REM001,ARV04,ARV06,VFV,VPE,BAS12,BAS13}");
expectedRecords.add("{REM001,REM002,REM003,REM010,VFV,VPE,BAS02,BAS23}");
expectedRecords.add("{VFV,VPE,BAS02,BAS23}");
expectedRecords.add("{REM001,REM002,ARV06,VFV,VPE,BAS17,BAS18}");
expectedRecords.add("{ARV06,VFV,VPE,BAS17,BAS18}");
expectedRecords.add("{ARV04,ARV17,VFV,VPE,BAS02,BAS03,BAS14}");
expectedRecords.add("{REM020,REM025,REM026,ARV04,ARV17,VFV,VPE,BAS02,BAS03,BAS14}");
Collections.sort(expectedRecords);

List<String> queryResults = dsnRemunerationRecords.get("typrem");
Collections.sort(queryResults);

assertArrayEquals(expectedRecords.toArray(), queryResults.toArray());

}

/**
* COVERAGE
* simple csv file load test
* tar.gz load test
* doublon detection test
* COVERAGE simple csv file load test tar.gz load test doublon detection test
*
* @param sandbox
* @param repertoire
* @throws IOException
* @throws ArcException
* @throws SQLException
*/
private void executeTestAnimal(String sandbox, String repertoire) throws IOException, ArcException, SQLException
{
private void executeTestAnimal(String sandbox, String repertoire) throws IOException, ArcException, SQLException {
BddPatcherTest.insertTestDataAnimal();

ApiServiceFactory.getService(TraitementPhase.INITIALISATION, sandbox, repertoire,
10000000, null
).invokeApi();

String repertoireDeDepot = DirectoryPath.directoryReceptionEntrepot(repertoire, sandbox, DataWarehouse.DEFAULT.getName());

Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/animals.tar.gz"), new File(repertoireDeDepot, "animals.tar.gz").toPath());

ApiServiceFactory.getService(TraitementPhase.RECEPTION, sandbox, repertoire,
10000000, null
).invokeApi();


ApiServiceFactory.getService(TraitementPhase.INITIALISATION, sandbox, repertoire, 10000000, null).invokeApi();

String repertoireDeDepot = DirectoryPath.directoryReceptionEntrepot(repertoire, sandbox,
DataWarehouse.DEFAULT.getName());

Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/animals.tar.gz"),
new File(repertoireDeDepot, "animals.tar.gz").toPath());

ApiServiceFactory.getService(TraitementPhase.RECEPTION, sandbox, repertoire, 10000000, null).invokeApi();

assertEquals(2, nbFileInPhase(sandbox, TraitementPhase.RECEPTION, TraitementEtat.OK));

ApiServiceFactory.getService(TraitementPhase.CHARGEMENT, sandbox, repertoire,
10000000, null
).invokeApi();

ApiServiceFactory.getService(TraitementPhase.CHARGEMENT, sandbox, repertoire, 10000000, null).invokeApi();
assertEquals(2, nbFileInPhase(sandbox, TraitementPhase.CHARGEMENT, TraitementEtat.OK));



// doublon detection test
Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/animals-001.csv"), new File(repertoireDeDepot, "animals-001.csv").toPath());
Files.copy(this.getClass().getClassLoader().getResourceAsStream("testFiles/animals-001.csv"),
new File(repertoireDeDepot, "animals-001.csv").toPath());

ApiServiceFactory.getService(TraitementPhase.RECEPTION, sandbox, repertoire, 10000000, null).invokeApi();

ApiServiceFactory.getService(TraitementPhase.RECEPTION, sandbox, repertoire,
10000000, null
).invokeApi();

assertEquals(1, nbFileInPhase(sandbox, TraitementPhase.RECEPTION, TraitementEtat.KO));

}

private int nbFileInPhase(String sandbox, TraitementPhase phase, TraitementEtat etat)
{
ArcPreparedStatementBuilder query=new ArcPreparedStatementBuilder();
query.build(SQL.SELECT, "count(*)", SQL.FROM, sandbox, ".", "pilotage_fichier", SQL.WHERE, "phase_traitement=", query.quoteText(phase.toString()), SQL.AND, "etat_traitement=", query.quoteText(etat.getSqlArrayExpression()), "::text[]");


private int nbFileInPhase(String sandbox, TraitementPhase phase, TraitementEtat etat) {
ArcPreparedStatementBuilder query = new ArcPreparedStatementBuilder();
query.build(SQL.SELECT, "count(*)", SQL.FROM, sandbox, ".", "pilotage_fichier", SQL.WHERE, "phase_traitement=",
query.quoteText(phase.toString()), SQL.AND, "etat_traitement=",
query.quoteText(etat.getSqlArrayExpression()), "::text[]");

return UtilitaireDao.get(0).getInt(c, query);
}


}

0 comments on commit 548c6e6

Please sign in to comment.