テスト用にGlassfish 4.0コンテナが埋め込まれたArquillianを使用しています。これまでのところ、なんとか動作させることができましたが、1 つのテスト ケースが失敗し続け、その理由がわかりません。ここに私のテストコードがあります:
// Test Class
@Inject
private CompetenceService competenceService;
@Test
public void createSingleCompetence() {
Competence c = new Competence();
// fill the competence with data
c = competenceService.save(c); // throws a RollbackException
// some testing assertions
}
これがサービス クラスです。
// CompetenceService
@Transactional
@ApplicationScoped
public class CompetenceService {
@PersistenceContext
private EntityManager em;
public Competence save(Competence c){
return em.merge(c);
}
}
これを arquillian で実行すると、次のエラーが表示されます。
Managed bean with Transactional annotation and TxType of REQUIRED encountered exception during commit javax.transaction.RollbackException: Transaction marked for rollback
私の質問は次のとおりです。何がうまくいかないのか、どうにかして理解できますか? 私が最初に考えたのは、すべての制約が満たされているわけではない ( など@NotNull
) ということでしたが、今はそれを除外しました。
完全なスタック トレースは得られず、テスト実行の最後のエラーのみが得られます。出力は次のとおりです。
[Competence test competence]
Aug 07, 2013 8:28:57 AM org.glassfish.cdi.transaction.TransactionalInterceptorRequired transactional
INFO: In REQUIRED TransactionalInterceptor
Aug 07, 2013 8:28:57 AM org.glassfish.cdi.transaction.TransactionalInterceptorRequired transactional
INFO: Managed bean with Transactional annotation and TxType of REQUIRED called outside a transaction context. Beginning a transaction...
Aug 07, 2013 8:28:57 AM org.glassfish.cdi.transaction.TransactionalInterceptorBase markRollbackIfActiveTransaction
INFO: About to setRollbackOnly from @Transactional interceptor on transaction:JavaEETransactionImpl: txId=1 nonXAResource=1 jtsTx=null localTxStatus=0 syncs=[org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper$1@fe04c00, org.eclipse.persistence.transaction.JTASynchronizationListener@4e9d9c24, org.eclipse.persistence.transaction.JTASynchronizationListener@4d7627ce, com.sun.enterprise.resource.pool.PoolManagerImpl$SynchronizationListener@82f6d1d]
Aug 07, 2013 8:28:57 AM org.glassfish.cdi.transaction.TransactionalInterceptorRequired transactional
INFO: Managed bean with Transactional annotation and TxType of REQUIRED encountered exception during commit javax.transaction.RollbackException: Transaction marked for rollback.
Aug 07, 2013 8:28:58 AM org.glassfish.persistence.common.Java2DBProcessorHelper executeDDLs
WARNING: PER01000: Got SQLException executing statement "ALTER TABLE COMPETENCECATEGORY DROP CONSTRAINT CMPTWNNGNSTNCNTTYD": java.sql.SQLSyntaxErrorException: ALTER TABLE failed. There is no constraint 'APP.CMPTWNNGNSTNCNTTYD' on table '"APP"."COMPETENCECATEGORY"'.
PlainTextActionReporterSUCCESS
PER01003: Deployment encountered SQL Exceptions:
PER01000: Got SQLException executing statement "ALTER TABLE COMPETENCECATEGORY DROP CONSTRAINT CMPTWNNGNSTNCNTTYD": java.sql.SQLSyntaxErrorException: ALTER TABLE failed. There is no constraint 'APP.CMPTWNNGNSTNCNTTYD' on table '"APP"."COMPETENCECATEGORY"'. Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 23.032 sec <<< FAILURE!
Aug 07, 2013 8:29:01 AM org.glassfish.admin.mbeanserver.JMXStartupService shutdown
INFO: JMXStartupService and JMXConnectors have been shut down.
JdbcRuntimeExtension, getAllSystemRAResourcesAndPools = [GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcConnectionPool, GlassFishConfigBean.org.glassfish.jdbc.config.JdbcResource]
Aug 07, 2013 8:29:01 AM com.sun.enterprise.connectors.service.ResourceAdapterAdminServiceImpl sendStopToResourceAdapter
INFO: RAR7094: __ds_jdbc_ra shutdown successful.
Aug 07, 2013 8:29:01 AM com.sun.enterprise.v3.server.AppServerStartup stop
INFO: Shutdown procedure finished
Results :
Tests in error:
createSingleCompetence(at.seresunit.outtasking.test.CompetenceTest): Managed bean with Transactional annotation and TxType of REQUIRED encountered exception during commit javax.transaction.RollbackException: Transaction marked for rollback.
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------