wake-up-neo.com

Tests schlagen fehl, wenn sie von maven, aber nicht von Intellij ausgeführt werden

Ich schreibe meine Unit-Tests mit JUnit, PowerMock, Spring Test und einer speicherinternen H2-Datenbank. Wenn ich die Tests von Intellij aus durchführe, läuft alles korrekt. Aber wenn ich die Tests von maven aus (entweder von Intellij oder von der Kommandozeile aus) starte, schlagen sie fehl.

Das ist meine Konfiguration:

   @EnableTransactionManagement
   @EnableJpaRepositories("my.app.repository")
   public class ApplicationTestConfiguration {
      @Bean
      public SimpleDriverDataSource dataSource() {
         SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
         simpleDriverDataSource.setDriverClass(org.h2.Driver.class);
         simpleDriverDataSource.setUrl("jdbc:h2:mem:./ScenarioService;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1");
         simpleDriverDataSource.setUsername("sa");
         simpleDriverDataSource.setPassword("sa");
         return simpleDriverDataSource;
      }
      (...)
      private Properties hibernateProperties() {
         Properties props = new Properties();
         props.setProperty("hibernate.dialect","org.hibernate.dialect.H2Dialect");
         props.setProperty("hibernate.hbm2ddl.auto", "create-drop");
         props.setProperty("hibernate.show_sql","true");
         return props;
      }
   }

Dies ist ein Beispieltest:

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebAppInitializer.class,ApplicationTestConfiguration.class, DirtiesContextTestExecutionListener.class})
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public final class ReadTicketsTest {

    @Autowired //this is a spring JPARepository
    protected TestRepository testRepository;

    @Before
    public void init() {
         testRepository.save(engineConfig);
    }

    @Test
    public void ticketShouldBeRead() {
        //assertion code
    }
}

Wenn ich die Tests von intelliJ aus durchführe und sie erfolgreich sind, sehe ich in den Ruhezustandsprotokollen etwa Folgendes:

Hibernate: drop table EngineConfigs if exists
Hibernate: create table EngineConfigs (id binary(16) not null, created datetime(6) DEFAULT NULL, customData MEDIUMTEXT, customerId binary(16) not null, signature varchar(255), signatureVersion integer, updated datetime(6) DEFAULT NULL, advancedConfiguration TEXT, engineConfigName varchar(255) not null, engineServiceName varchar(255) not null, locked boolean, probabilityMaximum integer not null, primary key (id))
Hibernate: select engineconf0_.id as id1_1_1_, engineconf0_.created as created2_1_1_, engineconf0_.customData as customDa3_1_1_, engineconf0_.customerId as customer4_1_1_, engineconf0_.signature as signatur5_1_1_, engineconf0_.signatureVersion as signatur6_1_1_, engineconf0_.updated as updated7_1_1_, engineconf0_.advancedConfiguration as advanced8_1_1_, engineconf0_.engineConfigName as engineCo9_1_1_, engineconf0_.engineServiceName as engineS10_1_1_, engineconf0_.locked as locked11_1_1_, engineconf0_.probabilityMaximum as probabi12_1_1_, accumulato1_.EngineConfigs_id as EngineCo1_1_3_, accumulato2_.id as accumula2_2_3_, accumulato2_.id as id1_0_0_, accumulato2_.created as created2_0_0_, accumulato2_.customData as customDa3_0_0_, accumulato2_.customerId as customer4_0_0_, accumulato2_.signature as signatur5_0_0_, accumulato2_.signatureVersion as signatur6_0_0_, accumulato2_.updated as updated7_0_0_, accumulato2_.accumulatorNumber as accumula8_0_0_, accumulato2_.description as descript9_0_0_, accumulato2_.engineConfig_id as engineC12_0_0_, accumulato2_.numberOfHits as numberO10_0_0_, accumulato2_.prize as prize11_0_0_ from EngineConfigs engineconf0_ left outer join EngineConfigs_Accumulators accumulato1_ on engineconf0_.id=accumulato1_.EngineConfigs_id left outer join Accumulators accumulato2_ on accumulato1_.accumulators_id=accumulato2_.id where engineconf0_.id=?
Hibernate: insert into EngineConfigs (created, customData, customerId, signature, signatureVersion, updated, advancedConfiguration, engineConfigName, engineServiceName, locked, probabilityMaximum, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: drop table EngineConfigs if exists

Dies ist sinnvoll, da erwartet wird, dass die Datenbank erstellt wird, die Tests (daher die Einfügung) ausgeführt werden und dann alle Tabellen aufgrund der @DirtiesContextAnnotation gelöscht werden. Aber wenn ich die Tests von Maven aus durchführe, sehe ich in den Ruhezustandsprotokollen etwa Folgendes:

Hibernate: drop table EngineConfigs if exists
Hibernate: create table EngineConfigs (id binary(16) not null, created datetime(6) DEFAULT NULL, customData MEDIUMTEXT, customerId binary(16) not null, signature varchar(255), signatureVersion integer, updated datetime(6) DEFAULT NULL, advancedConfiguration TEXT, engineConfigName varchar(255) not null, engineServiceName varchar(255) not null, locked boolean, probabilityMaximum integer not null, primary key (id))
Hibernate: select engineconf0_.id as id1_1_1_, engineconf0_.created as created2_1_1_, engineconf0_.customData as customDa3_1_1_, engineconf0_.customerId as customer4_1_1_, engineconf0_.signature as signatur5_1_1_, engineconf0_.signatureVersion as signatur6_1_1_, engineconf0_.updated as updated7_1_1_, engineconf0_.advancedConfiguration as advanced8_1_1_, engineconf0_.engineConfigName as engineCo9_1_1_, engineconf0_.engineServiceName as engineS10_1_1_, engineconf0_.locked as locked11_1_1_, engineconf0_.probabilityMaximum as probabi12_1_1_, accumulato1_.EngineConfigs_id as EngineCo1_1_3_, accumulato2_.id as accumula2_2_3_, accumulato2_.id as id1_0_0_, accumulato2_.created as created2_0_0_, accumulato2_.customData as customDa3_0_0_, accumulato2_.customerId as customer4_0_0_, accumulato2_.signature as signatur5_0_0_, accumulato2_.signatureVersion as signatur6_0_0_, accumulato2_.updated as updated7_0_0_, accumulato2_.accumulatorNumber as accumula8_0_0_, accumulato2_.description as descript9_0_0_, accumulato2_.engineConfig_id as engineC12_0_0_, accumulato2_.numberOfHits as numberO10_0_0_, accumulato2_.prize as prize11_0_0_ from EngineConfigs engineconf0_ left outer join EngineConfigs_Accumulators accumulato1_ on engineconf0_.id=accumulato1_.EngineConfigs_id left outer join Accumulators accumulato2_ on accumulato1_.accumulators_id=accumulato2_.id where engineconf0_.id=?
Hibernate: drop table EngineConfigs if exists

Gefolgt von dem eigentlichen Fehler:

org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select engineconf0_.id as id1_1_1_, engineconf0_.created as created2_1_1_, engineconf0_.customData as customDa3_1_1_, engineconf0_.customerId as customer4_1_1_, engineconf0_.signature as signatur5_1_1_, engineconf0_.signatureVersion as signatur6_1_1_, engineconf0_.updated as updated7_1_1_, engineconf0_.advancedConfiguration as advanced8_1_1_, engineconf0_.engineConfigName as engineCo9_1_1_, engineconf0_.engineServiceName as engineS10_1_1_, engineconf0_.locked as locked11_1_1_, engineconf0_.probabilityMaximum as probabi12_1_1_, accumulato1_.EngineConfigs_id as EngineCo1_1_3_, accumulato2_.id as accumula2_2_3_, accumulato2_.id as id1_0_0_, accumulato2_.created as created2_0_0_, accumulato2_.customData as customDa3_0_0_, accumulato2_.customerId as customer4_0_0_, accumulato2_.signature as signatur5_0_0_, accumulato2_.signatureVersion as signatur6_0_0_, accumulato2_.updated as updated7_0_0_, accumulato2_.accumulatorNumber as accumula8_0_0_, accumulato2_.description as descript9_0_0_, accumulato2_.engineConfig_id as engineC12_0_0_, accumulato2_.numberOfHits as numberO10_0_0_, accumulato2_.prize as prize11_0_0_ from EngineConfigs engineconf0_ left outer join EngineConfigs_Accumulators accumulato1_ on engineconf0_.id=accumulato1_.EngineConfigs_id left outer join Accumulators accumulato2_ on accumulato1_.accumulators_id=accumulato2_.id where engineconf0_.id=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.Java:172)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.Java:155)
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$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.Java:122)
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:207)
at com.Sun.proxy.$Proxy64.save(Unknown Source)
at com.twelve40.gameengine.scenario.ScenarioServiceTest.init(ScenarioServiceTest.Java:138)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.Java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.Java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.Java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.Java:24)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.Java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.Java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.Java:73)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.Java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:224)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.Java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.Java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.Java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.Java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.Java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.Java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.Java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.Java:68)
at org.junit.runners.ParentRunner.run(ParentRunner.Java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.Java:163)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.Java:148)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner$2.call(DelegatingPowerMockRunner.Java:140)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.withContextClassLoader(DelegatingPowerMockRunner.Java:131)
at org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner.run(DelegatingPowerMockRunner.Java:140)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.Java:121)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.Java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.Java:59)
at org.Apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.Java:252)
at org.Apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.Java:141)
at org.Apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.Java:112)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at org.Apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.Java:189)
at org.Apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.Java:165)
at org.Apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.Java:85)
at org.Apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.Java:115)
at org.Apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.Java:75)
Caused by: org.hibernate.exception.SQLGrammarException: could not prepare statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.Java:123)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.Java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.Java:126)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.Java:196)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.Java:160)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.Java:1885)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.Java:1862)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.Java:1839)
at org.hibernate.loader.Loader.doQuery(Loader.Java:910)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.Java:355)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.Java:325)
at org.hibernate.loader.Loader.loadEntity(Loader.Java:2149)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.Java:78)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.Java:68)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.Java:4126)
at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.Java:503)
at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.Java:468)
at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.Java:213)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.Java:275)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.Java:151)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.Java:1070)
at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.Java:176)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.Java:2551)
at org.hibernate.internal.SessionImpl.get(SessionImpl.Java:960)
at org.hibernate.event.internal.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.Java:306)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.Java:186)
at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.Java:85)
at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.Java:876)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.Java:858)
at org.hibernate.internal.SessionImpl.merge(SessionImpl.Java:863)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.Java:1196)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.Java:291)
at com.Sun.proxy.$Proxy58.merge(Unknown Source)
at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.Java:434)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:498)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.Java:414)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.Java:399)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.Java:371)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.Java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.Java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.Java:179)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.Java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.Java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.Java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.Java:179)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.Java:136)
... 50 more
Caused by: org.h2.jdbc.JdbcSQLException: Table "EngineConfigs" not found; SQL statement:
select engineconf0_.id as id1_1_1_, engineconf0_.created as created2_1_1_, engineconf0_.customData as customDa3_1_1_, engineconf0_.customerId as customer4_1_1_, engineconf0_.signature as signatur5_1_1_, engineconf0_.signatureVersion as signatur6_1_1_, engineconf0_.updated as updated7_1_1_, engineconf0_.advancedConfiguration as advanced8_1_1_, engineconf0_.engineConfigName as engineCo9_1_1_, engineconf0_.engineServiceName as engineS10_1_1_, engineconf0_.locked as locked11_1_1_, engineconf0_.probabilityMaximum as probabi12_1_1_, accumulato1_.EngineConfigs_id as EngineCo1_1_3_, accumulato2_.id as accumula2_2_3_, accumulato2_.id as id1_0_0_, accumulato2_.created as created2_0_0_, accumulato2_.customData as customDa3_0_0_, accumulato2_.customerId as customer4_0_0_, accumulato2_.signature as signatur5_0_0_, accumulato2_.signatureVersion as signatur6_0_0_, accumulato2_.updated as updated7_0_0_, accumulato2_.accumulatorNumber as accumula8_0_0_, accumulato2_.description as descript9_0_0_, accumulato2_.engineConfig_id as engineC12_0_0_, accumulato2_.numberOfHits as numberO10_0_0_, accumulato2_.prize as prize11_0_0_ from EngineConfigs engineconf0_ left outer join EngineConfigs_Accumulators accumulato1_ on engineconf0_.id=accumulato1_.EngineConfigs_id left outer join Accumulators accumulato2_ on accumulato1_.accumulators_id=accumulato2_.id where engineconf0_.id=? [42102-193]
at org.h2.message.DbException.getJdbcSQLException(DbException.Java:345)
at org.h2.message.DbException.get(DbException.Java:179)
at org.h2.message.DbException.get(DbException.Java:155)
at org.h2.command.Parser.readTableOrView(Parser.Java:5389)
at org.h2.command.Parser.readTableFilter(Parser.Java:1257)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.Java:1897)
at org.h2.command.Parser.parseSelectSimple(Parser.Java:2045)
at org.h2.command.Parser.parseSelectSub(Parser.Java:1891)
at org.h2.command.Parser.parseSelectUnion(Parser.Java:1709)
at org.h2.command.Parser.parseSelect(Parser.Java:1697)
at org.h2.command.Parser.parsePrepared(Parser.Java:445)
at org.h2.command.Parser.parse(Parser.Java:317)
at org.h2.command.Parser.parse(Parser.Java:289)
at org.h2.command.Parser.prepareCommand(Parser.Java:254)
at org.h2.engine.Session.prepareLocal(Session.Java:561)
at org.h2.engine.Session.prepareCommand(Session.Java:502)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.Java:1203)
at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.Java:73)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.Java:287)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.Java:162)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.Java:186)
... 99 more

Dieser Fehler ist genau der gleiche, der auftritt, wenn ich den Parameter DB_CLOSE_DELAY = -1 von der Verbindungs-URL entferne und die Tests von IntelliJ aus durchführe. Aber mit dem Parameter funktionieren die Tests von IntelliJ, aber nicht von Maven! Ich weiß nicht, woran das liegen könnte. AFAIK-Experten sollten die Durchführung der Tests nicht beeinträchtigen. Es scheint, als würde die Verbindung zur Datenbank geschlossen, bevor die Tests ausgeführt werden. Hilfe!

9
Neets

Das Problem war mit einer Bibliothek, die ich benutzte. Da ich das Bibliotheksprojekt in IntelliJ geladen hatte, wurde beim manuellen Ausführen der Tests der Bibliothekscode verwendet. Aber Maven nutzte die Bibliothek aus dem .m2-Repository, in dem die .jar nicht aktuell war. Dieses veraltete Glas hatte etwas, was dazu führte, dass die Erstellung der Tabelle EngineConfigs fehlschlug. Falls bei jemandem das gleiche Problem auftritt, besteht ein nützlicher Trick darin, das ": mem" aus der Datenbankverbindungs-URL zu entfernen und die * .trace.db-Datei zu überprüfen, die beim Ausführen der Tests generiert wird. Diese Tracedatei gibt Ihnen Informationen über das eigentliche zugrunde liegende Problem.

5
Neets

Es scheint, dass das zugrunde liegende Problem darin besteht, dass die Tabelle nicht gefunden werden kann:

Caused by: org.h2.jdbc.JdbcSQLException: Table "EngineConfigs" not found; SQL statement:

Wenn Sie Ihren Test in Maven ausführen, stimmen Ihre Datenbankkonfigurationsparameter (URL usw.) möglicherweise nicht mit denen überein, die in Ihrem Code (jdbc:h2:mem:./ScenarioService;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1 usw.) angegeben sind.

Ich würde versuchen herauszufinden, ob einige application.properties-Dateien (z. B. auf src\test\resources) diese Parameter in der Maven-Ausführung überschreiben.

0
Boni García