users@glassfish.java.net

Re: Maven2 junit test not finding src/resources/META-INF/persistence.xml

From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
Date: Tue, 16 Sep 2008 17:26:17 -0700
Can you run with mvn -X and see what command line is used to run your test. That should give you some clue.

The root cause is AssertionError from following code.

    public static URL computePURootURL(URL pxmlURL) throws IOException {
        String protocol = pxmlURL.getProtocol();
        if("file".equals(protocol)) { // NOI18N
            // e.g. file:/tmp/META-INF/persistence.xml
            assert(new File(pxmlURL.getFile()).isFile());


glassfish@javadesktop.org wrote:
Hi,

When i'm running my junit testcase from maven2 getting the error "No Persistence provider for EntityManager"
.
I have done lots of googling still struggling,
Looks testcases not able to find persistence.xml but why?

Is any body a have faced this issue?

Thank you

[b]( Inside target\surefire-reports\mytest.txt)[/b]
javax.persistence.PersistenceException: No Persistence provider for EntityManager named TestPU: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory:
java.lang.AssertionError
java.lang.AssertionError
    at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.computePURootURL(PersistenceUnitProcessor.java:263)
    at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:148)
==================================================================================================================

[b]src/test/resources/META-INF/persistence.xml[/b]
==============
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="TestPU" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <class>ABCEntity</class>
   <properties>
      <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/testdb"/>
      <property name="toplink.jdbc.user" value="test1"/>
      <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="toplink.jdbc.password" value="test123"/>
      <property name="toplink.ddl-generation" value="none"/>
      <property name="toplink.logging.level" value="fine"/>
      <property name="toplink.jdbc.native-sql" value="true"/>
      <property name="toplink.target-database" value="MySQL4"/>
    </properties>
  </persistence-unit>
</persistence>

[b]pom.xml[/b]
.............
..........
...
<resources>
            <resource>
                <filtering>false</filtering>
                <directory>${basedir}/src/main/resources</directory>
                <includes>
                    <include>META-INF/persistence.xml</include>
                </includes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${basedir}/src/test/resources</directory>
                <includes>
                    <include>META-INF/persistence.xml</include>
                </includes>
            </testResource>
        </testResources>

....
...
...
<dependency>
            <groupId>com.oracle.toplink</groupId>
            <artifactId>toplink</artifactId>
            <version>10.1.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.5</version>
            <scope>test</scope>
        </dependency>

...............
............

TestCase

 @Test
    public void testBalance() {
        javax.persistence.EntityManagerFactory emf =
                javax.persistence.Persistence.createEntityManagerFactory("TestPU");
        assertNotNull("The entity manager factory is null", emf);
        ...
....
...
..

    }
[Message sent by forum member 'happy007' (happy007)]

http://forums.java.net/jive/thread.jspa?messageID=299556

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net