6 Replies Latest reply on Oct 13, 2014 3:14 AM by manarh

    JUnitSeamTest Initialization Components from xml

    vata2999

      manarh  I'm trying to add Arquillian to Seam 2.2 . I added JUnitSeamTest, after running a unit test I get this exception

       

      java.lang.IllegalArgumentException: You must specify org.jboss.seam.core.init.jndiPattern or use @JndiName
      
      
      

       

      after debugging I realized in Initialization.java following method can not find JNDI even though I define JNDI in components.xml

       

      <core:init jndi-pattern="java:app/myseam-ejb/#{ejbName}" debug="true" distributable="false"/>
      

       

      protected void addComponent(ComponentDescriptor descriptor, Context context)
         {
            String name = descriptor.getName();
            String componentName = name + COMPONENT_SUFFIX;
            try
            {
               Component component = new Component(
                     descriptor.getComponentClass(),
                     name,
                     descriptor.getScope(),
                     descriptor.isStartup(),
                     descriptor.getStartupDependencies(),
                     descriptor.getJndiName() //returns null for EJB
                  );
      
      
      

       

      how can I fix this ?

        • 1. Re: JUnitSeamTest Initialization Components from xml
          manarh

          Do you mean you added this class jboss-seam/JUnitSeamTest.java at Seam_2_3 · seam2/jboss-seam · GitHub or different source?

           

          Basically Arquillian usage in Seam 2.3 uses components.xml from src/test/resources/WEB-INF directory which is added to test archive prepared by Shrinkwrap API calls.

           

          Look at jboss-seam/seam-integration-tests/src/test/resources/WEB-INF at Seam_2_3 · seam2/jboss-seam · GitHub and jboss-seam/Deployments.java at Seam_2_3 · seam2/jboss-seam · GitHub

           

          If you use Maven that is what you should do.

          • 2. Re: Re: JUnitSeamTest Initialization Components from xml
            vata2999

            I exactly added the class you mentioned from Seam 2.3 to Seam 2.2 and yes I'm using Maven.

            unlike the sample you pointed I'm trying to deploy an EAR file as following in Arquillian

             

            @Deployment(testable = false) 
                public static Archive<?> createDeployment() 
                { 
                    //TODO : get from System.getProperties(testDeployment) 
                    String testDeployment = "/home/omidbiz/blog-ear/target/blog.ear";//can not deploy exploded archive 
                    String deploymentName = testDeployment.substring(testDeployment.lastIndexOf("/") + 1); 
            
            
                    Class<? extends Archive<?>> deploymentClass = EnterpriseArchive.class; 
            
            
                    return ShrinkWrap.create(ZipImporter.class, deploymentName).importFrom(new File(testDeployment)).as(deploymentClass); //there is no addAsWebInfResource for EnterpriseArchive
                } 
            
            

             

            which I took from https://github.com/seam2/jboss-seam/blob/Seam_2_3/functional-tests/src/main/java/org/jboss/seam/example/common/test/DeploymentResolver.java

             

            can I deploy a Seam EAR file into Arquillian ? (the EAR file successfully runs in JBoss AS 7)

            • 3. Re: Re: JUnitSeamTest Initialization Components from xml
              manarh

              Omid,

              you can use EAR in Arquillian.

               

              Try to debug the content of your test EAR, like is described here http://arquillian.org/guides/getting_started_rinse_and_repeat/#export_the_deployment Seam 2.3 tests are using this option to have prepared a test archive in case of a deployment failure and that is not clear why it happens.

               

              Btw you are not trying to import exploded directory by

              ShrinkWrap.create(ZipImporter.class, deploymentName).importFrom(File) ? that is designed for already existing archive not directory I think.

              1 of 1 people found this helpful
              • 4. Re: Re: Re: JUnitSeamTest Initialization Components from xml
                vata2999

                I managed to solve the previous error now I get the following exception

                 

                java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:/myseamEntityManagerFactory
                  at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:261)
                
                Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
                  at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
                  at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
                  at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
                  at javax.naming.InitialContext.lookup(InitialContext.java:411)
                  at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:257)
                  ... 103 more
                
                
                

                 

                I don't understand the Arquillian if it's using the jboss that I define in arquillian.xml then everything should be ok

                 

                arquillian.xml

                 

                <arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://jboss.org/schema/arquillian"
                    xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
                
                
                    <defaultProtocol type="Servlet 3.0" />
                
                
                    <engine>
                        <property name="deploymentExportPath">target</property>
                    </engine>
                  
                    <container qualifier="jboss7" default="true">
                        <configuration>
                            <property name="jbossHome">/home/omidbiz/jboss-eap-6.2/</property>
                            <property name="javaVmArguments">-Xms512m -Xmx512m -XX:MaxPermSize=512m -Djava.net.preferIPv4Stack=true -XX:-UseSplitVerifier</property>          
                        </configuration>
                    </container>
                
                
                </arquillian>
                
                
                

                 

                TestCase.java

                 

                @Test
                    public void simpleEntryTest() throws Exception
                    {
                
                
                        String id = "simpleBlogEntry";
                        String title = "Simple blog entry";
                        String excerpt = "This is an excerpt";
                        String body = "This is a simple blog entry posted for testing purposes.";
                
                
                        System.out.println(id);
                        new ComponentTest()
                        {
                
                
                            @Override
                            protected void testComponents() throws Exception
                            {
                                DBUtil du =  (DBUtil) getValue("#{dbUtil}");
                                System.out.println(du.getEntityManager()); // this line throw the exception
                            }
                          
                        }.run();
                    }
                
                
                

                 

                I also realize that seam-integration-tests module is using Arquillian differently with packaging a war file after I changed my test module I get this exception

                 

                Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014395: Could not load component class org.jboss.seam.mock.MockSeamListener"}}
                
                • 5. Re: Re: Re: JUnitSeamTest Initialization Components from xml
                  manarh

                  You very probably use Seam 2.2 or 2.3.0.ALPHA which doesn't have the org.jboss.seam.mock.MockSeamListener class - it was added in 2.3.0.Beta2 - implementation of MockSeamListener · 3b57cc1 · seam2/jboss-seam · GitHub

                  I also realize that seam-integration-tests module is using Arquillian differently with packaging a war file after I changed my test module I get this exception

                   

                  1. Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS014395: Could not load component class org.jboss.seam.mock.MockSeamListener"}} 

                   

                  We use everywhere it is possible the easiest packaging - WAR - to not depend on building of whole EAR packagement. So almost all EJB tests are done in WAR only packagement.

                  • 6. Re: Re: Re: JUnitSeamTest Initialization Components from xml
                    manarh

                    Not sure with the error, but I would think that something is wrong with your configuration. Just try to deploy the test deployment as standard deployment manually into server and you will see if that persists. How do you launch your tests?

                    1. java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:/myseamEntityManagerFactory 
                    2.   at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:261) 
                    3.  
                    4. Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial 
                    5.   at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) 
                    6.   at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) 
                    7.   at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344) 
                    8.   at javax.naming.InitialContext.lookup(InitialContext.java:411) 
                    9.   at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManagerFactoryFromJndiOrValueBinding(ManagedPersistenceContext.java:257) 
                    10.   ... 103 more