From 548c6e6a40f03786341b61a8a5093a7f1dc88a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Manelphe?= Date: Fri, 13 Oct 2023 17:43:36 +0200 Subject: [PATCH] feat: update siera functional test --- .../core/businesstest/TestsFonctionnels.java | 229 +++++++++--------- 1 file changed, 109 insertions(+), 120 deletions(-) diff --git a/arc-core/src/test/java/fr/insee/arc/core/businesstest/TestsFonctionnels.java b/arc-core/src/test/java/fr/insee/arc/core/businesstest/TestsFonctionnels.java index 0399b6c40..fc3a29556 100644 --- a/arc-core/src/test/java/fr/insee/arc/core/businesstest/TestsFonctionnels.java +++ b/arc-core/src/test/java/fr/insee/arc/core/businesstest/TestsFonctionnels.java @@ -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; @@ -22,39 +27,32 @@ 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 @@ -62,50 +60,37 @@ public void executeFunctionnalTests() throws IOException, SQLException, ArcExcep * @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 @@ -113,51 +98,62 @@ private void executeTestSirene(String sandbox, String repertoire) throws IOExcep * @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> dsnRemunerationRecords = new GenericBean( + UtilitaireDao.get(0).executeRequest(c, query)).mapContent(); + List expectedRecords = new ArrayList(); + 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 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 @@ -165,48 +161,41 @@ private void executeTestSiera(String sandbox, String repertoire) throws IOExcept * @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); } - }