Using testNG with Seam
amit.u.purohit Sep 9, 2008 3:25 AMHi
I am working on JBOSS 4.3, seam-2.0.2.SP1 on eclipse IDE. I am trying to unit test my application using the TESTNG plugin. However, I get a null pointer exception on the fields/context parameters injected using the Seam annotations,
Please, let me know what am I doing wrong here..
example code
Seam component
@Stateful
@Name("S_Movie_Service")
public class MovieService {
@In(create=true)
@Out(required=false)
Movie S_Movies;
@In(create=true)
MovieHome S_Movie_Home ;
@Logger
private Log log;
public List<Movie> getAllMovies() throws CrbException{
try{
log.debug("Getting movie information for all the movies");
return (CrbUtil.getMovieList(S_Movie_Home.getAllMovies(entityManager)));
}catch(CrbException ce){
log.error("Error occured while retreving all the movies : #0 ", ce.getMessage());
throw new CrbException("Error occured while retreving all the movies",ce);
}catch(Exception e){
log.error("Uncaught exception was caught while retreiving all the movies : #0 ", e.getMessage());
e.printStackTrace();
throw new CrbException("Uncaught exception was caught while retreiving all the movies",e);
}
}
}
here is my TestNG class
public class MovieServiceTest extends BaseServiceTest{
MovieHome movieHome = new MovieHome();
CacheLoader S_CacheLoader = new CacheLoader();
@Test
public void testGetAllMovies(){
boolean pass = true;
List<Movie> lstMovies;
EntityManager entityManager = getEntityManager();
IMovieService movieService = new MovieService();
try{
initialiseCache(S_CacheLoader);
movieService.setCrbDatabase(entityManager);
entityManager.getTransaction().begin();
lstMovies = movieService.getAllMovies();
//Print the movie details
for(Movie movie : lstMovies){
//Display the movie information
}
assert (lstMovies.size() != 0);
//Commit the transaction
entityManager.getTransaction().commit();
entityManager.close();
}catch(CrbException ce){
pass = false;
}
catch(Exception e){
pass = false;
}finally{
assert pass;
}
}
}
When I run my above test case, I get a null pointer exception on
log.debug("Getting movie information for all the movies");
suggesting that the logger has not been initialised. Same is the error for other properties injected using Seamannotations @IN
can you suggest me how can I inject the dependencies at run time through my testNG class
I am working on JBOSS 4.3, seam-2.0.2.SP1 on eclipse IDE. I am trying to unit test my application using the TESTNG plugin. However, I get a null pointer exception on the fields/context parameters injected using the Seam annotations,
Please, let me know what am I doing wrong here..
example code
Seam component
@Stateful
@Name("S_Movie_Service")
public class MovieService {
@In(create=true)
@Out(required=false)
Movie S_Movies;
@In(create=true)
MovieHome S_Movie_Home ;
@Logger
private Log log;
public List<Movie> getAllMovies() throws CrbException{
try{
log.debug("Getting movie information for all the movies");
return (CrbUtil.getMovieList(S_Movie_Home.getAllMovies(entityManager)));
}catch(CrbException ce){
log.error("Error occured while retreving all the movies : #0 ", ce.getMessage());
throw new CrbException("Error occured while retreving all the movies",ce);
}catch(Exception e){
log.error("Uncaught exception was caught while retreiving all the movies : #0 ", e.getMessage());
e.printStackTrace();
throw new CrbException("Uncaught exception was caught while retreiving all the movies",e);
}
}
}
here is my TestNG class
public class MovieServiceTest extends BaseServiceTest{
MovieHome movieHome = new MovieHome();
CacheLoader S_CacheLoader = new CacheLoader();
@Test
public void testGetAllMovies(){
boolean pass = true;
List<Movie> lstMovies;
EntityManager entityManager = getEntityManager();
IMovieService movieService = new MovieService();
try{
initialiseCache(S_CacheLoader);
movieService.setCrbDatabase(entityManager);
entityManager.getTransaction().begin();
lstMovies = movieService.getAllMovies();
//Print the movie details
for(Movie movie : lstMovies){
//Display the movie information
}
assert (lstMovies.size() != 0);
//Commit the transaction
entityManager.getTransaction().commit();
entityManager.close();
}catch(CrbException ce){
pass = false;
}
catch(Exception e){
pass = false;
}finally{
assert pass;
}
}
}
When I run my above test case, I get a null pointer exception on
log.debug("Getting movie information for all the movies");
suggesting that the logger has not been initialised. Same is the error for other properties injected using Seamannotations @IN
can you suggest me how can I inject the dependencies at run time through my testNG class