Closed
Description
Description
Invalid entity is generated and then searched with Controller
To Reproduce
- Install UnitTestBot plugin built from main in IntelliJ IDEA
- Open
spring-petclinic
- Generate
Integration tests
forOwnerController$findOwner
withPetClinicApplication
configuration selected
Expected behavior
Valid entity is expected to be created and saved in to OwnerRepository.
Id should be saved and then used in findOwner
method call.
Some invalid id should be used in another test.
Actual behavior
Owner object is tried to be saved with entityManager.persist()
But it is not valid and ConstraintViolationException
is thrown.
then findOwner
method is called with id=-65
Screenshots, logs
///region FUZZER: ERROR SUITE for method findOwner(java.lang.Integer)
/**
* @utbot.classUnderTest {@link OwnerController}
* @utbot.methodUnderTest {@link OwnerController#findOwner(Integer)}
*/
@Test
@DisplayName("findOwner: ownerId = -65 (mutated from -1) -> throw AssertionFailure")
public void testFindOwnerThrowsAF() {
Owner owner1 = new Owner();
try {
entityManager1.persist(owner1);
} catch (jakarta.validation.ConstraintViolationException constraintViolationException1) {
}
/* This test fails because method [org.springframework.samples.petclinic.owner.OwnerController.findOwner] produces [org.hibernate.AssertionFailure: null id in org.springframework.samples.petclinic.owner.Owner entry (don't flush the Session after an exception occurs)]
org.hibernate.event.internal.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:82)
org.hibernate.event.internal.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:171)
org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:130)
org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107)
org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:214)
org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:90)
org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:48)
org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107)
org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1388)
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.lambda$new$0(ConcreteSqmSelectQueryPlan.java:111)
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.withCacheableSqmInterpretation(ConcreteSqmSelectQueryPlan.java:335)
org.hibernate.query.sqm.internal.ConcreteSqmSelectQueryPlan.performList(ConcreteSqmSelectQueryPlan.java:276)
org.hibernate.query.sqm.internal.QuerySqmImpl.doList(QuerySqmImpl.java:571)
org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:363)
org.hibernate.query.sqm.internal.QuerySqmImpl.list(QuerySqmImpl.java:1073)
org.hibernate.query.spi.AbstractSelectionQuery.getSingleResult(AbstractSelectionQuery.java:457)
org.hibernate.query.sqm.internal.QuerySqmImpl.getSingleResult(QuerySqmImpl.java:1103)
org.springframework.data.jpa.repository.query.JpaQueryExecution$SingleEntityExecution.doExecute(JpaQueryExecution.java:193)
org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:90)
org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:148)
org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:136)
org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:136)
org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:120)
org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:164)
org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:143)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:390)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:134)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:218)
jdk.proxy3/jdk.proxy3.$Proxy182.findById(Unknown Source)
org.springframework.samples.petclinic.owner.OwnerController.findOwner(OwnerController.java:62) */
ownerController.findOwner(-65);
}
///endregion
Environment
IntelliJ IDEA version - Ultimate 2023.2
Project - Gradle
JDK - 17
Metadata
Metadata
Assignees
Type
Projects
Status
Done