Hi,

I am trying to set up an EJB 3 test project in Eclipse and I am hitting on a
problem I can't find any explanation elsewhere. I am an EJB newbie so I may
be missing something trivial...

I downloaded the latest OpenEJB 3.1.1 and added all of its libraries to a
User Library set. I made a new Java project that contains the following
three classes:

file: test.Simple

package test;

public interface Simple {
        public int multiply(int a, int b);
}

file: test.SimpleBean

package test;

import javax.ejb.Stateless;

@Stateless
public class SimpleBean implements Simple {

        public int multiply(int a, int b) {
                return a*b;
        }
}

file: SimpleTest

import static org.junit.Assert.*;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import org.junit.Test;

import test.Simple;


public class SimpleTest {

        @Test
        public void testSimple() {
                Properties p = new Properties();
                p.put(Context.INITIAL_CONTEXT_FACTORY,
                                
"org.apache.openejb.client.LocalInitialContextFactory");
                InitialContext context;
                try {
                        context = new InitialContext(p);
                        Simple simple = 
(Simple)context.lookup("SimpleBeanLocal");
                        assertEquals(simple.multiply(2,2), 4);
                }
                catch ( Exception e ) {
                        e.printStackTrace();
                }
        }
}

I have ejb-jar.xml in META-INF folder under the src folder with just
'<ejb-jar />' in it. When I run the test I get the following output:

Apache OpenEJB 3.1.1    build: 20090530-06:18
http://openejb.apache.org/
INFO - openejb.home = /home/yuri/projects/test.openejb
INFO - openejb.base = /home/yuri/projects/test.openejb
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 - Found EjbModule in classpath: /home/yuri/projects/test.openejb/bin
INFO - Beginning load: /home/yuri/projects/test.openejb/bin
INFO - Configuring enterprise application: classpath.ear
INFO - Configuring Service(id=Default Stateless Container, type=Container,
provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean SimpleBean:
Container(type=STATELESS, id=Default Stateless Container)
INFO - Enterprise application "classpath.ear" loaded.
INFO - Assembling app: classpath.ear
INFO - Jndi(name=SimpleBeanLocal) --> Ejb(deployment-id=SimpleBean)
INFO - Created Ejb(deployment-id=SimpleBean, ejb-name=SimpleBean,
container=Default Stateless Container)
INFO - Deployed Application(path=classpath.ear)
java.lang.ClassCastException: $Proxy6 cannot be cast to test.Simple
        at SimpleTest.testSimple(SimpleTest.java:27)
        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:597)
        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)

-- 
View this message in context: 
http://www.nabble.com/Problem-setting-up-OpenEJB-in-Eclipse-tp23932458p23932458.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to