JUnit在路由中使用openJPA测试蓝图

时间:2014-03-13 15:11:23

标签: apache-camel junit4 openjpa blueprint

我有一个测试用例,它在JUnit的开头加载blueprint.xml和persistence.xml,但是当测试实际运行时,由于没有持久性提供程序而引发错误。

Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named blacklisting-pu 
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:92)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.apache.camel.component.jpa.JpaEndpoint.createEntityManagerFactory(JpaEndpoint.java:255)
at org.apache.camel.component.jpa.JpaEndpoint.getEntityManagerFactory(JpaEndpoint.java:165)
at org.apache.camel.component.jpa.JpaEndpoint.validate(JpaEndpoint.java:248)
at org.apache.camel.component.jpa.JpaEndpoint.createProducer(JpaEndpoint.java:103)
at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:405)

这是显示提供程序已加载的日志的第一部分:

16  blacklisting-pu  TRACE  [main] openjpa.Runtime - Setting the following properties from "file:/workspace/git/jdbc-util/target/test-classes/META-INF/persistence.xml" into configuration: {openjpa.jdbc.SynchronizeMappings=buildSchema(SchemaAction='add,deleteTableContents'), openjpa.ConnectionPassword=, openjpa.ConnectionDriverName=org.h2.Driver, javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl, openjpa.MetaDataFactory=jpa(Types=com.entity.MyEntity), openjpa.Log=DefaultLevel=TRACE, Tool=INFO, PersistenceVersion=1.0, openjpa.ConnectionUserName=, openjpa.ConnectionURL=jdbc:h2:mem:blacklisting;DB_CLOSE_DELAY=1000, openjpa.Id=blacklisting-pu}
74  blacklisting-pu  TRACE  [main] openjpa.Runtime - No cache marshaller found for id org.apache.openjpa.conf.MetaDataCacheMaintenance.
119  blacklisting-pu  TRACE  [main] openjpa.Runtime - No cache marshaller found for id org.apache.openjpa.conf.MetaDataCacheMaintenance.
128  blacklisting-pu  TRACE  [main] openjpa.MetaData - Scanning resource "META-INF/orm.xml" for persistent types.
129  blacklisting-pu  TRACE  [main] openjpa.MetaData - The persistent unit root url is "null"
129  blacklisting-pu  TRACE  [main] openjpa.MetaData - parsePersistentTypeNames() found [com.entity.BlacklistingEntity].
129  blacklisting-pu  TRACE  [main] openjpa.MetaData - Found 1 classes with metadata in 9 milliseconds.
132  blacklisting-pu  TRACE  [main] openjpa.MetaData - Clearing metadata repository"org.apache.openjpa.meta.MetaDataRepository@1766bfd8".

我让测试用例使用spring并在spring camel-context.xml中定义路由但后来我需要将路由移动到blueprint.xml,现在它似乎无法找到持久性。运行时的xml用于测试 我一直在使用它作为我的参考以及很多googleing: http://camel.apache.org/blueprint-testing.html 任何帮助将不胜感激

编辑: 我已经在JUnit中运行了以下作为设置方法的一部分,并且发现没有问题的calss

Object obj = Class.forName("org.apache.openjpa.persistence.PersistenceProviderImpl").newInstance();
    if(null==obj){
        Assert.fail("org.apache.openjpa.persistence.PersistenceProviderImpl not present on classpath.");
    }else{
        LOG.info("the class {} exists on the calsspath.",obj.getClass().getName());
    }

这是显示它已加载的日志

Creating service instance
Service created: org.apache.aries.blueprint.ext.impl.ExtNamespaceHandler@10a33ce2
Creating listeners
the class org.apache.openjpa.persistence.PersistenceProviderImpl exists on the calsspath.

的persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name="blacklisting-pu" transaction-type="RESOURCE_LOCAL">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <class>com.entity.BlacklistingEntity</class>
    <properties>
        <property name="openjpa.ConnectionURL" value="jdbc:h2:mem:blacklisting;DB_CLOSE_DELAY=1000" />
        <property name="openjpa.ConnectionDriverName" value="org.h2.Driver" />
        <property name="openjpa.ConnectionUserName" value="" />
        <property name="openjpa.ConnectionPassword" value="" />
        <property name="openjpa.Log" value="DefaultLevel=TRACE, Tool=INFO" />
        <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(SchemaAction='add,deleteTableContents')" />
    </properties>
</persistence-unit>

</persistence>

0 个答案:

没有答案