1
0

fix(jpa): 修复测试用例

This commit is contained in:
2026-01-21 13:23:33 +08:00
parent 54c12deb25
commit 02b9636fec

View File

@@ -7,8 +7,9 @@ import com.lanyuanxiaoyao.service.template.database.jpa.entity.Company_;
import com.lanyuanxiaoyao.service.template.database.jpa.entity.Employee;
import com.lanyuanxiaoyao.service.template.database.jpa.entity.Employee_;
import com.lanyuanxiaoyao.service.template.database.jpa.entity.QEmployee;
import com.lanyuanxiaoyao.service.template.database.jpa.repository.CompanyRepository;
import com.lanyuanxiaoyao.service.template.database.jpa.repository.EmployeeRepository;
import java.sql.SQLException;
import com.lanyuanxiaoyao.service.template.database.jpa.repository.ReportRepository;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
@@ -24,11 +25,15 @@ import org.springframework.util.Assert;
@EnableFenix
@EnableJpaAuditing
public class TestApplication extends AbstractTestApplication {
private final CompanyRepository companyRepository;
private final EmployeeRepository employeeRepository;
private final ReportRepository reportRepository;
public TestApplication(JdbcTemplate jdbcTemplate, EmployeeRepository employeeRepository) {
public TestApplication(JdbcTemplate jdbcTemplate, CompanyRepository companyRepository, EmployeeRepository employeeRepository, ReportRepository reportRepository) {
super(jdbcTemplate);
this.companyRepository = companyRepository;
this.employeeRepository = employeeRepository;
this.reportRepository = reportRepository;
}
public static void main(String[] args) {
@@ -36,7 +41,7 @@ public class TestApplication extends AbstractTestApplication {
}
@EventListener(ApplicationReadyEvent.class)
public void runTests() throws SQLException {
public void runTests() {
testCrud();
testSpecification();
testNative();
@@ -45,7 +50,6 @@ public class TestApplication extends AbstractTestApplication {
}
private void testSpecification() {
// 增
var cid1 = saveItem("company", randomCompany()).get("data").asLong();
var cid2 = saveItem("company", randomCompany()).get("data").asLong();
var cid3 = saveItem("company", randomCompany()).get("data").asLong();
@@ -101,7 +105,9 @@ public class TestApplication extends AbstractTestApplication {
);
Assert.isTrue(employees3.size() == 1, "查询数量错误");
System.exit(0);
companyRepository.deleteAllById(List.of(cid1, cid2, cid3));
employeeRepository.deleteAllById(List.of(eid1, eid2));
reportRepository.deleteAllById(List.of(rid1, rid2));
}
private void testNative() {
@@ -117,5 +123,8 @@ public class TestApplication extends AbstractTestApplication {
var list_native = employeeRepository.findAllEmployeeWithCompanyNameNative();
Assert.isTrue(list_native.size() == 3, "数量错误");
companyRepository.deleteAll();
employeeRepository.deleteAll();
}
}