diff --git a/src/test/java/com/mauvaisetroupe/eadesignit/service/importfile/ApplicationImportTest.java b/src/test/java/com/mauvaisetroupe/eadesignit/service/importfile/ApplicationImportTest.java index fd96dfe2..403d5cf3 100644 --- a/src/test/java/com/mauvaisetroupe/eadesignit/service/importfile/ApplicationImportTest.java +++ b/src/test/java/com/mauvaisetroupe/eadesignit/service/importfile/ApplicationImportTest.java @@ -9,10 +9,13 @@ import com.mauvaisetroupe.eadesignit.domain.ApplicationImport; import com.mauvaisetroupe.eadesignit.repository.ApplicationRepository; import com.mauvaisetroupe.eadesignit.service.importfile.dto.ErrorLineException; +import jakarta.transaction.Transactional; import java.io.IOException; import java.io.InputStream; import java.util.List; import org.apache.poi.EncryptedDocumentException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -25,6 +28,26 @@ public class ApplicationImportTest extends ImportFlowTest { @Autowired ApplicationRepository applicationRepository; + @AfterEach + @BeforeEach + @Transactional + public void clearDatabase() { + System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); + + //SELECT 'jdbcTemplate.execute("TRUNCATE TABLE ' || table_schema || '.' || table_name || ';");' AS sql_statement FROM information_schema.tables WHERE table_schema = 'PUBLIC' ORDER BY table_name; + jdbcTemplate.execute("SET REFERENTIAL_INTEGRITY FALSE"); + + List tableNames = getAllTableNames(); + + // Truncate tables in reverse order + for (int i = tableNames.size() - 1; i >= 0; i--) { + String tableName = tableNames.get(i); + String truncateQuery = "TRUNCATE TABLE " + tableName; + jdbcTemplate.execute(truncateQuery); + } + jdbcTemplate.execute("SET REFERENTIAL_INTEGRITY FALSE"); + } + @Test void testNullable() throws EncryptedDocumentException, IOException { ExcelReader excelReader = new ExcelReader(null); diff --git a/src/test/resources/junit/application_import/02-import-applications-name-changed.xlsx b/src/test/resources/junit/application_import/02-import-applications-name-changed.xlsx index ccc2093e..ed4146fb 100644 Binary files a/src/test/resources/junit/application_import/02-import-applications-name-changed.xlsx and b/src/test/resources/junit/application_import/02-import-applications-name-changed.xlsx differ