[jboss-user] [JBoss Seam] - Problem writing unit tests

Alpha1251 do-not-reply at jboss.com
Mon Jul 2 04:29:18 EDT 2007


Hello all.
I was trying to write a simple unit test for Seam hotel booking example and had some troubles. Seam 1.2.1GA

Test was the following
	@Test
	public void test_1_COMPONENT_CreateUser () throws Exception {

		EntityManagerFactory emf = Persistence.createEntityManagerFactory("bookingDatabase");
		final EntityManager em = emf.createEntityManager();

		em.getTransaction().begin();
		
		User user = new User();
		user.setUsername("blabla");
		user.setName("foobar");
		user.setPassword("foobar");
		RegisterAction action = new RegisterAction();
		//action.setUser(user);
		setField (action,"user",user);
		action.setEm(em);
		action.setVerify("foobar");
		
		action.register();
		
		assert action.isRegistered()==true;
		
		em.getTransaction().commit();
		em.close();
	}

And I had the following exception

javax.persistence.PersistenceException: org.hibernate.QueryException: unexpected char: '#' [select u.username from org.jboss.seam.example.booking.User u where u.username=#{user.username}]
	at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:567)
	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:79)
	at org.jboss.seam.example.booking.RegisterAction.register(RegisterAction.java:36)
	at org.jboss.seam.example.booking.test.CreateUserTest.test_1_COMPONENT_CreateUser(CreateUserTest.java:36)
Caused by: org.hibernate.QueryException: unexpected char: '#' [select u.username from org.jboss.seam.example.booking.User u where u.username=#{user.username}]
	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:203)
	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:110)
	at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:77)
	at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:56)
	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
	at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
	at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1612)
	at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:76)
	... 24 more

but I seems, that the main cause is the following

09:44:14,331 ERROR [AbstractKernelController] Error installing to Start: name=jboss.j2ee:jar=bin,name=Dispatcher,service=EJB3 state=Create
javax.naming.NamingException: Could not bind statless proxy with ejb name Dispatcher into JNDI under jndiName: /Dispatcher/local [Root exception is javax.naming.NameAlreadyBoundException]
	at org.jboss.ejb3.stateless.BaseStatelessProxyFactory.start(BaseStatelessProxyFactory.java:70)
	at org.jboss.ejb3.stateless.StatelessLocalProxyFactory.start(StatelessLocalProxyFactory.java:63)
	at org.jboss.ejb3.ProxyDeployer.start(ProxyDeployer.java:107)
	at org.jboss.ejb3.SessionContainer.start(SessionContainer.java:85)
	at org.jboss.ejb3.stateless.StatelessContainer.start(StatelessContainer.java:80)
	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.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:55)
	at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:107)
	at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66)
	at org.jboss.kernel.plugins.dependency.KernelControllerContextActions.dispatchJoinPoint(KernelControllerContextActions.java:100)
	at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$LifecycleAction.installAction(KernelControllerContextActions.java:582)
	at org.jboss.kernel.plugins.dependency.KernelControllerContextActions$KernelControllerContextAction.install(KernelControllerContextActions.java:175)
	at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
	at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:226)
	at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:593)
	at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:346)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:438)
	at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:379)
	at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:225)
	at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:151)
	at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:79)
	at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:73)
	at org.jboss.ejb3.MCKernelAbstraction.install(MCKernelAbstraction.java:91)
	at org.jboss.ejb3.Ejb3Deployment.registerEJBContainer(Ejb3Deployment.java:439)
	at org.jboss.ejb3.Ejb3Deployment.start(Ejb3Deployment.java:486)
	at org.jboss.ejb3.embedded.EJB3StandaloneDeployer.start(EJB3StandaloneDeployer.java:460)
	at org.jboss.seam.core.Ejb.startup(Ejb.java:56)
	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.jboss.seam.util.Reflections.invoke(Reflections.java:20)
	at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:123)
	at org.jboss.seam.Component.callComponentMethod(Component.java:1834)
	at org.jboss.seam.Component.callCreateMethod(Component.java:1757)
	at org.jboss.seam.Component.newInstance(Component.java:1746)
	at org.jboss.seam.contexts.Lifecycle.startup(Lifecycle.java:175)
	at org.jboss.seam.contexts.Lifecycle.endInitialization(Lifecycle.java:145)
	at org.jboss.seam.init.Initialization.init(Initialization.java:504)
	at org.jboss.seam.mock.SeamTest.init(SeamTest.java:701)
	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:604)
	at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:394)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:79)
	at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:165)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:103)
	at org.testng.TestRunner.runWorkers(TestRunner.java:678)
	at org.testng.TestRunner.privateRun(TestRunner.java:624)
	at org.testng.TestRunner.run(TestRunner.java:495)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:300)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:295)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:275)
	at org.testng.SuiteRunner.run(SuiteRunner.java:190)
	at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:792)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:765)
	at org.testng.TestNG.run(TestNG.java:699)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)
Caused by: javax.naming.NameAlreadyBoundException
	at org.jnp.server.NamingServer.bind(NamingServer.java:144)
	at org.jnp.server.NamingServer.bind(NamingServer.java:109)
	at org.jnp.interfaces.NamingContext.bind(NamingContext.java:567)
	at org.jnp.interfaces.NamingContext.bind(NamingContext.java:532)
	at org.jboss.util.naming.Util.bind(Util.java:102)
	at org.jboss.util.naming.Util.bind(Util.java:89)
	at org.jboss.ejb3.stateless.BaseStatelessProxyFactory.start(BaseStatelessProxyFactory.java:67)
	... 64 more

Also, I've tried to initialize EntityManager, like it was showed in a manual, and I had absolutelly another exception.

When I have tried to start ready unit tests from the examples, I had also some different kind of exceptions, but, seems, they all are caused by the same.

To show this. Icefaces had during unit testing the following:
10:23:57,890 WARN  [Interpolator] exception interpolating string: New booking: #{booking.id} for #{user.username}
java.lang.IllegalStateException: No application context active
	at org.jboss.seam.ScopeType.getContext(ScopeType.java:139)
	at org.jboss.seam.Component.getInstance(Component.java:1621)
	at org.jboss.seam.Component.getInstance(Component.java:1599)
	at org.jboss.seam.Component.getInstance(Component.java:1594)
	at org.jboss.seam.core.Expressions.instance(Expressions.java:265)
	at org.jboss.seam.core.Interpolator.interpolateExpressions(Interpolator.java:88)
	at org.jboss.seam.core.Interpolator.interpolate(Interpolator.java:67)
	at org.jboss.seam.log.LogImpl.interpolate(LogImpl.java:142)
	at org.jboss.seam.log.LogImpl.info(LogImpl.java:85)
	at org.jboss.seam.example.booking.HotelBookingAction.confirm(HotelBookingAction.java:99)
	at org.jboss.seam.example.booking.test.BookingUnitTest.testHotelBooking(BookingUnitTest.java:80)
	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:604)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:470)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:564)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:830)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
	at org.testng.TestRunner.runWorkers(TestRunner.java:678)
	at org.testng.TestRunner.privateRun(TestRunner.java:624)
	at org.testng.TestRunner.run(TestRunner.java:495)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:300)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:295)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:275)
	at org.testng.SuiteRunner.run(SuiteRunner.java:190)
	at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:792)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:765)
	at org.testng.TestNG.run(TestNG.java:699)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)

DVDStore, the following:

10:26:17,344 WARN  [LocalTxDataSource] Destroying connection that could not be successfully matched: org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener at 196eed5[state=NORMAL mc=org.jboss.resource.adapter.jdbc.local.LocalManagedConnection at 110caf0 handles=0 lastUse=1183364777313 permit=false trackByTx=false mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool at 17b6178 context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool at 13c2ac3 xaResource=org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource at 11b92e6 txSync=null]
10:26:17,344 WARN  [LocalTxDataSource] Throwable while attempting to get a new connection: null
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (org.jboss.resource.JBossResourceException: No Driver class specified!)
	at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:177)
	at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:579)
	at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:247)
	at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:540)
	at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:339)
	at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:301)
	at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:392)
	at org.jboss.resource.adapter.jdbc.local.LocalTxDataSource$ConnectionManagerDelegate.allocateConnection(LocalTxDataSource.java:78)
	at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
	at org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:69)
	at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
	at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:178)
	at org.hibernate.tool.hbm2ddl.SchemaExport.drop(SchemaExport.java:141)
	at org.hibernate.impl.SessionFactoryImpl.close(SessionFactoryImpl.java:807)
	at org.jbpm.persistence.db.DbPersistenceServiceFactory.close(DbPersistenceServiceFactory.java:120)
	at org.jbpm.JbpmConfiguration.close(JbpmConfiguration.java:460)
	at org.jbpm.JbpmConfiguration.close(JbpmConfiguration.java:437)
	at org.jboss.seam.core.Jbpm.shutdown(Jbpm.java:76)
	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.jboss.seam.util.Reflections.invoke(Reflections.java:20)
	at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:123)
	at org.jboss.seam.Component.callComponentMethod(Component.java:1834)
	at org.jboss.seam.Component.callDestroyMethod(Component.java:1765)
	at org.jboss.seam.contexts.Contexts.destroy(Contexts.java:231)
	at org.jboss.seam.contexts.Lifecycle.endApplication(Lifecycle.java:185)
	at org.jboss.seam.mock.SeamTest.cleanup(SeamTest.java:709)
	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:604)
	at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:394)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
	at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:79)
	at org.testng.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:208)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
	at org.testng.TestRunner.runWorkers(TestRunner.java:678)
	at org.testng.TestRunner.privateRun(TestRunner.java:624)
	at org.testng.TestRunner.run(TestRunner.java:495)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:300)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:295)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:275)
	at org.testng.SuiteRunner.run(SuiteRunner.java:190)
	at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:792)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:765)
	at org.testng.TestNG.run(TestNG.java:699)
	at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)
Caused by: org.jboss.resource.JBossResourceException: No Driver class specified!
	at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:257)
	at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:168)
	... 50 more

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

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



More information about the jboss-user mailing list