4 Replies Latest reply on Sep 16, 2008 12:52 AM by Amit Purohit

    Integration testing in Seam using TESTNG

    Amit Purohit Newbie
      I could test most of my services using the examples provided in the Seam documentation.
      However, I have a requirement, wherein my database services would accept a movie object and persist it as shown below

      public void persistMovieObj(Movie movie) {
              try{
                      log.debug("Persisting movie information for the movie : " + movie.getTitle() );
                      entityManager.persist(movie);
              }catch(Exception e){
                      log.error("Unhandled exception was caught while persisting movie : " + movie.getTitle() );
              }
      }






      my test method is as shown below:

      @Test
      public void testPersistMovie() throws Exception{
              new FacesRequest() {

              @Override
              protected void invokeApplication()
              {
                      boolean pass = true;
                      try{
                              Movie movie =(Movie)Component.getInstance(Movie.class, create);
                              movie.setTitle("Movie1");
                              invokeMethod("#{S_Movie_Service.persistMovieObj(movie)}");
                      }catch(Exception e){
                              log.error("Error occured " + e.getMessage());
                              e.printStackTrace();
                              pass = false;
                      }finally{
                              assert pass;
                      }

              }

              }.run();
      }

      The above method doest not seem to pass the movie object to the services layer and hence I get a null movie object when I try to persist the movie

      Can you please tell me what I am doing wrong or the changes to be made in the code ?
      Help Really Appreciated
      Description   
         Thanks for the reply. I could test most of my services using the examples provided in the Seam documentation. However, I have a requirement, wherein my database services would accept a movie object and persist it as shown below
        
         public void persistMovieObj(Movie movie)
         {
                 try{
                         log.debug("Persisting movie information for the movie : " + movie.getTitle() );
                         entityManager.persist(movie);
                 }catch(Exception e){
                      log.error("Unhandled exception was caught while persisting movie : " + movie.getTitle() );
                 }
         }

         my test method is as shown below:
        
         @Test public void testPersistMovie() throws Exception
         {
                 new FacesRequest()
                         { @Override protected void invokeApplication()
                                 {
                                 boolean pass = true;
                                 try{
                                         Movie movie =(Movie)Component.getInstance(Movie.class, create);
                                         movie.setTitle("Movie1");
                                         invokeMethod("#{S_Movie_Service.persistMovieObj(movie)}");
                                 }catch(Exception e){
                                         log.error("Error occured " + e.getMessage());
                                         e.printStackTrace();
                                         pass = false;
                                 }finally
                                 { assert pass; } }
                 }.run();
         }
         The above method doest not seem to pass the movie object to the services layer and hence I get a null movie object
         when I try to persist the movie
         Can you please tell me what I am doing wrong or the changes to be made in the code ? Help Really Appreciated