You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by ericp56 <er...@twcable.com> on 2008/11/03 17:53:38 UTC

JUnit question

Hello,

In Eclipse, I'm able to test a simple EJB with Junit.

I'm having problems testing one slightly more complicated.

I had to create an ejb-jar.xml file, because the openejb-jar.xml file was
not recognized in junit.

Now, I am getting this:
FATAL - OpenEJB has encountered a fatal error and cannot be started:
Assembler failed to build the container system. ... NullPointerException...

I'm guessing it's perhaps one of my openejb-jar.xml dependencies is not
being loaded, like a console.dbpool resource.

Any suggestions on how to resolve it?

Thanks,

Eric
-- 
View this message in context: http://www.nabble.com/JUnit-question-tp20306283p20306283.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JUnit question

Posted by David Blevins <da...@visi.com>.
On Nov 4, 2008, at 3:05 PM, ericp56 wrote:

> org
> .eclipse
> .jdt
> .internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java: 
> 196)
> Caused by: java.lang.NoClassDefFoundError:
> org/apache/commons/dbcp/BasicDataSource
>
>
> I'm guessing it's something simple with my configuration...

That class is in the commons-dbcp-all jar under the lib/ directory.   
Definitely add that to your classpath if you haven't.

-David


Re: JUnit question

Posted by ericp56 <er...@twcable.com>.
I'll give it a whirl...:)

David Blevins wrote:
> 
> 
> On Nov 19, 2008, at 6:32 AM, ericp56 wrote:
> 
>>
>> I wasn't paying attention to the package, only the class name.   
>> Thanks for
>> the clarification:)
> 
> No worries.  I've often thought it would be neat to add some  
> functionality that would catch ClassNotFoundExceptions and print the  
> name of the jar that should be added to the classpath.  Wouldn't be  
> too hard as all we'd have to do is create a maven plugin (or any plain  
> java code we can run via the maven-ant-plugin at build time) that  
> squirted the indexes of each jar we depend on into a file that we  
> include in the openejb-core jar.  Then it'd simply be a quick read  
> through that file to find the jar name to add to the error message.
> 
> Would be a cool contribution if you felt like giving it a whirl :)
> 
> -David
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/JUnit-question-tp20306283p20606400.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JUnit question

Posted by David Blevins <da...@visi.com>.
On Nov 19, 2008, at 6:32 AM, ericp56 wrote:

>
> I wasn't paying attention to the package, only the class name.   
> Thanks for
> the clarification:)

No worries.  I've often thought it would be neat to add some  
functionality that would catch ClassNotFoundExceptions and print the  
name of the jar that should be added to the classpath.  Wouldn't be  
too hard as all we'd have to do is create a maven plugin (or any plain  
java code we can run via the maven-ant-plugin at build time) that  
squirted the indexes of each jar we depend on into a file that we  
include in the openejb-core jar.  Then it'd simply be a quick read  
through that file to find the jar name to add to the error message.

Would be a cool contribution if you felt like giving it a whirl :)

-David


Re: JUnit question

Posted by ericp56 <er...@twcable.com>.
I wasn't paying attention to the package, only the class name.  Thanks for
the clarification:)
-- 
View this message in context: http://www.nabble.com/JUnit-question-tp20306283p20580964.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JUnit question

Posted by David Blevins <da...@visi.com>.
On Nov 5, 2008, at 2:50 PM, ericp56 wrote:

> That's already included in my classpath via openejb-core-3.0.jar (in  
> Geronimo
> server).

Not sure I follow.  The embeddable EJB container functionality for  
unit testing doesn't use the Geronimo server.  Also Geronimo doesn't  
use commons-dbcp as it has it's own connection management code.

You could try something like this in your test case to see what is in  
our classpath, assuming the Eclipse classloader is a subclass of  
URLClassLoader (good chance of that).

       ClassLoader classLoader =  
Thread.currentThread().getContextClassLoader();
       System.out.println("classLoader" + classLoader);
       System.out.println("classLoader.class" +  
classLoader.getClass().getName());
       if (classLoader instanceof URLClassLoader) {
           URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
           URL[] urls = urlClassLoader.getURLs();
           for (URL url : urls) {
               System.out.println("url = " + url.toExternalForm());
           }
       }

-David


Re: JUnit question

Posted by ericp56 <er...@twcable.com>.
That's already included in my classpath via openejb-core-3.0.jar (in Geronimo
server).


-- 
View this message in context: http://www.nabble.com/JUnit-question-tp20306283p20351506.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JUnit question

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Wed, Nov 5, 2008 at 12:05 AM, ericp56 <er...@twcable.com> wrote:

> My current problem is "caused by:"
> Caused by: java.lang.NoClassDefFoundError:
> org/apache/commons/dbcp/BasicDataSource

Add commons-dbcp-*.jar to CLASSPATH and start it over.

Jacek

-- 
Jacek Laskowski
Notatnik Projektanta Java EE - http://www.JacekLaskowski.pl

Re: JUnit question

Posted by ericp56 <er...@twcable.com>.
Hi David,

I'm using a test application to take it one step at a time.  I'll eventually
tackle that other one.

My current problem is "caused by:"
Caused by: java.lang.NoClassDefFoundError:
org/apache/commons/dbcp/BasicDataSource

ScrapTest.Java:
@Stateless(name="ScrapTest")
public class ScrapTest implements IScrapTest {

	@PersistenceContext(unitName = "ScrapEjb")
    private EntityManager entityManager;

	public String Echo(String EchoString) {
		// TODO Auto-generated method stub
		return EchoString;
	}

}

ejb-jar.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
  <display-name>Scrap Ejb Test </display-name>
  <enterprise-beans>
    <session>
      <ejb-name>ScrapTest</ejb-name>
      <resource-ref>
        <res-ref-name>SchedulerDB2</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>
      <resource-ref>
        <res-ref-name>SchedulerDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
      </resource-ref>
    </session>
  </enterprise-beans>
</ejb-jar>


persistence.xml
<?xml version="1.0" ...>
	<persistence-unit name="ScrapEjb" transaction-type="RESOURCE_LOCAL">
	<jta-data-source>SchedulerDB</jta-data-source>
	<non-jta-data-source>SchedulerDB2</non-jta-data-source>
		<class>com.abc.ivr.test.Outboundconfiguration</class>
		<properties>
			<!-- <property name="openjpa.Log"
value="File=/tmp/org.apache.openjpa.log, DefaultLevel=WARN, Runtime=INFO,
Tool=INFO, SQL=TRACE"/> 
		</properties>
	</persistence-unit>
</persistence>


It's during the discovery process when the EJBs in the classpath are being
loaded.  Here's the stack trace:

pache OpenEJB 3.0    build: 20080408-04:13
http://openejb.apache.org/
INFO - openejb.home = C:\Projects\IVR\geronimo\OutboundSchedulerTest
INFO - openejb.base = C:\Projects\IVR\geronimo\OutboundSchedulerTest
INFO - Configuring Service(id=Default Security Service,
type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager,
type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring Service(id=SchedulerDB2, type=Resource,
provider-id=Default JDBC Database)
INFO - Configuring Service(id=SchedulerDB, type=Resource,
provider-id=Default JDBC Database)
INFO - Configuring Service(id=Default JDK 1.3 ProxyFactory,
type=ProxyFactory, provider-id=Default JDK 1.3 ProxyFactory)
INFO - Found EjbModule in classpath:
C:\Projects\IVR\geronimo\EmailEjb\build\classes
INFO - Found EjbModule in classpath:
C:\eclipseRC3\workspace\ScrapEjb\build\classes
INFO - Configuring app: C:\Projects\IVR\geronimo\EmailEjb\build\classes
INFO - Configuring Service(id=Default Stateless Container, type=Container,
provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean SysErrorEmail:
Container(type=STATELESS, id=Default Stateless Container)
INFO - Configuring Service(id=Default Mail Session, type=Resource,
provider-id=Default Mail Session)
INFO - Auto-creating a Resource with id 'Default Mail Session' of type
'javax.mail.Session for 'SysErrorEmail'.
INFO - Auto-linking resource-ref 'mail/MailSession' in bean SysErrorEmail to
Resource(id=Default Mail Session)
INFO - Loaded Module: C:\Projects\IVR\geronimo\EmailEjb\build\classes
INFO - Configuring app: C:\eclipseRC3\workspace\ScrapEjb\build\classes
INFO - Auto-linking resource-ref 'SchedulerDB2' in bean ScrapTest to
Resource(id=SchedulerDB2)
INFO - Auto-linking resource-ref 'SchedulerDB' in bean ScrapTest to
Resource(id=SchedulerDB)
INFO - Configuring PersistenceUnit(name=ScrapEjb)
INFO - Loaded Module: C:\eclipseRC3\workspace\ScrapEjb\build\classes
ERROR - FATAL ERROR: Unknown error in Assembler.  Please send the following
stack trace and this message to user@openejb.org :
 org.apache.xbean.recipe.ConstructionException: Error invoking factory
method: public static javax.sql.DataSource
org.apache.openejb.resource.jdbc.DataSourceFactory.create(boolean,boolean)
	at
org.apache.xbean.recipe.ObjectRecipe.createInstance(ObjectRecipe.java:419)
	at org.apache.xbean.recipe.ObjectRecipe.create(ObjectRecipe.java:191)
	at org.apache.xbean.recipe.AbstractRecipe.create(AbstractRecipe.java:28)
	at
org.apache.openejb.assembler.classic.Assembler.createResource(Assembler.java:888)
	at
org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:327)
	at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:250)
	at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:149)
	at org.apache.openejb.OpenEJB.init(OpenEJB.java:288)
	at org.apache.openejb.OpenEJB.init(OpenEJB.java:267)
	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.openejb.loader.OpenEJBInstance.init(OpenEJBInstance.java:36)
	at
org.apache.openejb.client.LocalInitialContextFactory.init(LocalInitialContextFactory.java:62)
	at
org.apache.openejb.client.LocalInitialContextFactory.init(LocalInitialContextFactory.java:51)
	at
org.apache.openejb.client.LocalInitialContextFactory.getInitialContext(LocalInitialContextFactory.java:40)
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
	at javax.naming.InitialContext.init(InitialContext.java:223)
	at javax.naming.InitialContext.<init>(InitialContext.java:197)
	at
com.twcable.ivr.scheduler.CallSchedulerTest.test1(CallSchedulerTest.java:64)
	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.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
	at
org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
	at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
	at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
	at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
	at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
	at
org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
	at
org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
	at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
	at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
	at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.lang.NoClassDefFoundError:
org/apache/commons/dbcp/BasicDataSource


I'm guessing it's something simple with my configuration...
-- 
View this message in context: http://www.nabble.com/JUnit-question-tp20306283p20333264.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: JUnit question

Posted by David Blevins <da...@visi.com>.
Hi Eric,

Can you post the stack trace?

-David

On Nov 3, 2008, at 8:53 AM, ericp56 wrote:

>
> Hello,
>
> In Eclipse, I'm able to test a simple EJB with Junit.
>
> I'm having problems testing one slightly more complicated.
>
> I had to create an ejb-jar.xml file, because the openejb-jar.xml  
> file was
> not recognized in junit.
>
> Now, I am getting this:
> FATAL - OpenEJB has encountered a fatal error and cannot be started:
> Assembler failed to build the container system. ...  
> NullPointerException...
>
> I'm guessing it's perhaps one of my openejb-jar.xml dependencies is  
> not
> being loaded, like a console.dbpool resource.
>
> Any suggestions on how to resolve it?
>
> Thanks,
>
> Eric
> -- 
> View this message in context: http://www.nabble.com/JUnit-question-tp20306283p20306283.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
>