Merge pull request #15553 from Michaelin007/integrationtest

https://jira.baeldung.com/browse/BAEL-7375
This commit is contained in:
Maiklins 2024-01-12 23:26:06 +01:00 committed by GitHub
commit e2e9b10e68
3 changed files with 8 additions and 6 deletions

View File

@ -74,6 +74,7 @@
<validation-api.version>2.0.1.Final</validation-api.version>
<mysql-connector-java.version>8.2.0</mysql-connector-java.version>
<start-class>com.baeldung.boot.Application</start-class>
<spring-boot.version>3.2.0</spring-boot.version>
</properties>
</project>

View File

@ -1,6 +1,7 @@
package com.baeldung.springbootinitialload.tests;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.*;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -16,7 +17,8 @@ import com.baeldung.boot.repository.EmployeeRepository;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@Sql({"/employees_schema.sql", "/import_employees.sql"})
@Sql(scripts = {"/employees_schema.sql", "/import_employees.sql"}, executionPhase = BEFORE_TEST_CLASS)
@Sql(scripts = {"/delete_employees_data.sql"}, executionPhase = AFTER_TEST_CLASS)
public class SpringBootInitialLoadIntegrationTest {
@Autowired
@ -24,14 +26,12 @@ public class SpringBootInitialLoadIntegrationTest {
@Test
public void testLoadDataForTestClass() {
assertEquals(3, employeeRepository.findAll()
.size());
assertEquals(3, employeeRepository.findAll().size());
}
@Test
@Sql(scripts = {"/import_senior_employees.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = TransactionMode.ISOLATED))
@Sql(scripts = {"/import_senior_employees.sql"}, executionPhase = BEFORE_TEST_METHOD ,config = @SqlConfig(encoding = "utf-8", transactionMode = TransactionMode.ISOLATED))
public void testLoadDataForTestCase() {
assertEquals(5, employeeRepository.findAll()
.size());
assertEquals(5, employeeRepository.findAll().size());
}
}

View File

@ -0,0 +1 @@
DROP TABLE EMPLOYEES;