2

尝试在 Google-App-Engine Eclipse-Environment 中使用 JUnittest

Unittest 正在通过获取 Entitymanager 来测试处理 JPA 实体的类。

在“测试中的类”中,以下调用在生产代码中成功,但如果我将其作为 JUnit 测试运行则失败。

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

在上面调用的 JUnit 测试中抛出异常,“无法找到默认提供程序”(请参阅​​堆栈跟踪)

我直接在 src- 目录树中移动了 unittest,以确保persistence.xml 是可访问的。它抛出相同的异常。似乎可以访问名为“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站点上的演示单元测试运行良好: GAE 演示 JUnittest

如果在测试设置中使用 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

它正在寻找 BEAN VALIDATION 的默认提供程序,而不是 JPA。如果您想使用 bean 验证,则将 Apache BVAL 或 Hibernate Validator 之类的东西放在 CLASSPATH 中。

于 2013-06-08T07:47:21.510 回答