[jboss-dev-forums] [Design of EJB 3.0] - Re: Which is the best place to write a test case for ejb3-te

jaikiran do-not-reply at jboss.com
Thu Aug 7 02:44:42 EDT 2008


"ALRubinger" wrote : 
  | Nope. ;)
  | 
  | EJB3 Test is a set of common test scaffolding/utilities that my be shared by the other components (think of it as EJB3 Common, but for testing dependencies only).
  | 
  | So if you draw a dependency upon EJB3 Proxy to EJB3 Test, there will be a cyclic dependency. 
  | 

That's what i wanted to understand :) Thanks.


"ALRubinger" wrote : 
  | What exactly are you trying to do?
  | 

I'm actually trying to figure out the best place for the following testcase.  Here's more details (actually we had discussed this sometime back through a mail, but at that time, i never got to the point of coming up with a reproducible testcase):


  | public interface MySLSBLocal
  | {
  |    void printObject(Object obj);
  | 
  | }



  | @Stateless
  | @Local (MySLSBLocal.class)
  | public class MySLSBean implements MySLSBLocal
  | {
  | 
  |    public void printObject(Object obj)
  |    {
  |       System.out.println("Printing " + obj);
  |     
  |    }
  | 
  | }


And this is the testcase:

  | .....
  | import org.jboss.ejb3.test.proxy.common.Utils;
  | import org.jboss.ejb3.test.proxy.common.container.SessionContainer;
  | .....
  | 
  | @Test
  |    public void testBeanMethodInvocation() throws Throwable
  |    {
  |       // create the SLSB container
  |       this.sessionContainer = Utils.createSlsb(MySLSBean.class);
  | 
  |       // bind to JNDI
  |       Ejb3RegistrarLocator.locateRegistrar().bind(sessionContainer.getName(), sessionContainer);
  | 
  |       Context ctx = new InitialContext();
  |       // lookup the local bean
  |       MySLSBLocal local = (MySLSBLocal) ctx.lookup(getDefaultBusinessLocalJndiName(sessionContainer));
  |       
  |       assertNotNull("Local bean is null",local);
  |       
  |       //call the method
  |       String someString = new String("I am some string");
  |       local.printObject(someString);
  |       
  |    }


This fails with:

  | java.lang.reflect.UndeclaredThrowableException
  | 	at $Proxy55.printObject(Unknown Source)
  | 	at org.jboss.ejb3.test.proxy.jndiregistrar.unit.JndiSessionRegistrarBaseTestCase.testBeanMethodInvocation(JndiSessionRegistrarBaseTestCase.java:498)
  | 	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.TestMethod.invoke(TestMethod.java:59)
  | 	at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
  | 	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
  | 	at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
  | 	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
  | 	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
  | 	at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
  | 	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
  | 	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
  | 	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
  | 	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
  | 	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
  | 	at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
  | 	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
  | 	at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:165)
  | 	at org.apache.maven.surefire.Surefire.run(Surefire.java:107)
  | 	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:289)
  | 	at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:993)
  | Caused by: java.lang.NoSuchMethodException: org.jboss.ejb3.test.proxy.jndiregistrar.MySLSBLocal.printObject(java.lang.String)
  | 	at java.lang.Class.getDeclaredMethod(Class.java:1909)
  | 	at org.jboss.ejb3.test.proxy.common.container.SessionContainer.invoke(SessionContainer.java:188)
  | 	at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:120)
  | 	... 28 more
  | 

The root cause is that i have  a method in the bean with accepts a base class param (java.lang.Object) where as i am invoking the bean method by passing it a child class (java.lang.String). The issue is that the java reflection API used in SessionContainer.invoke looks for a exact match for the Method. The reflection APIs do not support a way to find the best match for a Method.

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

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



More information about the jboss-dev-forums mailing list