[jboss-user] [EJB 3.0] - Problems with TestNG

chawax do-not-reply at jboss.com
Fri Jul 20 05:19:37 EDT 2007


Hi,

I use AndroMDA to generate a project with EJB3. It generates test classes with TestNG, which use Jboss EJB3 embedded container. 

But when I run the tests, they fail with the following exception :

java.lang.RuntimeException: java.net.MalformedURLException: no protocol: and

The full stack trace :

-------------------------------------------------------
  |  T E S T S
  | -------------------------------------------------------
  | WARN  20-07 10:19:43,713 (Ejb3Configuration.java:addXMLEntities:365)  -Persistence provider caller does not implements the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null.
  | WARN  20-07 10:19:44,119 (AnnotationBinder.java:bindClass:543)  -Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: fr.horoquartz.t4.core.absence.DemandeAbsence
  | WARN  20-07 10:19:47,230 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:47,324 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:47,371 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:47,464 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:47,527 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:47,589 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:47,652 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:47,902 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:47,965 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:47,980 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,027 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,074 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,105 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,136 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,168 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,230 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,262 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,340 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,387 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,418 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,449 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,496 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,543 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,715 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,762 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | WARN  20-07 10:19:48,777 (JBossTimerServiceFactory.java:restoreTimerService:112)  -TIMER SERVICE IS NOT INSTALLED
  | lookup 
  |   CodeHoraireDao: org.jnp.interfaces.NamingContext
  |   I18nLibelleTraduitDao: org.jnp.interfaces.NamingContext
  |   I18nAttributDao: org.jnp.interfaces.NamingContext
  |   SectionHoraireDao: org.jnp.interfaces.NamingContext
  |   LigneDemandeAbsenceDao: org.jnp.interfaces.NamingContext
  |   RoleDao: org.jnp.interfaces.NamingContext
  |   JourneeEmployeDao: org.jnp.interfaces.NamingContext
  |   ServiceAbsenceBean: org.jnp.interfaces.NamingContext
  |   ServiceDemandeBean: org.jnp.interfaces.NamingContext
  |   ServiceEmployeBean: org.jnp.interfaces.NamingContext
  |   LigneProfilHoraireJournalierDao: org.jnp.interfaces.NamingContext
  |   ProfilHoraireJournalierDao: org.jnp.interfaces.NamingContext
  |   MotifAbsenceDao: org.jnp.interfaces.NamingContext
  |   AbsenceDao: org.jnp.interfaces.NamingContext
  |   UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
  |   DemandeDao: org.jnp.interfaces.NamingContext
  |   EmployeDao: org.jnp.interfaces.NamingContext
  |   DemandeAbsenceDao: org.jnp.interfaces.NamingContext
  |   ServiceWorkflowBean: org.jnp.interfaces.NamingContext
  |   ServiceDeclarantBean: org.jnp.interfaces.NamingContext
  |   I18nLanguageDao: org.jnp.interfaces.NamingContext
  |   CompteUtilisateurDao: org.jnp.interfaces.NamingContext
  |   ServiceUtilisateurBean: org.jnp.interfaces.NamingContext
  |   LigneCodeHoraireDao: org.jnp.interfaces.NamingContext
  |   AttributionHoraireDao: org.jnp.interfaces.NamingContext
  |   I18nServiceBean: org.jnp.interfaces.NamingContext
  |   LigneAttributionHoraireDao: org.jnp.interfaces.NamingContext
  | Running t4Seam Services Test
  | WARN  20-07 10:19:48,918 (ServiceEmployeTest.java:testCreateEmploye:74)  -Failed test testCreateEmploye()
  | java.lang.RuntimeException: java.net.MalformedURLException: no protocol: and
  | 	at org.jboss.aop.joinpoint.MethodInvocation.getArguments(MethodInvocation.java:281)
  | 	at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:258)
  | 	at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:58)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
  | 	at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
  | 	at $Proxy39.createEmploye(Unknown Source)
  | 	at fr.horoquartz.t4.core.employe.test.ServiceEmployeTest.testCreateEmploye(ServiceEmployeTest.java:70)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | 	at java.lang.reflect.Method.invoke(Method.java:585)
  | 	at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:552)
  | 	at org.testng.internal.Invoker.invokeMethod(Invoker.java:407)
  | 	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:778)
  | 	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
  | 	at org.testng.TestRunner.privateRun(TestRunner.java:682)
  | 	at org.testng.TestRunner.run(TestRunner.java:566)
  | 	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:220)
  | 	at org.testng.SuiteRunner.run(SuiteRunner.java:146)
  | 	at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:713)
  | 	at org.testng.TestNG.runSuitesLocally(TestNG.java:676)
  | 	at org.apache.maven.surefire.testng.TestNGExecutor.executeTestNG(TestNGExecutor.java:64)
  | 	at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
  | 	at org.apache.maven.surefire.Surefire.run(Surefire.java:129)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  | 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  | 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  | 	at java.lang.reflect.Method.invoke(Method.java:585)
  | 	at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:225)
  | 	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:747)
  | Caused by: java.net.MalformedURLException: no protocol: and
  | 	at java.net.URL.<init>(URL.java:567)
  | 	at java.net.URL.<init>(URL.java:464)
  | 	at java.net.URL.<init>(URL.java:413)
  | 	at sun.rmi.server.LoaderHandler.pathToURLs(LoaderHandler.java:747)
  | 	at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:147)
  | 	at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
  | 	at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
  | 	at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:197)
  | 	at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1544)
  | 	at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1466)
  | 	at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1699)
  | 	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1305)
  | 	at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1634)
  | 	at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
  | 	at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
  | 	at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
  | 	at org.jboss.aop.joinpoint.MethodInvocation.getArguments(MethodInvocation.java:276)
  | 	... 29 more
  | 

My test method :

    @org.testng.annotations.Test
  |     public void testCreateEmploye() 
  |     {
  |         try
  |         {
  |             fr.horoquartz.t4.core.employe.ServiceEmployeRemote serviceEmploye = (fr.horoquartz.t4.core.employe.ServiceEmployeRemote)EJB3Container.getInitialContext().lookup("ServiceEmployeBean/remote");
  |             
  |             VOEmploye employe = new VOEmploye();
  |             employe.setAdresse("adresse");
  |             employe.setDateNaissance((new GregorianCalendar(1974, Calendar.SEPTEMBER, 7)).getTime());
  |             employe.setMail("mail");
  |             employe.setMatricule("000000");
  |             employe.setNom("nom");
  |             employe.setPays("FRANCE");
  |             employe.setPrenom("prenom");
  |             employe.setTelephone("00 00 00 00 00");
  |             employe.setVille("VILLE");
  |             
  |             serviceEmploye.createEmploye(employe);
  |         }
  |         catch (Exception ex)
  |         {
  |             logger.warn("Failed test testCreateEmploye()", ex);
  |         }
  |     }
  | 

There is no error when I don't call the serviceEmploye.createEmploye() method, so I think there is no problem while finding the ServiceEmployeBean session bean in JNDI context. But it crashes when I call methods on this session bean.

A piece of the ejb-jar.xml file :

        <session>
  |             <description>
  |                 <![CDATA[
  |                 
  |                 ]]>
  |             </description>
  |             <ejb-name>ServiceEmployeBean</ejb-name>
  |             <remote>fr.horoquartz.t4.core.employe.ServiceEmployeRemote</remote>
  |             <ejb-class>fr.horoquartz.t4.core.employe.ServiceEmployeBean</ejb-class>
  |             <session-type>Stateless</session-type>
  |             <transaction-type>Container</transaction-type>
  |         </session>
  | 

For what I understood, the EJB3 embedded container is started with this class :

// license-header java merge-point
  | //
  | // Generated by: EJB3Container.vsl in andromda-ejb3-cartridge.
  | //
  | package fr.horoquartz.t4.seam.test;
  | 
  | import java.util.Hashtable;
  | 
  | import javax.naming.Context;
  | import javax.naming.InitialContext;
  | 
  | import org.apache.commons.logging.Log;
  | import org.apache.commons.logging.LogFactory;
  | import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
  | import org.jboss.ejb3.embedded.EJB3StandaloneDeployer;
  | 
  | import org.testng.annotations.Configuration;
  | 
  | /**
  |  * Boots the JBoss Microcontainer with an EJB3 configuration.
  |  *
  |  * You can also use this class to lookup managed beans from JNDI.
  |  *
  |  * @author vancek
  |  * <p><b>Note</b>. code was copied from christian.bauer at jboss.com
  |  * example on Hibernate's CaveatEmptor application
  |  * </p>
  |  */
  | public class EJB3Container 
  | {
  |     private final static Log logger = LogFactory.getLog(EJB3Container.class);
  |     
  |     private EJB3StandaloneDeployer deployer;
  | 
  |     @Configuration(beforeTest = true)
  |     public void startup() 
  |     {
  |         try 
  |         {
  |     	    logger.info("==>Bootstrapping EJB3 container...");
  |     
  |             // Boot the JBoss Microcontainer with EJB3 settings, loads ejb3-interceptors-aop.xml
  |             EJB3StandaloneBootstrap.boot(null);
  | 
  | //            Uncomment the following to enable security
  | //            logger.info("==>Deploying security-beans");
  | //            EJB3StandaloneBootstrap.deployXmlResource("security-beans.xml");
  | //            logger.info("==>Deployed security-beans");
  |              
  | //            logger.info("==>Deploying jboss-jms-beans - init JBoss MQ core services");
  | //            EJB3StandaloneBootstrap.deployXmlResource("jboss-jms-beans.xml");
  | //            logger.info("==>Deployed jboss-jms-beans");
  |             
  | //            logger.info("==>Configure test queue and topic");
  | //            EJB3StandaloneBootstrap.deployXmlResource("testjms.xml");
  | //            logger.info("==>Configured test queues and topics");
  | 
  |             logger.info("==>Deploying ejb3");
  |             EJB3StandaloneBootstrap.scanClasspath();
  | 
  |             // Add all EJBs found in the archive that has this file
  |             deployer = new EJB3StandaloneDeployer();
  |     
  |             // Deploy everything we got
  |             deployer.setKernel(EJB3StandaloneBootstrap.getKernel());	
  |             deployer.create();
  |             logger.info("==>Deployer created");
  |             deployer.start();
  |             logger.info("==>Deployer started");
  |             logger.info("==>End of bootstrapping EJB3 container");
  |         } 
  |         catch (Exception ex) 
  |         {
  |             logger.error(ex.getMessage(), ex);
  |             throw new RuntimeException(ex);
  |         }
  |     }
  | 
  |     @Configuration(afterTest = true)
  |     public void shutdown() 
  |     {
  |         try 
  |         {
  |             logger.info("==>Invoking EJB3.shutdown...");
  |             deployer.stop();
  |             deployer.destroy();
  |             EJB3StandaloneBootstrap.shutdown();
  |         } 
  |         catch (Exception ex)
  |         {
  |             throw new RuntimeException(ex);
  |         }
  |     }
  |     
  |     private static InitialContext initialContext = null;
  |     private static InitialContext securedInitialContext = null;
  | 
  |     /**
  |      * Return a new InitialContext based on org.jnp.interfaces.LocalOnlyContextFactory,
  |      * setting the the default context.
  |      * 
  |      * @return InitialContext
  |      * @throws Exception
  |      */
  |     public static InitialContext newInitialContext()
  |         throws Exception
  |     {
  |         Hashtable props = getInitialContextProperties();
  |         initialContext = new InitialContext(props);
  |         return initialContext;
  |     }
  |     
  |     /**
  |      * Return a new InitialContext based on org.jboss.security.jndi.JndiLoginInitialContextFactory,
  |      * setting the default context. Use the specified username and password to set the security context.
  |      * 
  |      * @param principal
  |      * @param credential
  |      * @return InitialContext
  |      * @throws Exception
  |      */
  |     public static InitialContext newInitialContext(String principal, String credential)
  |         throws Exception
  |     {
  |         Hashtable props = getInitialContextProperties(principal, credential);
  |         securedInitialContext = new InitialContext(props);
  |         return securedInitialContext;
  |     }
  |     
  |     /**
  |      * Return the default InitialContext based on org.jnp.interfaces.LocalOnlyContextFactory
  |      * if one is already instantiated, otherwise create a new InitialContext and set as the default.
  |      * 
  |      * @return InitialContext
  |      * @throws Exception
  |      */
  |     public static InitialContext getInitialContext() 
  |         throws Exception
  |     {
  |         if (initialContext == null)
  |         {
  |            Hashtable props = getInitialContextProperties();
  |            initialContext = new InitialContext(props);
  |         }
  |         return initialContext;
  |     }
  |     
  |     /**
  |      * Return the default InitialContext based on org.jboss.security.jndi.JndiLoginInitialContextFactory
  |      * if one is already instantiated, otherwise create a new InitialContext and set as the default.
  |      * Use the specified username and password to set the security context.
  |      * 
  |      * @param principal
  |      * @param credential
  |      * @return
  |      * @throws Exception
  |      */
  |     public static InitialContext getInitialContext(String principal, String credential)
  |         throws Exception
  |     {
  |         if (securedInitialContext == null)
  |         {
  |            Hashtable props = getInitialContextProperties(principal, credential);
  |            securedInitialContext = new InitialContext(props);
  |         }
  |         return securedInitialContext;
  |     }
  |     
  |     private static Hashtable getInitialContextProperties()
  |     {
  |         Hashtable<String, String> props = new Hashtable<String, String>();
  |         props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.LocalOnlyContextFactory");
  |         props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
  |         return props;
  |     }
  |     
  |     private static Hashtable getInitialContextProperties(String principal, String credential)
  |     {
  |         Hashtable<String, String> props = new Hashtable<String, String>();
  |         props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
  |         props.put(Context.SECURITY_PRINCIPAL, principal);
  |         props.put(Context.SECURITY_CREDENTIALS, credential);
  |         return props;
  |     }
  | }
  | 

I am new to EJB3 and TestNG, so it looks like chinese to me. Any idea ?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4066082#4066082

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4066082



More information about the jboss-user mailing list