1 2 3 Previous Next 36 Replies Latest reply on Nov 12, 2007 4:25 PM by bsmithjj

    Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

      Hello,

      I used to be able to boot JBoss embedded from Seam tests in my app in the 1.2.1 and earlier days (was it only 6 months ago?). Anyway, now when I run my tests, I am getting null-pointer exceptions from a class called SeamBaseTest. For example:

      public class PersistenceUnitConfigurationTest extends SeamTest {
      
       private Log log = LogFactory.getLog(PersistenceUnitConfigurationTest.class);
      
       @Test
       public void test_GetManagedPersistenceContext_from_Seam() throws Exception {
      
       new FacesRequest() {
       protected void invokeApplication() throws Exception {
       EntityManager em = (EntityManager) getInstance("entityManager");
       assert em != null;
       }
       }.run();
      
       }
      }
      

      yields
      -------------------------------------------------------------------------------
      Test set: SampleEJB3Test
      -------------------------------------------------------------------------------
      Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.198 sec <<< FAILURE!
      test_GetManagedPersistenceContext_from_Seam Time elapsed: 0.047 sec <<< FAILURE!
      java.lang.NullPointerException
       at org.jboss.seam.mock.BaseSeamTest$Request.run(BaseSeamTest.java:504)
       at com.javaplant.mapper.police.PersistenceUnitConfigurationTest.test_GetManagedPersistenceContext_from_Seam(PersistenceUnitConfigurationTest.java:22)
      


      Ok - so it looks like there is now something called a ComponentTest, so I'll try that instead:

      public class PersistenceUnitConfigurationTest extends SeamTest {
      
       private Log log = LogFactory.getLog(PersistenceUnitConfigurationTest.class);
      
       @Test
       public void test_GetManagedPersistenceContext_from_Seam() throws Exception {
      
       new ComponentTest() {
      
       protected void testComponents() throws Exception {
       EntityManager em = (EntityManager) getInstance("entityManager");
       assert em != null;
       }
       }.run();
      
       }
      }
      

      and this yields:

      -------------------------------------------------------------------------------
      Test set: SampleEJB3Test
      -------------------------------------------------------------------------------
      Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.195 sec <<< FAILURE!
      test_GetManagedPersistenceContext_from_Seam Time elapsed: 0.07 sec <<< FAILURE!
      java.lang.NullPointerException
       at org.jboss.seam.servlet.ServletSessionMap.get(ServletSessionMap.java:54)
       at org.jboss.seam.contexts.BasicContext.get(BasicContext.java:48)
       at org.jboss.seam.contexts.Contexts.lookupInStatefulContexts(Contexts.java:199)
       at org.jboss.seam.Component.getInstance(Component.java:1844)
       at org.jboss.seam.Component.getInstance(Component.java:1839)
       at org.jboss.seam.mock.BaseSeamTest.getInstance(BaseSeamTest.java:98)
       at com.javaplant.mapper.police.PersistenceUnitConfigurationTest.access$000(PersistenceUnitConfigurationTest.java:15)
       at com.javaplant.mapper.police.PersistenceUnitConfigurationTest$1.testComponents(PersistenceUnitConfigurationTest.java:25)
       at org.jboss.seam.mock.BaseSeamTest$ComponentTest.run(BaseSeamTest.java:164)
       at com.javaplant.mapper.police.PersistenceUnitConfigurationTest.test_GetManagedPersistenceContext_from_Seam(PersistenceUnitConfigurationTest.java:22)
      


      So what's going on with SeamBaseTest?

      Thanks,
      Brad Smith

        • 1. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?
          pmuir

          Brad, I dropped your class above into Seam's integration test suite and it passed with no exceptions thrown (this is head, but nothing much has changed since CR3). So, is that the whole test?

          • 2. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

            Pete,

            Yes - the whole test. I'm mainly trying to recover the ability to bootstrap the JBoss embeddable from maven 2 in the test phase. Figuring that out the first time was horrible (more than a year ago). Is there an enumerated list of dependencies for writing Seam tests that use JPA + EJB3? Also, is there a sample (prototype) configuration for boot strapping? there used to be a <core:ejb/> tag that did the trick but that doesn't seem to be a member of the core namespace anymore.

            Thanks,
            Brad

            • 3. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?
              pmuir

              No, no enumerated list :( But, if you are using maven, try, for your test environment only, depending on org.jboss.embedded jboss-embedded, org.jboss.seam jboss-seam and that *should* be enough to run just JPA + EJB3. But take a look at the jboss-seam pom to see what dependencies Seam itself has (its fairly obvious what most are for). Remember that testing requires JBoss Embedded, *not* the jboss jar's we use to compile Seam (yes, this is a pita).


              SeamTest now bootstraps Embedded itself - I think the init() method isn't being called from your stack trace. We will try to get more examples of using Maven into Seam, but as this is quite a drastic change in Seam, we need JBoss Tools to be able to work with a maven structure first.

              • 4. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

                 

                we need JBoss Tools to be able to work with a maven structure first.


                JBoss Tools? Try IDEA 7.0 - works seamlessly with Maven 2 poms ;-) - no need to wait.

                • 5. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

                  When I was getting that exception, adding init() and begin() to the top of the method solved it. However I'm still having issues with runnings tests using Maven (work fine when run from Eclipse) -- I haven't heard of anyone successfully running Seam2 tests from Maven yet.

                  • 6. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

                    Strange how ComponentTest doesn't come with support for init()'ing the container environment. I see by adding init() (and begin()) that I can get farther, now Seam doesn't know how to create my component. Guess it's time to try FacesRequest again ... sigh....

                    Thanks

                    • 7. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?
                      pmuir

                      It most certainly does. Both init and begin are called by TestNG using @BeforeClass and @BeforeMethod - for some reason TestNG isn't calling these methods.

                      • 8. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

                        When run from Eclipse I was using JUnit4 and they weren't being called; is TestNG a requirement?

                        • 9. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

                          is this dependency no longer sufficient?

                           <dependency>
                           <groupId>org.testng</groupId>
                           <artifactId>testng</artifactId>
                           <version>4.7</version>
                           <scope>test</scope>
                           <classifier>jdk15</classifier>
                           </dependency>
                          


                          here is the test I am working with at the moment:

                          public class BootStrapTest extends SeamTest {
                          
                           @Test
                           public void test_persistenceMappingsGuud() throws Exception {
                          
                           new ComponentTest() {
                          
                           protected void testComponents() throws Exception {
                           init();
                           begin();
                           EntityManager entityManager = (EntityManager) getInstance("entityManager");
                           assert entityManager != null;
                           List<Type> types = entityManager.createQuery(
                           "from Type t"
                           ).getResultList();
                           assert types != null;
                           assert types.size() > 0;
                           }
                          
                           }.run();
                          
                           }
                          }
                          


                          I just want to be sure the container is booted and my entity model is 'correct' before other tests fire, but right now I am stuck with just trying to boot the container.

                          Thanks

                          • 10. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

                            oh yes, one rant - if a specific version of testng is required, then what happened to the days when frameworks listed out their depedencies including versions? Has listing depedencies gone the way of documentation? ;-)

                            from an old version of hibernate:

                            ant.jar (1.5.3)
                            - Ant core
                            - buildtime
                            
                            c3p0.jar (0.8.3)
                            - C3P0 JDBC connection pool
                            - runtime, optional
                            
                            cglib2.jar (2.0rc1)
                            - CGLIB bytecode generator
                            - runtime, required
                            
                            commons-collections.jar (2.1)
                            - runtime, required
                            
                            commons-dbcp.jar (1.1)
                            - runtime, optional
                            
                            commons-lang.jar (1.0.1)
                            - runtime, optional (required by JCS)
                            
                            commons-logging.jar (1.0.3)
                            - runtime, required
                            
                            commons-pool.jar (1.1)
                            - runtime, optional
                            
                            concurrent.jar
                            - runtime, optional (required by TreeCache)
                            
                            connector.jar
                            - Standard JCA API
                            - runtime, optional
                            
                            dom4j.jar (1.4)
                            - XML configuration & mapping parser
                            - runtime, required
                            
                            ehcache.jar (0.6)
                            - EHCache cache
                            - runtime, optional
                            
                            hibernate2.jar (2.0)
                            - Hibernate core
                            - runtime, required
                            
                            jaas.jar
                            - Standard JAAS API
                            - runtime, optional (required by JCA)
                            
                            jboss-cache.jar (CVS-11.12.03)
                            - TreeCache clustered cache
                            - runtime, optional
                            
                            jboss-common.jar
                            - runtime, optional (required by TreeCache)
                            
                            jboss-jmx.jar
                            - runtime, optional (required by TreeCache)
                            
                            jboss-system.jar
                            - runtime, optional (required by TreeCache)
                            
                            jcs.jar (1.0-dev)
                            - JCS cache
                            - runtime, optional (deprecated)
                            
                            jdbc2_0-stdext.jar
                            - Standard JDBC APIs
                            - runtime, required for standalone operation (outside application server)
                            
                            jgroups.jar (2.2)
                            - JGroups multicast library
                            - runtime, optional (required by replicated caches)
                            
                            jta.jar
                            - Standard JTA API
                            - runtime, required for standalone operation (outside application server)
                            
                            junit.jar (3.8.1)
                            - JUnit test framework
                            - buildtime
                            
                            odmg.jar (3.0)
                            - ODMG API 3.0
                            - runtime, required
                            
                            optional.jar (1.5.3)
                            - Ant optional tasks
                            - buildtime
                            
                            oscache.jar (2.0)
                            - OpenSymphony OSCache
                            - runtime, optional
                            
                            proxool.jar (0.7.2)
                            - Proxool JDBC connection pool
                            - runtime, optional
                            
                            swarmcache.jar (1.0rc2)
                            - SwarmCache replicated cache
                            - runtime, optional
                            
                            xalan.jar (2.4.0)
                            - XSLT processor
                            - runtime, required
                            
                            xerces.jar (2.4.0)
                            - SAX parser
                            - runtime, some SAX parser is required
                            
                            xml-apis.jar
                            - Standard JAXP API
                            - runtime, some SAX parser is required
                            



                            • 11. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

                              it looks like the version of testng supplied with Seam 2.0.0.CR3 is 5.6-200706070953 (from MANIFEST.MF file). The maven2 surefire plugin docs are based on testng 4.7 (which I was using - see previous post in thread).

                              So has anyone out there found a way to get maven2-surefire to work with testng 5.5 or higher?

                              Thanks

                              • 12. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

                                The testng docs provide some assistance with getting Maven2 and Testng 5.X to work http://testng.org/doc/maven.html#maven2...

                                • 13. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?

                                  this link is even better - pay close attention to the maven-surefire-plugin version

                                  http://www.martingilday.org/blog/2007/sep/12/testng-and-maven/

                                  • 14. Re: Writing SeamTests with Seam 2.0.0. CR2 - What's Changed?
                                    pmuir

                                     

                                    "bsmithjj" wrote:
                                    oh yes, one rant - if a specific version of testng is required, then what happened to the days when frameworks listed out their depedencies including versions? Has listing depedencies gone the way of documentation? ;-)


                                    No, we now have a dependencies chapter which discusses common runtime and compile dependencies for your project and pom's which documents the versions and dependencies for compiling and using Seam.

                                    We would like to get a report out of maven that prints out all the jars, but this seems to require us to use snapshot versions of maven plugins. I will add this for 2.0.1

                                    it looks like the version of testng supplied with Seam 2.0.0.CR3 is 5.6-200706070953 (from MANIFEST.MF file). The maven2 surefire plugin docs are based on testng 4.7 (which I was using - see previous post in thread).


                                    Yes, surefire is broken and stagnating. I think you have to use the snapshot but don't know - the last working version of testng with the released surefire is 5.1 IIRC.

                                    When run from Eclipse I was using JUnit4 and they weren't being called; is TestNG a requirement?


                                    Yes.

                                    1 2 3 Previous Next