Skip to content

Commit cbadedd

Browse files
Application Import error management - Fix junit
1 parent 94bf4f4 commit cbadedd

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/test/java/com/mauvaisetroupe/eadesignit/service/importfile/ApplicationImportTest.java

+23
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
import com.mauvaisetroupe.eadesignit.domain.ApplicationImport;
1010
import com.mauvaisetroupe.eadesignit.repository.ApplicationRepository;
1111
import com.mauvaisetroupe.eadesignit.service.importfile.dto.ErrorLineException;
12+
import jakarta.transaction.Transactional;
1213
import java.io.IOException;
1314
import java.io.InputStream;
1415
import java.util.List;
1516
import org.apache.poi.EncryptedDocumentException;
17+
import org.junit.jupiter.api.AfterEach;
18+
import org.junit.jupiter.api.BeforeEach;
1619
import org.junit.jupiter.api.Test;
1720
import org.springframework.beans.factory.annotation.Autowired;
1821

@@ -25,6 +28,26 @@ public class ApplicationImportTest extends ImportFlowTest {
2528
@Autowired
2629
ApplicationRepository applicationRepository;
2730

31+
@AfterEach
32+
@BeforeEach
33+
@Transactional
34+
public void clearDatabase() {
35+
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
36+
37+
//SELECT 'jdbcTemplate.execute("TRUNCATE TABLE ' || table_schema || '.' || table_name || ';");' AS sql_statement FROM information_schema.tables WHERE table_schema = 'PUBLIC' ORDER BY table_name;
38+
jdbcTemplate.execute("SET REFERENTIAL_INTEGRITY FALSE");
39+
40+
List<String> tableNames = getAllTableNames();
41+
42+
// Truncate tables in reverse order
43+
for (int i = tableNames.size() - 1; i >= 0; i--) {
44+
String tableName = tableNames.get(i);
45+
String truncateQuery = "TRUNCATE TABLE " + tableName;
46+
jdbcTemplate.execute(truncateQuery);
47+
}
48+
jdbcTemplate.execute("SET REFERENTIAL_INTEGRITY FALSE");
49+
}
50+
2851
@Test
2952
void testNullable() throws EncryptedDocumentException, IOException {
3053
ExcelReader excelReader = new ExcelReader(null);

0 commit comments

Comments
 (0)