hello all,
following an interesting article ont he net about testing EJBs using
OpenEJB (with no server running), i decided to try to use openEJB with
my EJBS.
I have successfully run samples that used openejb 1.0, i am however
unable to run tests with the 2.0 version, and i was wondering if
someone could help.
TEsts are articulated so that there is no server running,but the
openEJB is embedded inside the JUnit test (i attach sample test case).
I am unable to run tests, and checking logs i found out following:
INFO :
********************************************************************************
OpenEJB http://www.openejb.org
Startup: 13/07/05 18:24
Copyright 1999-2004 (C) OpenEJB Project, All Rights Reserved.
Version: 1.0-SNAPSHOT
Build date: 20040829
Build time: 0049
********************************************************************************
WARN : No ApplicationServer was specified! The container system will
only be accessible by same-vm clients via the IntraVm Server.
WARN : Deprecated: The propery name "org/openejb/assembler_class" is
deprecated and will be removed in a future version of OpenEJB, please
use the property name "openejb.assembler" instead.
DEBUG: Instantiating assembler class
org.openejb.alt.assembler.classic.Assembler
WARN : Jar not loaded.
C:\Sw\TestEJB\target\ejb-testing-examples-1.0.jar. Cannot parse the
XML of the ejb-jar.xml file. Received message: unable to find
FieldDescriptor for 'cmp-version' in ClassDescriptor of entity
DEBUG: Containers : 1
DEBUG: Type Container ID
DEBUG: STATELESS Default Stateless Container
DEBUG: Deployments : 0
DEBUG: SecurityService : org.openejb.ri.sp.PseudoSecurityService
DEBUG: TransactionManager: org.openejb.core.TransactionManagerWrapper
INFO : OpenEJB ready.
INFO :
********************************************************************************
OpenEJB http://www.openejb.org
Startup: 13/07/05 18:25
Copyright 1999-2004 (C) OpenEJB Project, All Rights Reserved.
Version: 1.0-SNAPSHOT
Build date: 20040829
Build time: 0049
********************************************************************************
WARN : No ApplicationServer was specified! The container system will
only be accessible by same-vm clients via the IntraVm Server.
WARN : Deprecated: The propery name "org/openejb/assembler_class" is
deprecated and will be removed in a future version of OpenEJB, please
use the property name "openejb.assembler" instead.
DEBUG: Instantiating assembler class
org.openejb.alt.assembler.classic.Assembler
WARN : Jar not loaded.
C:\Sw\TestEJB\target\ejb-testing-examples-1.0.jar. Cannot parse the
XML of the ejb-jar.xml file. Received message: unable to find
FieldDescriptor for 'cmp-version' in ClassDescriptor of entity
DEBUG: Containers : 1
DEBUG: Type Container ID
DEBUG: STATELESS Default Stateless Container
DEBUG: Deployments : 0
DEBUG: SecurityService : org.openejb.ri.sp.PseudoSecurityService
DEBUG: TransactionManager: org.openejb.core.TransactionManagerWrapper
INFO : OpenEJB ready.
WARN : No ApplicationServer was specified! The container system will
only be accessible by same-vm clients via the IntraVm Server.
INFO :
********************************************************************************
OpenEJB null
Startup: 19/07/05 17:53
null
Version: null
Build date: null
Build time: null
********************************************************************************
DEBUG: Instantiating assembler class org.openejb.assembler.Assembler
FATAL: OpenEJB has encountered a fatal error and cannot be started:
Assembler failed to initialize.
org.openejb.OpenEJBException: Cannot read the service-jar.xml at
resource2:/org/openejb/service-jar.xml. Received message: unknown
protocol: resource2
at
org.openejb.config.ServiceUtils.handleException(ServiceUtils.java:311)
at
org.openejb.config.ServiceUtils.readServicesJar(ServiceUtils.java:137)
at
org.openejb.config.ServiceUtils.getServiceProvider(ServiceUtils.java:100)
at
org.openejb.config.ServiceUtils.getServiceProvider(ServiceUtils.java:76)
at
org.openejb.config.ConfigurationFactory.initTransactionService(ConfigurationFactory.java:308)
at
org.openejb.config.ConfigurationFactory.getOpenEjbConfiguration(ConfigurationFactory.java:168)
at org.openejb.assembler.Assembler.init(Assembler.java:160)
at org.openejb.OpenEJB.initializeAssembler(OpenEJB.java:280)
at org.openejb.OpenEJB.init(OpenEJB.java:155)
at org.openejb.OpenEJB.init(OpenEJB.java:130)
at org.openejb.loader.EmbeddedLoader.load(EmbeddedLoader.java:66)
at org.openejb.loader.EmbeddingLoader.load(EmbeddingLoader.java:81)
at
org.openejb.client.LocalInitialContextFactory.getInitialContext(LocalInitialContextFactory.java:66)
at
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at com.myapp.ejb.Example01Test.setUp(Example01Test.java:15)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:325)
at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:536)
can anyone help me found out what's the problem?
attached is my sample test case, along with openejb.properties (if that matter)
package com.myapp.ejb;
import java.util.Collection;
import java.util.Properties;
import java.util.Vector;
import javax.naming.InitialContext;
import junit.framework.TestCase;
public class Example01Test extends TestCase {
private AdminFacadeLocalHome ejbHome;
private AdminFacadeLocal ejbObject;
public void setUp() throws Exception{
InitialContext context = new InitialContext(System.getProperties());
Object obj = context.lookup("AdminFacade");
ejbHome = (AdminFacadeLocalHome)obj;
ejbObject = ejbHome.create();
}
/*-------------------------------------------------*/
/* String */
/*-------------------------------------------------*/
public void test_returnStringObject() {
try{
Collection collection = ejbObject.getExpenseTypes();
assertEquals("We should have 2 items", 2, collection.size());
} catch (Exception e){
fail("Received Exception "+e.getClass()+ " : "+e.getMessage());
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar >
<description><![CDATA[No Description.]]></description>
<display-name>Generated by XDoclet</display-name>
<enterprise-beans>
<!-- Session Beans -->
<session >
<description><![CDATA[Facade EJB for ExpenseTypes]]></description>
<ejb-name>BudgetFacade</ejb-name>
<local-home>com.myapp.ejb.BudgetFacadeLocalHome</local-home>
<local>com.myapp.ejb.BudgetFacadeLocal</local>
<ejb-class>com.myapp.ejb.BudgetFacadeSession</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref >
<ejb-ref-name>ejb/Entry</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.myapp.ejb.EntryHome</home>
<remote>com.myapp.ejb.Entry</remote>
<ejb-link>Entry</ejb-link>
</ejb-ref>
</session>
<session >
<description><![CDATA[Facade SessionBean for administrative purposes]]></description>
<ejb-name>AdminFacade</ejb-name>
<local-home>com.myapp.ejb.AdminFacadeLocalHome</local-home>
<local>com.myapp.ejb.AdminFacadeLocal</local>
<ejb-class>com.myapp.ejb.AdminFacadeSession</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
<!--
To add session beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called session-beans.xml that contains
the <session></session> markup for those beans.
-->
<!-- Entity Beans -->
<entity >
<description><![CDATA[Entity Bean for Expenses]]></description>
<ejb-name>Entry</ejb-name>
<home>com.myapp.ejb.EntryHome</home>
<remote>com.myapp.ejb.Entry</remote>
<local-home>com.myapp.ejb.EntryLocalHome</local-home>
<local>com.myapp.ejb.EntryLocal</local>
<ejb-class>com.myapp.ejb.EntryCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.myapp.ejb.EntryPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>Entry</abstract-schema-name>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>id</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>description</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>amount</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>type</field-name>
</cmp-field>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>date</field-name>
</cmp-field>
<query>
<query-method>
<method-name>findEntryByDateTypeUserDate</method-name>
<method-params>
<method-param>int</method-param>
<method-param>java.util.Date</method-param>
<method-param>java.util.Date</method-param>
<method-param>String</method-param>
</method-params>
</query-method>
<ejb-ql><![CDATA[SELECT OBJECT(e) FROM Entry where e.type=?1 AND e.date <= ?2 AND e.date < ?3 and e.user= ?4]]></ejb-ql>
</query>
<!-- Write a file named ejb-finders-EntryBean.xml if you want to define extra finders. -->
</entity>
<entity >
<description><![CDATA[EJB-CMP for UserBean]]></description>
<ejb-name>User</ejb-name>
<home>com.myapp.ejb.UserHome</home>
<remote>com.myapp.ejb.User</remote>
<local-home>com.myapp.ejb.UserLocalHome</local-home>
<local>com.myapp.ejb.UserLocal</local>
<ejb-class>com.myapp.ejb.UserCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>com.myapp.ejb.UserPK</prim-key-class>
<reentrant>False</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>User</abstract-schema-name>
<cmp-field >
<description><![CDATA[]]></description>
<field-name>username</field-name>
</cmp-field>
<!-- Write a file named ejb-finders-UserBean.xml if you want to define extra finders. -->
</entity>
<!--
To add entity beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called entity-beans.xml that contains
the <entity></entity> markup for those beans.
-->
<!-- Message Driven Beans -->
<!--
To add message driven beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called message-driven-beans.xml that contains
the <message-driven></message-driven> markup for those beans.
-->
</enterprise-beans>
<!-- Relationships -->
<!-- Assembly Descriptor -->
<!--
To specify your own assembly descriptor info here, add a file to your
XDoclet merge directory called assembly-descriptor.xml that contains
the <assembly-descriptor></assembly-descriptor> markup.
-->
<assembly-descriptor >
<!--
To specify additional security-role elements, add a file in the merge
directory called ejb-security-roles.xml that contains them.
-->
<!-- method permissions -->
<!--
To specify additional method-permission elements, add a file in the merge
directory called ejb-method-permissions.ent that contains them.
-->
<!-- finder permissions -->
<!-- finder permissions -->
<!-- finder permissions -->
<!-- finder permissions -->
<!-- transactions -->
<!--
To specify additional container-transaction elements, add a file in the merge
directory called ejb-container-transaction.ent that contains them.
-->
<!-- finder transactions -->
<!--
To specify an exclude-list element, add a file in the merge directory
called ejb-exclude-list.xml that contains it.
-->
</assembly-descriptor>
</ejb-jar>