1 2 Previous Next 15 Replies Latest reply on Aug 9, 2008 8:50 PM by Francisco Jose Peredo Noguez

    Spring into Seam = No Unit Testing

    Francisco Jose Peredo Noguez Master

      Hi!
      I configured Spring into Seam and now, if I try to run my unit-test (BTW my project was created by JBossTools 2.1.2) I get this error:


      
      You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: webappsbmi-test
      
      



      Full stack trace:


      
      org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):
      
      *** CONTEXTS IN ERROR: Name -> Error
      
      vfsfile:/C:/Users/fperedo/Proyectos/sbmi/implementacion/workspace/webappsbmi-test/bin/ -> java.io.IOException: Server returned HTTP response code: 403 for URL: http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd
      
      persistence.units:unitName=webappsbmi-test -> java.lang.RuntimeException: Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: webappsbmi-test
      
      
           at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:576)
           at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:559)
           at org.jboss.embedded.DeploymentGroup.process(DeploymentGroup.java:128)
           at org.jboss.embedded.Bootstrap.deployResourceBases(Bootstrap.java:289)
           at org.jboss.seam.mock.EmbeddedBootstrap.startAndDeployResources(EmbeddedBootstrap.java:15)
           at org.jboss.seam.mock.BaseSeamTest.startJbossEmbeddedIfNecessary(BaseSeamTest.java:1041)
           at org.jboss.seam.mock.BaseSeamTest.startSeam(BaseSeamTest.java:935)
           at org.jboss.seam.mock.BaseSeamTest.init(BaseSeamTest.java:923)
           at org.jboss.seam.mock.SeamTest.init(SeamTest.java:42)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
           at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:398)
           at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:145)
           at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:82)
           at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166)
           at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:103)
           at org.testng.TestRunner.runWorkers(TestRunner.java:689)
           at org.testng.TestRunner.privateRun(TestRunner.java:566)
           at org.testng.TestRunner.run(TestRunner.java:466)
           at org.testng.SuiteRunner.runTest(SuiteRunner.java:301)
           at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:296)
           at org.testng.SuiteRunner.privateRun(SuiteRunner.java:276)
           at org.testng.SuiteRunner.run(SuiteRunner.java:191)
           at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808)
           at org.testng.TestNG.runSuitesLocally(TestNG.java:776)
           at org.testng.TestNG.run(TestNG.java:701)
           at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
           at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
      
      
      



      What can I do?

        • 1. Re: Spring into Seam = No Unit Testing
          Francisco Jose Peredo Noguez Master

          Hi!


          First, let me say something very important, the Spring into Seam integration is working perfectly in aftaer a normal WAR deployment, it only fails when unit-testing.


          I have been looking for documentation on the EmbeddedBootstrap class but I can not find anything relevant in google...


          But I have a theory, the method startAndDeployResources looks like this (and the stack trace indicates it crashes on bootstrap.deployResourceBases("seam.properties"):


          public void startAndDeployResources() throws Exception
             {
                Bootstrap bootstrap = Bootstrap.getInstance();
                bootstrap.bootstrap();
          
                if (resourceExists("seam.properties")) 
                {
                   bootstrap.deployResourceBases("seam.properties");
                }
                if (resourceExists("META-INF/components.xml")) 
                {
                   bootstrap.deployResourceBases("META-INF/components.xml");
                }
                if (resourceExists("META-INF/seam.properties")) 
                {
                   bootstrap.deployResourceBases("META-INF/seam.properties");
                }
             }
          
          



          So I am guessing that it fails because bootstrap.deployResourceBases("seam.properties" happens before bootstrap.deployResourceBases("META-INF/components.xml") and since the configuration for spring related stuff is in components.xml the embbeded jboss is unable to find the datasource configuration and fails.


          Am I right?



          • 2. Re: Spring into Seam = No Unit Testing
            Francisco Jose Peredo Noguez Master

            Hi!


            I also decided to take a look at the spring examples included in Seam 2.0.2SP1, in jboss-seam-2.0.2.SP1\examples\spring\readme.txt I read: Note: there is no testng suite for this example.


            But, at the same time I see in jboss-seam-2.0.2.SP1\examples\spring\src\org\jboss\seam\example\spring\test a file named StartupTest.java that really looks like a testng suite for this example, but if I try to run examples by writing ant test in the command line (inside the jboss-seam-2.0.2.SP1\examples\spring\ directory) I get a:


            BUILD FAILED
            Target "test" does not exist in the project "Spring Example".
            



            So... do tests work when Spring and Seam are integrated? or not?


            Thanks,


            • 3. Re: Spring into Seam = No Unit Testing
              Francisco Jose Peredo Noguez Master

              Okey, so I decided to go with my theory that the problem is the early call to:


               if (resourceExists("seam.properties")) 
                    {
                       bootstrap.deployResourceBases("seam.properties");
                    }
              



              and changed its order (after bootstrap.deployResourceBases("META-INF/components.xml")) but it only helped to make it crash later.


              So I tried just commenting it out... and got this error. As I may have mentioned before, we have heavly modified my seam-gen, and a have a .jar with custom code to deal with my new annotations (and the old ones in a new way, for example, we added support for many2many relationships in seam-gen). Well, that new project with my utility classes and new annotations has a lib folder with jboss-seam.jar on it, so I decided to configure an eclipse user library instead, and it failed in the same way:


              vfsjar:file:/C:/devstudio/jboss-eap/jboss-seam-2.0.2.SP1/lib/jboss-seam.jar!/ -> java.lang.IllegalStateException: Container jboss.j2ee:jar=jboss-seam.jar,name=TimerServiceDispatcher,service=EJB3,VMID=d09598faaa6701b9:1e08e762:11b6adc551f:-8000 + is already registered
              



              So, I enter again to the eclipse build path configuration, and I try with the add jar button, and select the jboss-seam.jar inside my WAR project.


              And voila! now my unit-test is working!


              But now I have a lot of questions...



              1. Why does the test-project get confused if another project references jboss-seam.jar (but only if that jboss-seam.jar is not in the WEB-INF\lib of the WAR project?)

              2. Why if I change the order of  bootstrap.deployResourceBases("seam.properties"); to be after bootstrap.deployResourceBases("META-INF/components.xml"); it still crashes?

              3. What is the purpose of the bootstrap.deployResourceBases("seam.properties"); (other than making it impossible to run the test if using Spring integration ;-) )?



              As anyone can see, I am doing my homework, I am searching in google, and I am trying to understand this stuff, but still need some help... (I am worried about going to have strange secondary effects because I commented the line bootstrap.deployResourceBases("seam.properties");... Is my workaround safe? Should I submit a JIRA?


              Any hints?

              • 4. Re: Spring into Seam = No Unit Testing
                Pete Muir Master

                Try to explain clearly and simply your problem from a well known starting point.

                • 5. Re: Spring into Seam = No Unit Testing
                  Francisco Jose Peredo Noguez Master

                  Hi!



                  Pete Muir wrote on Jul 29, 2008 12:38:


                  Try to explain clearly and simply your problem from a well known starting point.



                  Okey, here it goes again:


                  I am using Seam 2.0.2SP1, with  JBossTools 2.1.2, JDK 1.5_14. Windows XP.
                  I configured Spring into Seam and now as explained here, and it worked as explained in the article.


                  Then I tried to run my unit-tests, and they failed:


                  
                  You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: webappsbmi-test
                  
                  



                  So I started looking at the stacktrace, and the crash seemed to come here:


                  public void startAndDeployResources() throws Exception
                     {
                        Bootstrap bootstrap = Bootstrap.getInstance();
                        bootstrap.bootstrap();
                  
                        if (resourceExists("seam.properties")) 
                        {
                           bootstrap.deployResourceBases("seam.properties");
                        }
                        if (resourceExists("META-INF/components.xml")) 
                        {
                           bootstrap.deployResourceBases("META-INF/components.xml");
                        }
                        if (resourceExists("META-INF/seam.properties")) 
                        {
                           bootstrap.deployResourceBases("META-INF/seam.properties");
                        }
                     }
                  



                  The line bootstrap.deployResourceBases("seam.properties"); is the one that produces the crash, so I comment it on the theory that is trying to load Seam configuration before the components.xml and therefore it doesn't know that Spring is now responsible for providing the datasource. (After that I realize that, while trying other solutions to make my unit-tests work, I had reconfigured the java build path of another project, causing this error and I am pretty sure this is a bug in the way test projects dependencies are handled in eclipse)


                  Now, everything works fine.
                  Questions:



                  1. Why does the test-project get confused if another project references jboss-seam.jar (but only if that jboss-seam.jar is not in the WEB-INF\lib of the WAR project?)

                  2. What is the purpose of the bootstrap.deployResourceBases("seam.properties");? I deleted it and now everything works...

                  3. Since I commented this line... will I start seeing some kind of missing functionality or instability later? should I submit a JIRA saying that this line prevents unit-test integration with Spring?



                  I really hope I explained my problem better this time :$.


                  Thanks,



                  • 6. Re: Spring into Seam = No Unit Testing
                    Pete Muir Master

                    1) I've no idea what you are asking. This sounds like some odd Eclipse WTP stuff, ask on the JBoss Tools forum.
                    2) To deploy archive (exploded or collapsed) which contain seam.properties - without it that won't be used as a marker for deploying archives
                    3) Yes. No, it's got nothing to do with Seam/Spring integration, just your test setup.


                    Post the -ds.xml and persistence.xml used in your test setup.

                    • 7. Re: Spring into Seam = No Unit Testing
                      Francisco Jose Peredo Noguez Master

                      Hi!



                      Pete Muir wrote on Jul 29, 2008 16:37:


                      1) I've no idea what you are asking. This sounds like some odd Eclipse WTP stuff, ask on the JBoss Tools forum.


                      Okey.



                      2) To deploy archive (exploded or collapsed) which contain seam.properties - without it that won't be used as a marker for deploying archives


                      Well, and why if I delete it everything seems to work fine?



                      3) Yes. No, it's got nothing to do with Seam/Spring integration, just your test setup.

                      Post the -ds.xml and persistence.xml used in your test setup.


                      IMHO the -ds.xml is irrelevant (I am using Seam/Spring integration and therefore Spring is providing the datasource (As you can see on Listing 1), the -ds.xml is just not used, I can delete it (just tested) from my project and everything still works fine,but of course I will use it for the final deployment to take advantage of connection pooling)


                      
                      <?xml version="1.0" encoding="UTF-8"?>
                      
                      <!DOCTYPE datasources
                          PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
                          "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
                          
                      <datasources>
                            
                         <local-tx-datasource>
                            <jndi-name>webappsbmiDatasource</jndi-name>
                            
                            <connection-url>jdbc:oracle:thin:@****:1521:****</connection-url>
                            <driver-class>oracle.jdbc.OracleDriver</driver-class>
                            <user-name>****</user-name>
                            <password>****</password>
                      
                         </local-tx-datasource>
                          
                      </datasources>
                      
                      



                      The persistence.xml is almost as irrelevant, is nothing more than a required placeholder, as you can see in Listing 2. It is just empty.


                      
                      <?xml version="1.0" encoding="UTF-8"?>
                      <!-- Persistence deployment descriptor for dev profile -->
                      <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
                                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
                                   version="1.0">
                                      
                         <persistence-unit name="webappsbmi-test" transaction-type="RESOURCE_LOCAL"> 
                         </persistence-unit>
                               
                      </persistence>
                      
                      



                      This 2 files become irrelevant and almost irrelevant because of Seam/Spring integration, so, I think it has  everything do with Seam/Spring integration. Am I wrong?


                      Thanks,


                      Regards,





                      • 8. Re: Spring into Seam = No Unit Testing
                        youngm Novice
                        A couple of comments.

                        1. It appears you are using JBoss DataSource management to provide a datasource through JNDI to Spring right?  I would guess that datasource would be a JTA datasource and so your transaction-type in persistenct.xml should be JTA?

                        2. It also appears that JBoss embedded is attempting to deploy your EMF.  Do you want this?  Or do you want spring to manage your EMF using something like a LocalContainerEntityManagerFactoryBean?  In that case we need to figure out some way to stop EmbeddedJBoss from attempting to deploy your EMF.

                        Generally when I integrate Spring+Seam I utilize Spring as a replacement for Embedded JBoss and use Spring to manage the datasource, etc.  Though I imagine that this approach should work too assuming you can stop Embedded JBoss from attempting to create your EMF.  What App Server are you deploying to when it works?  Jboss or Tomcat?

                        If Tomcat I would recommend either having JBossEmbedded manage your EMF and simply get an instance of it through JNDI in Spring.  If you don't want that approach then eliminate JbossEmbedded all together and just use Spring to manage you datasource and EMF.

                        Spring+Seam+integration tests work fine.  However, I have not tested using Spring+Seam+JbossEmbedded+integration test.

                        Mike
                        • 9. Re: Spring into Seam = No Unit Testing
                          Francisco Jose Peredo Noguez Master

                          Hi!




                          Mike Youngstrom wrote on Jul 29, 2008 22:47:


                          A couple of comments.

                          1. It appears you are using JBoss DataSource management to provide a datasource through JNDI to Spring right?  I would guess that datasource would be a JTA datasource and so your transaction-type in persistenct.xml should be JTA?


                          Right now, that would be wrong, I am not using JNDI for development, that is why I say that -ds.xml file is irrelevant (but I will use it on the final production deployment), it is more convenient not use JNDI, that way, I can customize my datasource without messing with the entire container, why? for example to use log4jdbc without having to copy stuff into jboss-4.2.2.GA\server\default\lib. I prefer to keep my Jboss as clean as possible during development.




                          2. It also appears that JBoss embedded is attempting to deploy your EMF.  Do you want this?  Or do you want spring to manage your EMF using something like a LocalContainerEntityManagerFactoryBean?  In that case we need to figure out some way to stop EmbeddedJBoss from attempting to deploy your EMF.


                          I have figured that one (or, to be more precise Dan Allen figured that one out)




                          Generally when I integrate Spring+Seam I utilize Spring as a replacement for Embedded JBoss and use Spring to manage the datasource, etc.  Though I imagine that this approach should work too assuming you can stop Embedded JBoss from attempting to create your EMF.  What App Server are you deploying to when it works?  Jboss or Tomcat?



                          JBoss, the problem, is not that it fails when I run my WAR on Jboss, let me state that again: my WAR deployment works perfectly, my problem is that my tests do not work (unless I disable bootstrap.deployResourceBases("seam.properties"); in EmbeddedBootstrap ).




                          If Tomcat I would recommend either having JBossEmbedded manage your EMF and simply get an instance of it through JNDI in Spring.  If you don't want that approach then eliminate JbossEmbedded all together and just use Spring to manage you datasource and EMF.



                          If you know how to  eliminate JbossEmbedded all together when running Seam tests, I'd love to be able to do that..




                          Spring+Seam+integration tests work fine.  However, I have not tested using Spring+Seam+JbossEmbedded+integration test.

                          Mike



                          How did you manage to the run integration tests without JbossEmbedded? I thought it was a requirement. (By integration tests I mean those that inherit from org.jboss.seam.mock.SeamTest as described here)


                          Or.. do you test things using a completely different approach?


                          • 10. Re: Spring into Seam = No Unit Testing
                            youngm Novice

                            I believe if you remove any jboss-embedded jars from your classpath it will run without embedded jboss.


                            Just make sure you don't have any classes in your classpath with org.jboss.embedded.Bootstrap.class in it and it should run standalone.


                            Mike

                            • 11. Re: Spring into Seam = No Unit Testing
                              Francisco Jose Peredo Noguez Master

                              I cannot believe I am actually writing this, but you are right, if I disable the startup of jboss-embedded it... it actually... works? works! and way faster! (10 seconds faster!) and if just delete jboss-embedded jars, it runs even faster! (11 seconds faster), so now, instead of taking 24 seconds to run 1 tests, it takes 13 seconds!


                              Oh, and BTW, with jboss-embedded deleted, EmbeddedBootstrap.startAndDeployResources is never executed, and, since my tests still pass, now I am even more puzzled (what is the purpose of all the code in EmbeddedBootstrap.startAndDeployResources then?

                              • 12. Re: Spring into Seam = No Unit Testing
                                Pete Muir Master

                                As you aren't deploying EJBs, then you don't need the container to deploy archives which contain EJBs.

                                • 13. Re: Spring into Seam = No Unit Testing
                                  Francisco Jose Peredo Noguez Master

                                  it would be nice to see an error message saying that instead of persistence.units:unitName=webappsbmi-test -> java.lang.RuntimeException: Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named: webappsbmi-test ;-)

                                  1 2 Previous Next