2

Google-App-Engine Eclipse-Environment で JUnittest を実行しようとしています

Unittest は、Entitymanager を取得することにより、JPA エンティティを処理するクラスをテストしています。

「テスト中のクラス」では、次の呼び出しは生産性コードで成功しますが、JUnit テストとして実行すると失敗します。

EntityManager em = EMF.get().createEntityManager();

上記の JUnit テストでは、「デフォルト プロバイダーが見つかりません」という例外がスローされます (スタック トレースを参照)。

persistence.xml が到達可能であることを確認するために、ユニットテストを src- ディレクトリ ツリーに直接移動しました。同じ例外がスローされます。「transactions-optional」という名前のpersistenceUnitに到達できるようです。

JUnittest でデフォルト プロバイダーを構成するにはどうすればよいですか?

次の jar を含めました:
${SDK_ROOT}/lib/impl/appengine-api.jar
${SDK_ROOT}/lib/impl/appengine-api-labs.jar
${SDK_ROOT}/lib/impl/appengine-api-stubs.瓶

GAEサイトの demo-Unittest は正常に動作しています: GAE Demo JUnittest

test-Setup で JPA を使用する場合、追加の構成を行う必要がありますか?

private final LocalServiceTestHelper helper =
        new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());

スタック トレースを含むコンソール出力:

Jun 07, 2013 12:33:17 PM com.google.appengine.api.datastore.dev.LocalDatastoreService init
INFO: Local Datastore initialized: 
    Type: Master/Slave
    Storage: In-memory

Jun 07, 2013 12:33:18 PM org.datanucleus.metadata.MetaDataManager loadPersistenceUnit
WARNING: Class ch.didge.ashopper.cloud.client.GreetingService was specified in persistence-unit transactions-optional but not annotated, so ignoring
Jun 07, 2013 12:33:18 PM org.datanucleus.metadata.MetaDataManager loadPersistenceUnit
WARNING: Class ch.didge.ashopper.cloud.persistence.EMF was specified in persistence-unit transactions-optional but not annotated, so ignoring
Jun 07, 2013 12:33:18 PM org.datanucleus.metadata.MetaDataManager loadPersistenceUnit
WARNING: Class ch.didge.ashopper.cloud.connectivity.UserServlet was specified in persistence-unit transactions-optional but not annotated, so ignoring
Jun 07, 2013 12:33:18 PM org.datanucleus.metadata.MetaDataManager loadPersistenceUnit
WARNING: Class ch.didge.ashopper.cloud.business.AShopperManagerTest was specified in persistence-unit transactions-optional but not annotated, so ignoring
Jun 07, 2013 12:33:18 PM org.datanucleus.metadata.MetaDataManager loadPersistenceUnit
WARNING: Class ch.didge.ashopper.cloud.business.AShopperManager was specified in persistence-unit transactions-optional but not annotated, so ignoring
Jun 07, 2013 12:33:18 PM org.datanucleus.metadata.MetaDataManager loadPersistenceUnit
WARNING: Class ch.didge.ashopper.cloud.shared.FieldVerifier was specified in persistence-unit transactions-optional but not annotated, so ignoring
Jun 07, 2013 12:33:18 PM org.datanucleus.metadata.MetaDataManager loadPersistenceUnit
WARNING: Class ch.didge.ashopper.cloud.server.GreetingServiceImpl was specified in persistence-unit transactions-optional but not annotated, so ignoring
Jun 07, 2013 12:33:18 PM org.datanucleus.metadata.MetaDataManager loadPersistenceUnit
WARNING: Class ch.didge.ashopper.cloud.client.AShopperCloud was specified in persistence-unit transactions-optional but not annotated, so ignoring
Jun 07, 2013 12:33:18 PM org.datanucleus.metadata.MetaDataManager loadPersistenceUnit
WARNING: Class ch.didge.ashopper.cloud.client.GreetingServiceAsync was specified in persistence-unit transactions-optional but not annotated, so ignoring
Jun 07, 2013 12:33:18 PM org.datanucleus.NucleusContext getValidationHandler
WARNING: Unable to create validator handler
javax.validation.ValidationException: Unable to find a default provider
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)
    at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)
    at org.datanucleus.NucleusContext.getValidationHandler(NucleusContext.java:1067)
    at org.datanucleus.api.jpa.JPAEntityManager.<init>(JPAEntityManager.java:138)
    at org.datanucleus.api.jpa.JPAEntityManagerFactory.newEntityManager(JPAEntityManagerFactory.java:564)
    at org.datanucleus.api.jpa.JPAEntityManagerFactory.createEntityManager(JPAEntityManagerFactory.java:529)
    at ch.didge.ashopper.cloud.business.AShopperManager.register(AShopperManager.java:169)
    at ch.didge.ashopper.cloud.business.AShopperManagerTest.testRegister(AShopperManagerTest.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Jun 07, 2013 12:33:18 PM com.google.appengine.api.datastore.dev.LocalDatastoreService init
INFO: Local Datastore initialized: 
    Type: Master/Slave

    Storage: In-memory

誰が何がうまくいかなかったのか考えていますか?

4

1 に答える 1

0

JPAではなく、BEAN VALIDATIONのデフォルトプロバイダーを探しています。Bean 検証を使用する場合は、Apache BVAL や Hibernate Validator などを CLASSPATH に追加します。

于 2013-06-08T07:47:21.510 に答える