0
Previously the test worked and after a while stopped working. The structure in the database was not changed.
get the message:
Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'auditDetailInfoRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract void com.project.repository.BaseRepository.refresh(java.lang.Object)! No property refresh found for type AuditDetailInfo!
Caused by: java.lang.IllegalArgumentException: Failed to create query for method public abstract void com.project.repository.BaseRepository.refresh(java.lang.Object)! No property refresh found for type ExtractionCode!
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:96)
I would like to know what configuration is necessary for the unit test to work again, since the implosion of the unit test was already working.
All of my unit scores are failing now. an example unit test that previously ran smoothly:
@DataJpaTest
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class SampleRepositoryTest {
@Autowired
SampleRepository repository;
@Test
@Sql("/sqls/sample/populate_with_data.sql")
void test_sample_find_by_name_case_insensitive() {
List<Sample> samples = repository.findByNumber("9999999993213");
assertTrue(!samples.isEmpty());
}
@Test
@Sql("/sqls/sample/populate_with_data.sql")
void test_sample_soft_delete() {
List<Sample> samples = repository.findByNumber("9999999993213");
samples.stream().forEach(sample -> sample.setStatus(SampleStatus.INACTIVE));
repository.saveAll(samples);
List<Sample> samples2 = repository.findByNumber("9999999993213").stream()
.filter(sample -> !sample.getStatus().equals(SampleStatus.INACTIVE)).collect(Collectors.toList());
assertTrue(samples2.size() == 0);
}
Application.yml test project file:
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/devdb
username: postgres
password: postgres
jpa:
hibernate:
ddl-auto: validate # When you launch the application for the first time - switch "none" at "create"
show-sql: true
database: postgresql
database-platform: org.hibernate.dialect.PostgreSQLDialect
open-in-view: false
generate-ddl: true
flyway:
enabled: false
Build.Radle file:
//Junit AND test (uma parte)
dependencies {
//Spring
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation "junit:junit:4.12"
testImplementation('junit:junit:4.13')
testImplementation 'org.springframework.security:spring-security-test'
testImplementation'org.springframework.boot:spring-boot-starter-test'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile("org.assertj:assertj-core:3.11.1")