tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Louis MONTEIRO <jean-louis.monte...@atosorigin.com>
Subject Re: "Local server is not initialized"
Date Wed, 10 Sep 2008 09:20:23 GMT

Andreas,

May be you can define properties statically.
And then, use always new InitialContext(props) or use a jndi.properties file
if you are running JUnit test cases.

Jean-Louis




Andreas Karalus wrote:
> 
> Here is a simple example to show that the lookup is failing. 
> The class is the testclass from openejb jpa-hibernate example. I added a
> new test2 method to simulate behaviour. 
> 
> 
> package org.superbiz.injection.h3jpa;
> 
> import junit.framework.TestCase;
> 
> import javax.naming.Context;
> import javax.naming.InitialContext;
> import java.util.Properties;
> import java.util.List;
> 
> import org.superbiz.injection.h3jpa.Movie;
> import org.superbiz.injection.h3jpa.Movies;
> 
> /**
>  * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27
> Dec 2007) $
>  */
> public class MoviesTest extends TestCase {
> 
>     public void test() throws Exception {
>         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:mem:moviedb");
> 
>         p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource");
>         p.put("movieDatabaseUnmanaged.JdbcDriver",
> "org.hsqldb.jdbcDriver");
>         p.put("movieDatabaseUnmanaged.JdbcUrl",
> "jdbc:hsqldb:mem:moviedb");
>         p.put("movieDatabaseUnmanaged.JtaManaged", "false");
> 
>         Context context = new InitialContext(p);
> 
>         Movies movies = (Movies) context.lookup("MoviesLocal");
> 
>         movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs",
> 1992));
>         movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
>         movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
> 
>         List<Movie> list = movies.getMovies();
>         assertEquals("List.size()", 3, list.size());
> 
>         for (Movie movie : list) {
>             movies.deleteMovie(movie);
>         }
> 
>         assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
>     }
>     
>     /**
>      * this method simulates a call in production code, 
>      * with a bean lookup from a normal "POJO" class 
>      *
>      * @throws Exception
>      */
>     public void test2() throws Exception{
>     	// this call unfortunately fails.
>     	// question is how can we instantiate another initalContext while
> openejb is running, whithout touching production code? 
>     	InitialContext context = new InitialContext();
>     	Movies movies = (Movies) context.lookup("MoviesLocal");
>     	assertNotNull(movies);
>     }
> }
>  
> 

-- 
View this message in context: http://www.nabble.com/%22Local-server-is-not-initialized%22-tp19396008p19409679.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Mime
View raw message