I have created Entity Listerner
public class SomeListener {
@PrePersist
@PreUpdate
public void someAction(final SomeInterface entity) {
And added it to Entitites
@Entity
@EntityListeners(SomeListener.class)
public class SomeEntity implements SomeInterface {
Entities obtained from repository
@Repository
public interface SomeRepository
extends JpaRepository<SomeEntity, Long>, JpaSpecificationExecutor<SomeEntity> {
In code it works fine, but in tests this listener is ignored
Test configuration:
@SpringBootApplication(scanBasePackages = {
"package with listener",
"package with model",
"package with repository",
"and all other packages"
})
@EnableJpaRepositories(basePackages = {
"packages with repositories"
})
@EntityScan(basePackages = {
"packages with models"
})
public class TestConfig {
}
Abstract class for Integration tests:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = TestConfig.class)
@AutoConfigureMockMvc
@Transactional
public abstract class AbstractTestInt {
and in test just called
mockMvc.perform(post(CREATE_URL).params(someparams))
.andExpect(status().is5xxServerError())
Entity listener should check some attributes and throw exception, because provided params wrong, but exception isn't thrown and in debugger I can see that parameters really wrong, so returned status redirection, as success save when called someRepository.save(entity)
Why Entity Listener not called in test context?