tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amber <>
Subject Re: openEJB fail on second test
Date Wed, 22 Feb 2012 20:45:22 GMT
Romain, thanks for your advices :)

Of course if I remove the transaction code I have to use the entity manager
from the EJB and not the one remains in the test class ^^ (I should have
delete it..)

Anyway the code is working now and I even tried to move it to a Web Service.
works fine..except one thing : after the delete, the final assertion failed
(null pointer) I don't know why ?

Here the code :

*The movie :* 

public class Movie {

    private long id; 

*The movies *
@WebService(endpointInterface = "org.superbiz.altdd.IMoviesWS", serviceName
= "MoviesWebService", targetNamespace = "")
public class Movies implements IMoviesWS {

	@PersistenceContext(unitName = "movie-unit", type =
	private EntityManager entityManager;

	public void addMovie(Movie movie) throws Exception {

	public void deleteMovie(Movie movie) throws Exception {
		entityManager.remove(entityManager.find(Movie.class, movie.getId()));

	public List<Movie> getMovies() throws Exception {
		Query query = entityManager.createQuery("SELECT m from Movie as m");
		return query.getResultList();

*The interface of the WS :*

@WebService(name = "IMoviesWS", targetNamespace =
public interface IMoviesWS {

	void addMovie(Movie movie) throws Exception;

	void deleteMovie(Movie movie) throws Exception;

	List<Movie> getMovies() throws Exception;

*And the test :*

public class MoviesTest extends TestCase {

	@WebServiceRef(wsdlLocation = "")
	private IMoviesWS movies;

	private InitialContext initialContext;

	public void setUp() throws Exception {

		Properties properties = new Properties();
		properties.put("movieDatabase", "new://Resource?type=DataSource");
		properties.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
		properties.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");

		properties.setProperty("openejb.embedded.remotable", "true");

		initialContext = new InitialContext(properties);
		initialContext.bind("inject", this);

	public void test() throws Exception {
		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) {
		/*// do a null pointer exception why?*/
		// assertEquals("Movies.getMovies()", 0, movies.getMovies().size());

	public void testWS() throws Exception {
		Service movieService = Service.create(new URL(
				""), new QName(
				"", "MoviesWebService"));

		IMoviesWS mv = movieService.getPort(IMoviesWS.class);
		mv.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992));
		assertEquals("List.size()", 1, movies.getMovies().size());

thank you for your patience!
And I hope this will help other noobs like me ))

View this message in context:
Sent from the OpenEJB User mailing list archive at

View raw message