NetBeans Forums
| View previous topic :: View next topic |
| Author |
Message |
tbbstny
Joined: 02 Jul 2010 Posts: 7
|
Posted: Thu Aug 05, 2010 1:50 pm Post subject: HowTo JUnit EJBs? |
|
|
I have an app working that is deployed to JBoss and accessing data from DB2. I am trying to write some JUnit tests for my EJB entities, which means running outside the container. I am getting an error trying to inject my testing EntityManager.
What I've done:
- Included in the "Test Libraries" of the EJB project the TopLink Essentials and MySAL JDBC Driver libraries
- Added a test persistence unit as follows
| Code: |
<persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL">
<class>com.model.ejb.entity.Ao6</class>
<properties>
<property name="toplink.ddl-generation" value="create-tables"/>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/test" />
<property name="toplink.jdbc.user" value="root"/>
<property name="toplink.jdbc.password" value=""/>
</properties>
</persistence-unit>
|
The setUp method in the test is failing on the second line with the error above
| Code: |
@Before
public void setUp() {
emf = Persistence.createEntityManagerFactory("testPU");
em = emf.createEntityManager();
facade = new Ao6Facade(em);
}
|
The Error:
"Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform."
I'm trying to use MySQL for my testing, so the settings look right to me. It appears that for some reason it isn't reading the settings out of the persistence.xml file as it should.
Please advise |
|
| Back to top |
|
 |
Steven Siebert Posted via mailing list.
|
Posted: Thu Aug 05, 2010 4:28 pm Post subject: Re: HowTo JUnit EJBs? |
|
|
| Sounds like your on the right track. |
|
| Back to top |
|
 |
tbbstny
Joined: 02 Jul 2010 Posts: 7
|
Posted: Thu Aug 05, 2010 5:34 pm Post subject: |
|
|
| Well, I thought so, until my track ended in errors. Looking for input on how to get rid of them. |
|
| Back to top |
|
 |
Steven Siebert Posted via mailing list.
|
Posted: Thu Aug 05, 2010 9:49 pm Post subject: Re: HowTo JUnit EJBs? |
|
|
Did moving the persistence.xml file help?
On Thu, Aug 5, 2010 at 1:34 PM, tbbstny <address-removed ([email]address-removed[/email])> wrote:
| Quote: | | Well, I thought so, until my track ended in errors. |
|
| Back to top |
|
 |
tbbstny
Joined: 02 Jul 2010 Posts: 7
|
Posted: Fri Aug 06, 2010 12:18 am Post subject: |
|
|
I wouldn't know where to move it to, and don't think I should have to. Maybe a false assumption, but the IDE stubbs out the persistence.xml, Test Libraries, etc, and I am expecting that it is doing so in the correct locations so that the tests run with out a need to hunt down alternative places to put things.
I got my tests running by switching to EclipseLink instead of TopLink. Not sure why it mattered. In my case it could be a mix, as I am using EclipseLink in deployment, thus that is in my 'Libraries' folder. Then I added TopLink to to my 'Test Libraries' folder. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|