zum Testen ich ein Benutzerobjekt erstellen möchten, und sie für den späteren speichern mit:So beheben Sie eine IllegalStateException: Benutzer wurde nicht im JUnit-Test gefunden?
User user = userService.createUserInformation("testl", "testpw", "peter", "tester", "[email protected]", "en");
Innen kommt, dass es einen Anruf um den Benutzer zu speichern:
public User createUserInformation(...)
User newUser = new User();
Authority authority = authorityRepository.findOne("ROLE_USER");
...
newUser.setAuthorities(authorities);
userRepository.save(newUser);
}
Aber wenn ich versuche, diese , erhalte ich ein:
org.springframework.dao.InvalidDataAccessApiUsageException: User not found!; nested exception is java.lang.IllegalStateException: User not found!
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:381)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:227)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:131)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
at com.sun.proxy.$Proxy166.save(Unknown Source)
at app.backend.service.UserService.createUserInformation(UserService.java:111)
at
Was dies bedeutet hat (Benutzer nicht gefunden, während ich es speichern?) Wie kann ich mehr Details des User-Objekt zu sehen, oder wie man dieses Problem zu beheben?
Die Testkonfiguration basiert auf einem AbstractControllerTest:
@WebAppConfiguration
@ContextConfiguration
@ActiveProfiles({"dev", "test"})
public class AbstractControllerTest extends AbstractTest {
(nicht sicher, wo die genaue App-Konfiguration für den Test zu finden)
Vielen Dank für Ihre Hilfe!
poste deine createUserInformation und Konfiguration –
ok, ich fügte einige weitere Infos hinzu, nicht sicher, wo die App-Konfiguration genau dort zu finden ist ist keine XML-Datei, sondern eine Klasse, die die Liquibase-Verbindung laden könnte - Informationen darüber, wie man eine Konfiguration für den Test richtig macht, wären ebenfalls hilfreich – poseid