You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by siegfried <si...@heintze.com> on 2009/05/26 10:07:33 UTC

How to examine database when testing entity beans?

I'm studying 
c:\dev\sandboxes\EJB\openejb\examples\apache\openejb-examples-3.1\simple-cmp
2\src\test\java\org\superbiz\cmp2\MoviesTest.java
 
 
Who is cleaning up the database? I thought it was using dbunit was doing it
but I see MoviesTest.java is deleting it. Hmmmm.... Could this example have
been done more efficiently with dbunit?
 
How can I pause the execution of the test so I can see the data in the HSQL
database using a client like squirrel to look at the data?
 
Thanks,
Siegfried

Re: How to examine database when testing entity beans?

Posted by Jonathan Gallimore <jo...@gmail.com>.
Hi Siegfried,

This test uses a HSQLDB in-memory database running embedded in the JVM, so
(as far as I'm aware) you can't connect to it with a client.

You could however, run an instance of HSQLDB as a server, and you can hook
up SQuirreL to that:

You can run the server from the console by running:

java -cp lib/hsqldb-1.8.0.7.jar org.hsqldb.Server -database.0 file:movies
-dbname.0 movies

And then change the properties at the top of the test to look like this:

        Properties p = new Properties();
        p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
        p.put("movieDatabase", "new://Resource?type=DataSource");
        p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
        p.put("movieDatabase.JdbcUrl",
"jdbc:hsqldb:hsql://localhost/movies");

        p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource");
        p.put("movieDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver");
        p.put("movieDatabaseUnmanaged.JdbcUrl",
"jdbc:hsqldb:hsql://localhost/movies");
        p.put("movieDatabaseUnmanaged.JtaManaged", "false");

You'll then be able to connect to the database using this JDBC URL:
jdbc:hsqldb:hsql://localhost/movies

Hope that helps.

Jon

On Tue, May 26, 2009 at 9:07 AM, siegfried <si...@heintze.com> wrote:

> I'm studying
>
> c:\dev\sandboxes\EJB\openejb\examples\apache\openejb-examples-3.1\simple-cmp
> 2\src\test\java\org\superbiz\cmp2\MoviesTest.java
>
>
> Who is cleaning up the database? I thought it was using dbunit was doing it
> but I see MoviesTest.java is deleting it. Hmmmm.... Could this example have
> been done more efficiently with dbunit?
>
> How can I pause the execution of the test so I can see the data in the HSQL
> database using a client like squirrel to look at the data?
>
> Thanks,
> Siegfried
>